1 //========================================================================
2 // GLFW 3.4 Wayland - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2014 Jonas Ã…dahl <jadahl@gmail.com>
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would
17 // be appreciated but is not required.
19 // 2. Altered source versions must be plainly marked as such, and must not
20 // be misrepresented as being the original software.
22 // 3. This notice may not be removed or altered from any source
25 //========================================================================
26 // It is fine to use C99 in this file because it will not be built with VS
27 //========================================================================
38 static void outputHandleGeometry(void* data,
39 struct wl_output* output,
42 int32_t physicalWidth,
43 int32_t physicalHeight,
49 struct _GLFWmonitor *monitor = data;
54 monitor->widthMM = physicalWidth;
55 monitor->heightMM = physicalHeight;
57 snprintf(name, sizeof(name), "%s %s", make, model);
58 monitor->name = _glfw_strdup(name);
61 static void outputHandleMode(void* data,
62 struct wl_output* output,
68 struct _GLFWmonitor *monitor = data;
76 mode.refreshRate = (int) round(refresh / 1000.0);
80 realloc(monitor->modes, monitor->modeCount * sizeof(GLFWvidmode));
81 monitor->modes[monitor->modeCount - 1] = mode;
83 if (flags & WL_OUTPUT_MODE_CURRENT)
84 monitor->wl.currentMode = monitor->modeCount - 1;
87 static void outputHandleDone(void* data, struct wl_output* output)
89 struct _GLFWmonitor *monitor = data;
91 _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST);
94 static void outputHandleScale(void* data,
95 struct wl_output* output,
98 struct _GLFWmonitor *monitor = data;
100 monitor->wl.scale = factor;
103 static const struct wl_output_listener outputListener = {
104 outputHandleGeometry,
111 //////////////////////////////////////////////////////////////////////////
112 ////// GLFW internal API //////
113 //////////////////////////////////////////////////////////////////////////
115 void _glfwAddOutputWayland(uint32_t name, uint32_t version)
117 _GLFWmonitor *monitor;
118 struct wl_output *output;
122 _glfwInputError(GLFW_PLATFORM_ERROR,
123 "Wayland: Unsupported output interface version");
127 // The actual name of this output will be set in the geometry handler.
128 monitor = _glfwAllocMonitor(NULL, 0, 0);
130 output = wl_registry_bind(_glfw.wl.registry,
132 &wl_output_interface,
136 _glfwFreeMonitor(monitor);
140 monitor->wl.scale = 1;
141 monitor->wl.output = output;
142 monitor->wl.name = name;
144 wl_output_add_listener(output, &outputListener, monitor);
148 //////////////////////////////////////////////////////////////////////////
149 ////// GLFW platform API //////
150 //////////////////////////////////////////////////////////////////////////
152 void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor)
154 if (monitor->wl.output)
155 wl_output_destroy(monitor->wl.output);
158 void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
161 *xpos = monitor->wl.x;
163 *ypos = monitor->wl.y;
166 void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor,
167 float* xscale, float* yscale)
170 *xscale = (float) monitor->wl.scale;
172 *yscale = (float) monitor->wl.scale;
175 void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor,
176 int* xpos, int* ypos,
177 int* width, int* height)
180 *xpos = monitor->wl.x;
182 *ypos = monitor->wl.y;
184 *width = monitor->modes[monitor->wl.currentMode].width;
186 *height = monitor->modes[monitor->wl.currentMode].height;
189 GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
191 *found = monitor->modeCount;
192 return monitor->modes;
195 void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
197 *mode = monitor->modes[monitor->wl.currentMode];
200 GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp)
202 _glfwInputError(GLFW_FEATURE_UNAVAILABLE,
203 "Wayland: Gamma ramp access is not available");
207 void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor,
208 const GLFWgammaramp* ramp)
210 _glfwInputError(GLFW_FEATURE_UNAVAILABLE,
211 "Wayland: Gamma ramp access is not available");
215 //////////////////////////////////////////////////////////////////////////
216 ////// GLFW native API //////
217 //////////////////////////////////////////////////////////////////////////
219 GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* handle)
221 _GLFWmonitor* monitor = (_GLFWmonitor*) handle;
222 _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
223 return monitor->wl.output;