Wise&mystical  1.0
Project about Europe
Loading...
Searching...
No Matches
wl_monitor.c
Go to the documentation of this file.
1//========================================================================
2// GLFW 3.4 Wayland - www.glfw.org
3//------------------------------------------------------------------------
4// Copyright (c) 2014 Jonas Ã…dahl <jadahl@gmail.com>
5//
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.
9//
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:
13//
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.
18//
19// 2. Altered source versions must be plainly marked as such, and must not
20// be misrepresented as being the original software.
21//
22// 3. This notice may not be removed or altered from any source
23// distribution.
24//
25//========================================================================
26// It is fine to use C99 in this file because it will not be built with VS
27//========================================================================
28
29#include "internal.h"
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34#include <errno.h>
35#include <math.h>
36
37
38static void outputHandleGeometry(void* data,
39 struct wl_output* output,
40 int32_t x,
41 int32_t y,
42 int32_t physicalWidth,
43 int32_t physicalHeight,
44 int32_t subpixel,
45 const char* make,
46 const char* model,
47 int32_t transform)
48{
49 struct _GLFWmonitor *monitor = data;
50
51 monitor->wl.x = x;
52 monitor->wl.y = y;
53 monitor->widthMM = physicalWidth;
54 monitor->heightMM = physicalHeight;
55
56 snprintf(monitor->name, sizeof(monitor->name), "%s %s", make, model);
57}
58
59static void outputHandleMode(void* data,
60 struct wl_output* output,
61 uint32_t flags,
62 int32_t width,
63 int32_t height,
64 int32_t refresh)
65{
66 struct _GLFWmonitor *monitor = data;
67 GLFWvidmode mode;
68
69 mode.width = width;
70 mode.height = height;
71 mode.redBits = 8;
72 mode.greenBits = 8;
73 mode.blueBits = 8;
74 mode.refreshRate = (int) round(refresh / 1000.0);
75
76 monitor->modeCount++;
77 monitor->modes =
78 realloc(monitor->modes, monitor->modeCount * sizeof(GLFWvidmode));
79 monitor->modes[monitor->modeCount - 1] = mode;
80
81 if (flags & WL_OUTPUT_MODE_CURRENT)
82 monitor->wl.currentMode = monitor->modeCount - 1;
83}
84
85static void outputHandleDone(void* data, struct wl_output* output)
86{
87 struct _GLFWmonitor *monitor = data;
88
89 if (monitor->widthMM <= 0 || monitor->heightMM <= 0)
90 {
91 // If Wayland does not provide a physical size, assume the default 96 DPI
92 const GLFWvidmode* mode = &monitor->modes[monitor->wl.currentMode];
93 monitor->widthMM = (int) (mode->width * 25.4f / 96.f);
94 monitor->heightMM = (int) (mode->height * 25.4f / 96.f);
95 }
96
98}
99
100static void outputHandleScale(void* data,
101 struct wl_output* output,
102 int32_t factor)
103{
104 struct _GLFWmonitor *monitor = data;
105
106 monitor->wl.scale = factor;
107}
108
109static const struct wl_output_listener outputListener = {
110 outputHandleGeometry,
111 outputHandleMode,
112 outputHandleDone,
113 outputHandleScale,
114};
115
116
120
122{
123 _GLFWmonitor *monitor;
124 struct wl_output *output;
125
126 if (version < 2)
127 {
129 "Wayland: Unsupported output interface version");
130 return;
131 }
132
133 // The actual name of this output will be set in the geometry handler.
134 monitor = _glfwAllocMonitor("", 0, 0);
135
136 output = wl_registry_bind(_glfw.wl.registry,
137 name,
138 &wl_output_interface,
139 2);
140 if (!output)
141 {
142 _glfwFreeMonitor(monitor);
143 return;
144 }
145
146 monitor->wl.scale = 1;
147 monitor->wl.output = output;
148 monitor->wl.name = name;
149
150 wl_output_add_listener(output, &outputListener, monitor);
151}
152
153
157
159{
160 if (monitor->wl.output)
161 wl_output_destroy(monitor->wl.output);
162}
163
164void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos)
165{
166 if (xpos)
167 *xpos = monitor->wl.x;
168 if (ypos)
169 *ypos = monitor->wl.y;
170}
171
173 float* xscale, float* yscale)
174{
175 if (xscale)
176 *xscale = (float) monitor->wl.scale;
177 if (yscale)
178 *yscale = (float) monitor->wl.scale;
179}
180
182 int* xpos, int* ypos,
183 int* width, int* height)
184{
185 if (xpos)
186 *xpos = monitor->wl.x;
187 if (ypos)
188 *ypos = monitor->wl.y;
189 if (width)
190 *width = monitor->modes[monitor->wl.currentMode].width;
191 if (height)
192 *height = monitor->modes[monitor->wl.currentMode].height;
193}
194
196{
197 *found = monitor->modeCount;
198 return monitor->modes;
199}
200
202{
203 *mode = monitor->modes[monitor->wl.currentMode];
204}
205
207{
209 "Wayland: Gamma ramp access is not available");
210 return GLFW_FALSE;
211}
212
214 const GLFWgammaramp* ramp)
215{
217 "Wayland: Gamma ramp access is not available");
218}
219
220
224
225GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* handle)
226{
227 _GLFWmonitor* monitor = (_GLFWmonitor*) handle;
229 return monitor->wl.output;
230}
231
#define GLFWAPI
Definition: glfw3.h:269
#define GLFW_CONNECTED
Definition: glfw3.h:1230
#define GLFW_FEATURE_UNAVAILABLE
The requested feature is not provided by the platform.
Definition: glfw3.h:810
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
Definition: glfw3.h:758
#define GLFW_FALSE
Zero.
Definition: glfw3.h:319
struct GLFWmonitor GLFWmonitor
Opaque monitor object.
Definition: glfw3.h:1307
_GLFWlibrary _glfw
Definition: init.c:46
void _glfwInputError(int code, const char *format,...)
Definition: init.c:160
void _glfwInputMonitor(_GLFWmonitor *monitor, int action, int placement)
Definition: monitor.c:97
void _glfwFreeMonitor(_GLFWmonitor *monitor)
Definition: monitor.c:180
#define _GLFW_REQUIRE_INIT_OR_RETURN(x)
Definition: internal.h:214
_GLFWmonitor * _glfwAllocMonitor(const char *name, int widthMM, int heightMM)
Definition: monitor.c:167
#define _GLFW_INSERT_LAST
Definition: internal.h:52
int GLFWbool
Definition: internal.h:61
#define NULL
Definition: miniaudio.h:3718
unsigned int uint32_t
Definition: stdint.h:80
signed int int32_t
Definition: stdint.h:77
GLFWvidmode * modes
Definition: internal.h:448
int modeCount
Definition: internal.h:449
GLFWvidmode currentMode
Definition: internal.h:450
char name[128]
Definition: internal.h:439
int heightMM
Definition: internal.h:443
Gamma ramp.
Definition: glfw3.h:1826
Video mode type.
Definition: glfw3.h:1792
int greenBits
Definition: glfw3.h:1804
int redBits
Definition: glfw3.h:1801
int width
Definition: glfw3.h:1795
int refreshRate
Definition: glfw3.h:1810
int height
Definition: glfw3.h:1798
int blueBits
Definition: glfw3.h:1807
void _glfwPlatformFreeMonitor(_GLFWmonitor *monitor)
Definition: wl_monitor.c:158
void _glfwAddOutputWayland(uint32_t name, uint32_t version)
Definition: wl_monitor.c:121
GLFWAPI struct wl_output * glfwGetWaylandMonitor(GLFWmonitor *handle)
Definition: wl_monitor.c:225
GLFWvidmode * _glfwPlatformGetVideoModes(_GLFWmonitor *monitor, int *found)
Definition: wl_monitor.c:195
void _glfwPlatformGetVideoMode(_GLFWmonitor *monitor, GLFWvidmode *mode)
Definition: wl_monitor.c:201
void _glfwPlatformSetGammaRamp(_GLFWmonitor *monitor, const GLFWgammaramp *ramp)
Definition: wl_monitor.c:213
void _glfwPlatformGetMonitorPos(_GLFWmonitor *monitor, int *xpos, int *ypos)
Definition: wl_monitor.c:164
GLFWbool _glfwPlatformGetGammaRamp(_GLFWmonitor *monitor, GLFWgammaramp *ramp)
Definition: wl_monitor.c:206
void _glfwPlatformGetMonitorContentScale(_GLFWmonitor *monitor, float *xscale, float *yscale)
Definition: wl_monitor.c:172
void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor *monitor, int *xpos, int *ypos, int *width, int *height)
Definition: wl_monitor.c:181