glfw3.c 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/GLFW/CMakeLists.txt +368 -0
  2. package/GLFW/cocoa_init.m +694 -0
  3. package/GLFW/cocoa_joystick.h +49 -0
  4. package/GLFW/cocoa_joystick.m +485 -0
  5. package/GLFW/cocoa_monitor.m +643 -0
  6. package/GLFW/cocoa_platform.h +302 -0
  7. package/GLFW/cocoa_time.c +57 -0
  8. package/GLFW/cocoa_time.h +35 -0
  9. package/GLFW/cocoa_window.m +2072 -0
  10. package/GLFW/context.c +765 -0
  11. package/GLFW/egl_context.c +911 -0
  12. package/GLFW/glfw.rc.in +30 -0
  13. package/GLFW/glfw3.c +109 -0
  14. package/GLFW/glfw3.h +6564 -0
  15. package/GLFW/glfw3native.h +663 -0
  16. package/GLFW/glx_context.c +719 -0
  17. package/GLFW/init.c +528 -0
  18. package/GLFW/input.c +1505 -0
  19. package/GLFW/internal.h +1022 -0
  20. package/GLFW/linux_joystick.c +436 -0
  21. package/GLFW/linux_joystick.h +64 -0
  22. package/GLFW/mappings.h +1001 -0
  23. package/GLFW/mappings.h.in +82 -0
  24. package/GLFW/monitor.c +548 -0
  25. package/GLFW/nsgl_context.m +384 -0
  26. package/GLFW/null_init.c +264 -0
  27. package/GLFW/null_joystick.c +56 -0
  28. package/GLFW/null_joystick.h +32 -0
  29. package/GLFW/null_monitor.c +160 -0
  30. package/GLFW/null_platform.h +271 -0
  31. package/GLFW/null_window.c +719 -0
  32. package/GLFW/osmesa_context.c +383 -0
  33. package/GLFW/platform.c +214 -0
  34. package/GLFW/platform.h +212 -0
  35. package/GLFW/posix_module.c +53 -0
  36. package/GLFW/posix_poll.c +83 -0
  37. package/GLFW/posix_poll.h +30 -0
  38. package/GLFW/posix_thread.c +107 -0
  39. package/GLFW/posix_thread.h +49 -0
  40. package/GLFW/posix_time.c +65 -0
  41. package/GLFW/posix_time.h +41 -0
  42. package/GLFW/vulkan.c +328 -0
  43. package/GLFW/wgl_context.c +798 -0
  44. package/GLFW/win32_init.c +731 -0
  45. package/GLFW/win32_joystick.c +767 -0
  46. package/GLFW/win32_joystick.h +51 -0
  47. package/GLFW/win32_module.c +51 -0
  48. package/GLFW/win32_monitor.c +569 -0
  49. package/GLFW/win32_platform.h +631 -0
  50. package/GLFW/win32_thread.c +100 -0
  51. package/GLFW/win32_thread.h +53 -0
  52. package/GLFW/win32_time.c +54 -0
  53. package/GLFW/win32_time.h +43 -0
  54. package/GLFW/win32_window.c +2592 -0
  55. package/GLFW/window.c +1172 -0
  56. package/GLFW/wl_init.c +1003 -0
  57. package/GLFW/wl_monitor.c +274 -0
  58. package/GLFW/wl_platform.h +691 -0
  59. package/GLFW/wl_window.c +3308 -0
  60. package/GLFW/x11_init.c +1656 -0
  61. package/GLFW/x11_monitor.c +641 -0
  62. package/GLFW/x11_platform.h +1004 -0
  63. package/GLFW/x11_window.c +3357 -0
  64. package/GLFW/xkb_unicode.c +943 -0
  65. package/GLFW/xkb_unicode.h +30 -0
  66. package/LICENSE +22 -0
  67. package/README.md +236 -0
  68. package/package.json +32 -0
package/GLFW/wl_init.c ADDED
@@ -0,0 +1,1003 @@
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
+
27
+ #include "internal.h"
28
+
29
+ #if defined(_GLFW_WAYLAND)
30
+
31
+ #include <errno.h>
32
+ #include <limits.h>
33
+ #include <linux/input.h>
34
+ #include <stdio.h>
35
+ #include <stdlib.h>
36
+ #include <string.h>
37
+ #include <sys/mman.h>
38
+ #include <sys/timerfd.h>
39
+ #include <unistd.h>
40
+ #include <time.h>
41
+ #include <assert.h>
42
+
43
+ #include "wayland-client-protocol.h"
44
+ #include "xdg-shell-client-protocol.h"
45
+ #include "xdg-decoration-unstable-v1-client-protocol.h"
46
+ #include "viewporter-client-protocol.h"
47
+ #include "relative-pointer-unstable-v1-client-protocol.h"
48
+ #include "pointer-constraints-unstable-v1-client-protocol.h"
49
+ #include "fractional-scale-v1-client-protocol.h"
50
+ #include "xdg-activation-v1-client-protocol.h"
51
+ #include "idle-inhibit-unstable-v1-client-protocol.h"
52
+
53
+ // NOTE: Versions of wayland-scanner prior to 1.17.91 named every global array of
54
+ // wl_interface pointers 'types', making it impossible to combine several unmodified
55
+ // private-code files into a single compilation unit
56
+ // HACK: We override this name with a macro for each file, allowing them to coexist
57
+
58
+ #define types _glfw_wayland_types
59
+ #include "wayland-client-protocol-code.h"
60
+ #undef types
61
+
62
+ #define types _glfw_xdg_shell_types
63
+ #include "xdg-shell-client-protocol-code.h"
64
+ #undef types
65
+
66
+ #define types _glfw_xdg_decoration_types
67
+ #include "xdg-decoration-unstable-v1-client-protocol-code.h"
68
+ #undef types
69
+
70
+ #define types _glfw_viewporter_types
71
+ #include "viewporter-client-protocol-code.h"
72
+ #undef types
73
+
74
+ #define types _glfw_relative_pointer_types
75
+ #include "relative-pointer-unstable-v1-client-protocol-code.h"
76
+ #undef types
77
+
78
+ #define types _glfw_pointer_constraints_types
79
+ #include "pointer-constraints-unstable-v1-client-protocol-code.h"
80
+ #undef types
81
+
82
+ #define types _glfw_fractional_scale_types
83
+ #include "fractional-scale-v1-client-protocol-code.h"
84
+ #undef types
85
+
86
+ #define types _glfw_xdg_activation_types
87
+ #include "xdg-activation-v1-client-protocol-code.h"
88
+ #undef types
89
+
90
+ #define types _glfw_idle_inhibit_types
91
+ #include "idle-inhibit-unstable-v1-client-protocol-code.h"
92
+ #undef types
93
+
94
+ static void wmBaseHandlePing(void* userData,
95
+ struct xdg_wm_base* wmBase,
96
+ uint32_t serial)
97
+ {
98
+ xdg_wm_base_pong(wmBase, serial);
99
+ }
100
+
101
+ static const struct xdg_wm_base_listener wmBaseListener =
102
+ {
103
+ wmBaseHandlePing
104
+ };
105
+
106
+ static void registryHandleGlobal(void* userData,
107
+ struct wl_registry* registry,
108
+ uint32_t name,
109
+ const char* interface,
110
+ uint32_t version)
111
+ {
112
+ if (strcmp(interface, "wl_compositor") == 0)
113
+ {
114
+ _glfw.wl.compositor =
115
+ wl_registry_bind(registry, name, &wl_compositor_interface,
116
+ _glfw_min(3, version));
117
+ }
118
+ else if (strcmp(interface, "wl_subcompositor") == 0)
119
+ {
120
+ _glfw.wl.subcompositor =
121
+ wl_registry_bind(registry, name, &wl_subcompositor_interface, 1);
122
+ }
123
+ else if (strcmp(interface, "wl_shm") == 0)
124
+ {
125
+ _glfw.wl.shm =
126
+ wl_registry_bind(registry, name, &wl_shm_interface, 1);
127
+ }
128
+ else if (strcmp(interface, "wl_output") == 0)
129
+ {
130
+ _glfwAddOutputWayland(name, version);
131
+ }
132
+ else if (strcmp(interface, "wl_seat") == 0)
133
+ {
134
+ if (!_glfw.wl.seat)
135
+ {
136
+ _glfw.wl.seat =
137
+ wl_registry_bind(registry, name, &wl_seat_interface,
138
+ _glfw_min(4, version));
139
+ _glfwAddSeatListenerWayland(_glfw.wl.seat);
140
+ }
141
+ }
142
+ else if (strcmp(interface, "wl_data_device_manager") == 0)
143
+ {
144
+ if (!_glfw.wl.dataDeviceManager)
145
+ {
146
+ _glfw.wl.dataDeviceManager =
147
+ wl_registry_bind(registry, name,
148
+ &wl_data_device_manager_interface, 1);
149
+ }
150
+ }
151
+ else if (strcmp(interface, "xdg_wm_base") == 0)
152
+ {
153
+ _glfw.wl.wmBase =
154
+ wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
155
+ xdg_wm_base_add_listener(_glfw.wl.wmBase, &wmBaseListener, NULL);
156
+ }
157
+ else if (strcmp(interface, "zxdg_decoration_manager_v1") == 0)
158
+ {
159
+ _glfw.wl.decorationManager =
160
+ wl_registry_bind(registry, name,
161
+ &zxdg_decoration_manager_v1_interface,
162
+ 1);
163
+ }
164
+ else if (strcmp(interface, "wp_viewporter") == 0)
165
+ {
166
+ _glfw.wl.viewporter =
167
+ wl_registry_bind(registry, name, &wp_viewporter_interface, 1);
168
+ }
169
+ else if (strcmp(interface, "zwp_relative_pointer_manager_v1") == 0)
170
+ {
171
+ _glfw.wl.relativePointerManager =
172
+ wl_registry_bind(registry, name,
173
+ &zwp_relative_pointer_manager_v1_interface,
174
+ 1);
175
+ }
176
+ else if (strcmp(interface, "zwp_pointer_constraints_v1") == 0)
177
+ {
178
+ _glfw.wl.pointerConstraints =
179
+ wl_registry_bind(registry, name,
180
+ &zwp_pointer_constraints_v1_interface,
181
+ 1);
182
+ }
183
+ else if (strcmp(interface, "zwp_idle_inhibit_manager_v1") == 0)
184
+ {
185
+ _glfw.wl.idleInhibitManager =
186
+ wl_registry_bind(registry, name,
187
+ &zwp_idle_inhibit_manager_v1_interface,
188
+ 1);
189
+ }
190
+ else if (strcmp(interface, "xdg_activation_v1") == 0)
191
+ {
192
+ _glfw.wl.activationManager =
193
+ wl_registry_bind(registry, name,
194
+ &xdg_activation_v1_interface,
195
+ 1);
196
+ }
197
+ else if (strcmp(interface, "wp_fractional_scale_manager_v1") == 0)
198
+ {
199
+ _glfw.wl.fractionalScaleManager =
200
+ wl_registry_bind(registry, name,
201
+ &wp_fractional_scale_manager_v1_interface,
202
+ 1);
203
+ }
204
+ }
205
+
206
+ static void registryHandleGlobalRemove(void* userData,
207
+ struct wl_registry* registry,
208
+ uint32_t name)
209
+ {
210
+ for (int i = 0; i < _glfw.monitorCount; ++i)
211
+ {
212
+ _GLFWmonitor* monitor = _glfw.monitors[i];
213
+ if (monitor->wl.name == name)
214
+ {
215
+ _glfwInputMonitor(monitor, GLFW_DISCONNECTED, 0);
216
+ return;
217
+ }
218
+ }
219
+ }
220
+
221
+
222
+ static const struct wl_registry_listener registryListener =
223
+ {
224
+ registryHandleGlobal,
225
+ registryHandleGlobalRemove
226
+ };
227
+
228
+ void libdecorHandleError(struct libdecor* context,
229
+ enum libdecor_error error,
230
+ const char* message)
231
+ {
232
+ _glfwInputError(GLFW_PLATFORM_ERROR,
233
+ "Wayland: libdecor error %u: %s",
234
+ error, message);
235
+ }
236
+
237
+ static const struct libdecor_interface libdecorInterface =
238
+ {
239
+ libdecorHandleError
240
+ };
241
+
242
+ static void libdecorReadyCallback(void* userData,
243
+ struct wl_callback* callback,
244
+ uint32_t time)
245
+ {
246
+ _glfw.wl.libdecor.ready = GLFW_TRUE;
247
+
248
+ assert(_glfw.wl.libdecor.callback == callback);
249
+ wl_callback_destroy(_glfw.wl.libdecor.callback);
250
+ _glfw.wl.libdecor.callback = NULL;
251
+ }
252
+
253
+ static const struct wl_callback_listener libdecorReadyListener =
254
+ {
255
+ libdecorReadyCallback
256
+ };
257
+
258
+ // Create key code translation tables
259
+ //
260
+ static void createKeyTables(void)
261
+ {
262
+ memset(_glfw.wl.keycodes, -1, sizeof(_glfw.wl.keycodes));
263
+ memset(_glfw.wl.scancodes, -1, sizeof(_glfw.wl.scancodes));
264
+
265
+ _glfw.wl.keycodes[KEY_GRAVE] = GLFW_KEY_GRAVE_ACCENT;
266
+ _glfw.wl.keycodes[KEY_1] = GLFW_KEY_1;
267
+ _glfw.wl.keycodes[KEY_2] = GLFW_KEY_2;
268
+ _glfw.wl.keycodes[KEY_3] = GLFW_KEY_3;
269
+ _glfw.wl.keycodes[KEY_4] = GLFW_KEY_4;
270
+ _glfw.wl.keycodes[KEY_5] = GLFW_KEY_5;
271
+ _glfw.wl.keycodes[KEY_6] = GLFW_KEY_6;
272
+ _glfw.wl.keycodes[KEY_7] = GLFW_KEY_7;
273
+ _glfw.wl.keycodes[KEY_8] = GLFW_KEY_8;
274
+ _glfw.wl.keycodes[KEY_9] = GLFW_KEY_9;
275
+ _glfw.wl.keycodes[KEY_0] = GLFW_KEY_0;
276
+ _glfw.wl.keycodes[KEY_SPACE] = GLFW_KEY_SPACE;
277
+ _glfw.wl.keycodes[KEY_MINUS] = GLFW_KEY_MINUS;
278
+ _glfw.wl.keycodes[KEY_EQUAL] = GLFW_KEY_EQUAL;
279
+ _glfw.wl.keycodes[KEY_Q] = GLFW_KEY_Q;
280
+ _glfw.wl.keycodes[KEY_W] = GLFW_KEY_W;
281
+ _glfw.wl.keycodes[KEY_E] = GLFW_KEY_E;
282
+ _glfw.wl.keycodes[KEY_R] = GLFW_KEY_R;
283
+ _glfw.wl.keycodes[KEY_T] = GLFW_KEY_T;
284
+ _glfw.wl.keycodes[KEY_Y] = GLFW_KEY_Y;
285
+ _glfw.wl.keycodes[KEY_U] = GLFW_KEY_U;
286
+ _glfw.wl.keycodes[KEY_I] = GLFW_KEY_I;
287
+ _glfw.wl.keycodes[KEY_O] = GLFW_KEY_O;
288
+ _glfw.wl.keycodes[KEY_P] = GLFW_KEY_P;
289
+ _glfw.wl.keycodes[KEY_LEFTBRACE] = GLFW_KEY_LEFT_BRACKET;
290
+ _glfw.wl.keycodes[KEY_RIGHTBRACE] = GLFW_KEY_RIGHT_BRACKET;
291
+ _glfw.wl.keycodes[KEY_A] = GLFW_KEY_A;
292
+ _glfw.wl.keycodes[KEY_S] = GLFW_KEY_S;
293
+ _glfw.wl.keycodes[KEY_D] = GLFW_KEY_D;
294
+ _glfw.wl.keycodes[KEY_F] = GLFW_KEY_F;
295
+ _glfw.wl.keycodes[KEY_G] = GLFW_KEY_G;
296
+ _glfw.wl.keycodes[KEY_H] = GLFW_KEY_H;
297
+ _glfw.wl.keycodes[KEY_J] = GLFW_KEY_J;
298
+ _glfw.wl.keycodes[KEY_K] = GLFW_KEY_K;
299
+ _glfw.wl.keycodes[KEY_L] = GLFW_KEY_L;
300
+ _glfw.wl.keycodes[KEY_SEMICOLON] = GLFW_KEY_SEMICOLON;
301
+ _glfw.wl.keycodes[KEY_APOSTROPHE] = GLFW_KEY_APOSTROPHE;
302
+ _glfw.wl.keycodes[KEY_Z] = GLFW_KEY_Z;
303
+ _glfw.wl.keycodes[KEY_X] = GLFW_KEY_X;
304
+ _glfw.wl.keycodes[KEY_C] = GLFW_KEY_C;
305
+ _glfw.wl.keycodes[KEY_V] = GLFW_KEY_V;
306
+ _glfw.wl.keycodes[KEY_B] = GLFW_KEY_B;
307
+ _glfw.wl.keycodes[KEY_N] = GLFW_KEY_N;
308
+ _glfw.wl.keycodes[KEY_M] = GLFW_KEY_M;
309
+ _glfw.wl.keycodes[KEY_COMMA] = GLFW_KEY_COMMA;
310
+ _glfw.wl.keycodes[KEY_DOT] = GLFW_KEY_PERIOD;
311
+ _glfw.wl.keycodes[KEY_SLASH] = GLFW_KEY_SLASH;
312
+ _glfw.wl.keycodes[KEY_BACKSLASH] = GLFW_KEY_BACKSLASH;
313
+ _glfw.wl.keycodes[KEY_ESC] = GLFW_KEY_ESCAPE;
314
+ _glfw.wl.keycodes[KEY_TAB] = GLFW_KEY_TAB;
315
+ _glfw.wl.keycodes[KEY_LEFTSHIFT] = GLFW_KEY_LEFT_SHIFT;
316
+ _glfw.wl.keycodes[KEY_RIGHTSHIFT] = GLFW_KEY_RIGHT_SHIFT;
317
+ _glfw.wl.keycodes[KEY_LEFTCTRL] = GLFW_KEY_LEFT_CONTROL;
318
+ _glfw.wl.keycodes[KEY_RIGHTCTRL] = GLFW_KEY_RIGHT_CONTROL;
319
+ _glfw.wl.keycodes[KEY_LEFTALT] = GLFW_KEY_LEFT_ALT;
320
+ _glfw.wl.keycodes[KEY_RIGHTALT] = GLFW_KEY_RIGHT_ALT;
321
+ _glfw.wl.keycodes[KEY_LEFTMETA] = GLFW_KEY_LEFT_SUPER;
322
+ _glfw.wl.keycodes[KEY_RIGHTMETA] = GLFW_KEY_RIGHT_SUPER;
323
+ _glfw.wl.keycodes[KEY_COMPOSE] = GLFW_KEY_MENU;
324
+ _glfw.wl.keycodes[KEY_NUMLOCK] = GLFW_KEY_NUM_LOCK;
325
+ _glfw.wl.keycodes[KEY_CAPSLOCK] = GLFW_KEY_CAPS_LOCK;
326
+ _glfw.wl.keycodes[KEY_PRINT] = GLFW_KEY_PRINT_SCREEN;
327
+ _glfw.wl.keycodes[KEY_SCROLLLOCK] = GLFW_KEY_SCROLL_LOCK;
328
+ _glfw.wl.keycodes[KEY_PAUSE] = GLFW_KEY_PAUSE;
329
+ _glfw.wl.keycodes[KEY_DELETE] = GLFW_KEY_DELETE;
330
+ _glfw.wl.keycodes[KEY_BACKSPACE] = GLFW_KEY_BACKSPACE;
331
+ _glfw.wl.keycodes[KEY_ENTER] = GLFW_KEY_ENTER;
332
+ _glfw.wl.keycodes[KEY_HOME] = GLFW_KEY_HOME;
333
+ _glfw.wl.keycodes[KEY_END] = GLFW_KEY_END;
334
+ _glfw.wl.keycodes[KEY_PAGEUP] = GLFW_KEY_PAGE_UP;
335
+ _glfw.wl.keycodes[KEY_PAGEDOWN] = GLFW_KEY_PAGE_DOWN;
336
+ _glfw.wl.keycodes[KEY_INSERT] = GLFW_KEY_INSERT;
337
+ _glfw.wl.keycodes[KEY_LEFT] = GLFW_KEY_LEFT;
338
+ _glfw.wl.keycodes[KEY_RIGHT] = GLFW_KEY_RIGHT;
339
+ _glfw.wl.keycodes[KEY_DOWN] = GLFW_KEY_DOWN;
340
+ _glfw.wl.keycodes[KEY_UP] = GLFW_KEY_UP;
341
+ _glfw.wl.keycodes[KEY_F1] = GLFW_KEY_F1;
342
+ _glfw.wl.keycodes[KEY_F2] = GLFW_KEY_F2;
343
+ _glfw.wl.keycodes[KEY_F3] = GLFW_KEY_F3;
344
+ _glfw.wl.keycodes[KEY_F4] = GLFW_KEY_F4;
345
+ _glfw.wl.keycodes[KEY_F5] = GLFW_KEY_F5;
346
+ _glfw.wl.keycodes[KEY_F6] = GLFW_KEY_F6;
347
+ _glfw.wl.keycodes[KEY_F7] = GLFW_KEY_F7;
348
+ _glfw.wl.keycodes[KEY_F8] = GLFW_KEY_F8;
349
+ _glfw.wl.keycodes[KEY_F9] = GLFW_KEY_F9;
350
+ _glfw.wl.keycodes[KEY_F10] = GLFW_KEY_F10;
351
+ _glfw.wl.keycodes[KEY_F11] = GLFW_KEY_F11;
352
+ _glfw.wl.keycodes[KEY_F12] = GLFW_KEY_F12;
353
+ _glfw.wl.keycodes[KEY_F13] = GLFW_KEY_F13;
354
+ _glfw.wl.keycodes[KEY_F14] = GLFW_KEY_F14;
355
+ _glfw.wl.keycodes[KEY_F15] = GLFW_KEY_F15;
356
+ _glfw.wl.keycodes[KEY_F16] = GLFW_KEY_F16;
357
+ _glfw.wl.keycodes[KEY_F17] = GLFW_KEY_F17;
358
+ _glfw.wl.keycodes[KEY_F18] = GLFW_KEY_F18;
359
+ _glfw.wl.keycodes[KEY_F19] = GLFW_KEY_F19;
360
+ _glfw.wl.keycodes[KEY_F20] = GLFW_KEY_F20;
361
+ _glfw.wl.keycodes[KEY_F21] = GLFW_KEY_F21;
362
+ _glfw.wl.keycodes[KEY_F22] = GLFW_KEY_F22;
363
+ _glfw.wl.keycodes[KEY_F23] = GLFW_KEY_F23;
364
+ _glfw.wl.keycodes[KEY_F24] = GLFW_KEY_F24;
365
+ _glfw.wl.keycodes[KEY_KPSLASH] = GLFW_KEY_KP_DIVIDE;
366
+ _glfw.wl.keycodes[KEY_KPASTERISK] = GLFW_KEY_KP_MULTIPLY;
367
+ _glfw.wl.keycodes[KEY_KPMINUS] = GLFW_KEY_KP_SUBTRACT;
368
+ _glfw.wl.keycodes[KEY_KPPLUS] = GLFW_KEY_KP_ADD;
369
+ _glfw.wl.keycodes[KEY_KP0] = GLFW_KEY_KP_0;
370
+ _glfw.wl.keycodes[KEY_KP1] = GLFW_KEY_KP_1;
371
+ _glfw.wl.keycodes[KEY_KP2] = GLFW_KEY_KP_2;
372
+ _glfw.wl.keycodes[KEY_KP3] = GLFW_KEY_KP_3;
373
+ _glfw.wl.keycodes[KEY_KP4] = GLFW_KEY_KP_4;
374
+ _glfw.wl.keycodes[KEY_KP5] = GLFW_KEY_KP_5;
375
+ _glfw.wl.keycodes[KEY_KP6] = GLFW_KEY_KP_6;
376
+ _glfw.wl.keycodes[KEY_KP7] = GLFW_KEY_KP_7;
377
+ _glfw.wl.keycodes[KEY_KP8] = GLFW_KEY_KP_8;
378
+ _glfw.wl.keycodes[KEY_KP9] = GLFW_KEY_KP_9;
379
+ _glfw.wl.keycodes[KEY_KPDOT] = GLFW_KEY_KP_DECIMAL;
380
+ _glfw.wl.keycodes[KEY_KPEQUAL] = GLFW_KEY_KP_EQUAL;
381
+ _glfw.wl.keycodes[KEY_KPENTER] = GLFW_KEY_KP_ENTER;
382
+ _glfw.wl.keycodes[KEY_102ND] = GLFW_KEY_WORLD_2;
383
+
384
+ for (int scancode = 0; scancode < 256; scancode++)
385
+ {
386
+ if (_glfw.wl.keycodes[scancode] > 0)
387
+ _glfw.wl.scancodes[_glfw.wl.keycodes[scancode]] = scancode;
388
+ }
389
+ }
390
+
391
+ static GLFWbool loadCursorTheme(void)
392
+ {
393
+ int cursorSize = 16;
394
+
395
+ const char* sizeString = getenv("XCURSOR_SIZE");
396
+ if (sizeString)
397
+ {
398
+ errno = 0;
399
+ const long cursorSizeLong = strtol(sizeString, NULL, 10);
400
+ if (errno == 0 && cursorSizeLong > 0 && cursorSizeLong < INT_MAX)
401
+ cursorSize = (int) cursorSizeLong;
402
+ }
403
+
404
+ const char* themeName = getenv("XCURSOR_THEME");
405
+
406
+ _glfw.wl.cursorTheme = wl_cursor_theme_load(themeName, cursorSize, _glfw.wl.shm);
407
+ if (!_glfw.wl.cursorTheme)
408
+ {
409
+ _glfwInputError(GLFW_PLATFORM_ERROR,
410
+ "Wayland: Failed to load default cursor theme");
411
+ return GLFW_FALSE;
412
+ }
413
+
414
+ // If this happens to be NULL, we just fallback to the scale=1 version.
415
+ _glfw.wl.cursorThemeHiDPI =
416
+ wl_cursor_theme_load(themeName, cursorSize * 2, _glfw.wl.shm);
417
+
418
+ _glfw.wl.cursorSurface = wl_compositor_create_surface(_glfw.wl.compositor);
419
+ _glfw.wl.cursorTimerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
420
+ return GLFW_TRUE;
421
+ }
422
+
423
+
424
+ //////////////////////////////////////////////////////////////////////////
425
+ ////// GLFW platform API //////
426
+ //////////////////////////////////////////////////////////////////////////
427
+
428
+ GLFWbool _glfwConnectWayland(int platformID, _GLFWplatform* platform)
429
+ {
430
+ const _GLFWplatform wayland =
431
+ {
432
+ .platformID = GLFW_PLATFORM_WAYLAND,
433
+ .init = _glfwInitWayland,
434
+ .terminate = _glfwTerminateWayland,
435
+ .getCursorPos = _glfwGetCursorPosWayland,
436
+ .setCursorPos = _glfwSetCursorPosWayland,
437
+ .setCursorMode = _glfwSetCursorModeWayland,
438
+ .setRawMouseMotion = _glfwSetRawMouseMotionWayland,
439
+ .rawMouseMotionSupported = _glfwRawMouseMotionSupportedWayland,
440
+ .createCursor = _glfwCreateCursorWayland,
441
+ .createStandardCursor = _glfwCreateStandardCursorWayland,
442
+ .destroyCursor = _glfwDestroyCursorWayland,
443
+ .setCursor = _glfwSetCursorWayland,
444
+ .getScancodeName = _glfwGetScancodeNameWayland,
445
+ .getKeyScancode = _glfwGetKeyScancodeWayland,
446
+ .setClipboardString = _glfwSetClipboardStringWayland,
447
+ .getClipboardString = _glfwGetClipboardStringWayland,
448
+ #if defined(GLFW_BUILD_LINUX_JOYSTICK)
449
+ .initJoysticks = _glfwInitJoysticksLinux,
450
+ .terminateJoysticks = _glfwTerminateJoysticksLinux,
451
+ .pollJoystick = _glfwPollJoystickLinux,
452
+ .getMappingName = _glfwGetMappingNameLinux,
453
+ .updateGamepadGUID = _glfwUpdateGamepadGUIDLinux,
454
+ #else
455
+ .initJoysticks = _glfwInitJoysticksNull,
456
+ .terminateJoysticks = _glfwTerminateJoysticksNull,
457
+ .pollJoystick = _glfwPollJoystickNull,
458
+ .getMappingName = _glfwGetMappingNameNull,
459
+ .updateGamepadGUID = _glfwUpdateGamepadGUIDNull,
460
+ #endif
461
+ .freeMonitor = _glfwFreeMonitorWayland,
462
+ .getMonitorPos = _glfwGetMonitorPosWayland,
463
+ .getMonitorContentScale = _glfwGetMonitorContentScaleWayland,
464
+ .getMonitorWorkarea = _glfwGetMonitorWorkareaWayland,
465
+ .getVideoModes = _glfwGetVideoModesWayland,
466
+ .getVideoMode = _glfwGetVideoModeWayland,
467
+ .getGammaRamp = _glfwGetGammaRampWayland,
468
+ .setGammaRamp = _glfwSetGammaRampWayland,
469
+ .createWindow = _glfwCreateWindowWayland,
470
+ .destroyWindow = _glfwDestroyWindowWayland,
471
+ .setWindowTitle = _glfwSetWindowTitleWayland,
472
+ .setWindowIcon = _glfwSetWindowIconWayland,
473
+ .getWindowPos = _glfwGetWindowPosWayland,
474
+ .setWindowPos = _glfwSetWindowPosWayland,
475
+ .getWindowSize = _glfwGetWindowSizeWayland,
476
+ .setWindowSize = _glfwSetWindowSizeWayland,
477
+ .setWindowSizeLimits = _glfwSetWindowSizeLimitsWayland,
478
+ .setWindowAspectRatio = _glfwSetWindowAspectRatioWayland,
479
+ .getFramebufferSize = _glfwGetFramebufferSizeWayland,
480
+ .getWindowFrameSize = _glfwGetWindowFrameSizeWayland,
481
+ .getWindowContentScale = _glfwGetWindowContentScaleWayland,
482
+ .iconifyWindow = _glfwIconifyWindowWayland,
483
+ .restoreWindow = _glfwRestoreWindowWayland,
484
+ .maximizeWindow = _glfwMaximizeWindowWayland,
485
+ .showWindow = _glfwShowWindowWayland,
486
+ .hideWindow = _glfwHideWindowWayland,
487
+ .requestWindowAttention = _glfwRequestWindowAttentionWayland,
488
+ .focusWindow = _glfwFocusWindowWayland,
489
+ .setWindowMonitor = _glfwSetWindowMonitorWayland,
490
+ .windowFocused = _glfwWindowFocusedWayland,
491
+ .windowIconified = _glfwWindowIconifiedWayland,
492
+ .windowVisible = _glfwWindowVisibleWayland,
493
+ .windowMaximized = _glfwWindowMaximizedWayland,
494
+ .windowHovered = _glfwWindowHoveredWayland,
495
+ .framebufferTransparent = _glfwFramebufferTransparentWayland,
496
+ .getWindowOpacity = _glfwGetWindowOpacityWayland,
497
+ .setWindowResizable = _glfwSetWindowResizableWayland,
498
+ .setWindowDecorated = _glfwSetWindowDecoratedWayland,
499
+ .setWindowFloating = _glfwSetWindowFloatingWayland,
500
+ .setWindowOpacity = _glfwSetWindowOpacityWayland,
501
+ .setWindowMousePassthrough = _glfwSetWindowMousePassthroughWayland,
502
+ .pollEvents = _glfwPollEventsWayland,
503
+ .waitEvents = _glfwWaitEventsWayland,
504
+ .waitEventsTimeout = _glfwWaitEventsTimeoutWayland,
505
+ .postEmptyEvent = _glfwPostEmptyEventWayland,
506
+ .getEGLPlatform = _glfwGetEGLPlatformWayland,
507
+ .getEGLNativeDisplay = _glfwGetEGLNativeDisplayWayland,
508
+ .getEGLNativeWindow = _glfwGetEGLNativeWindowWayland,
509
+ .getRequiredInstanceExtensions = _glfwGetRequiredInstanceExtensionsWayland,
510
+ .getPhysicalDevicePresentationSupport = _glfwGetPhysicalDevicePresentationSupportWayland,
511
+ .createWindowSurface = _glfwCreateWindowSurfaceWayland
512
+ };
513
+
514
+ void* module = _glfwPlatformLoadModule("libwayland-client.so.0");
515
+ if (!module)
516
+ {
517
+ if (platformID == GLFW_PLATFORM_WAYLAND)
518
+ {
519
+ _glfwInputError(GLFW_PLATFORM_ERROR,
520
+ "Wayland: Failed to load libwayland-client");
521
+ }
522
+
523
+ return GLFW_FALSE;
524
+ }
525
+
526
+ PFN_wl_display_connect wl_display_connect = (PFN_wl_display_connect)
527
+ _glfwPlatformGetModuleSymbol(module, "wl_display_connect");
528
+ if (!wl_display_connect)
529
+ {
530
+ if (platformID == GLFW_PLATFORM_WAYLAND)
531
+ {
532
+ _glfwInputError(GLFW_PLATFORM_ERROR,
533
+ "Wayland: Failed to load libwayland-client entry point");
534
+ }
535
+
536
+ _glfwPlatformFreeModule(module);
537
+ return GLFW_FALSE;
538
+ }
539
+
540
+ struct wl_display* display = wl_display_connect(NULL);
541
+ if (!display)
542
+ {
543
+ if (platformID == GLFW_PLATFORM_WAYLAND)
544
+ _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Failed to connect to display");
545
+
546
+ _glfwPlatformFreeModule(module);
547
+ return GLFW_FALSE;
548
+ }
549
+
550
+ _glfw.wl.display = display;
551
+ _glfw.wl.client.handle = module;
552
+
553
+ *platform = wayland;
554
+ return GLFW_TRUE;
555
+ }
556
+
557
+ int _glfwInitWayland(void)
558
+ {
559
+ // These must be set before any failure checks
560
+ _glfw.wl.keyRepeatTimerfd = -1;
561
+ _glfw.wl.cursorTimerfd = -1;
562
+
563
+ _glfw.wl.tag = glfwGetVersionString();
564
+
565
+ _glfw.wl.client.display_flush = (PFN_wl_display_flush)
566
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_display_flush");
567
+ _glfw.wl.client.display_cancel_read = (PFN_wl_display_cancel_read)
568
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_display_cancel_read");
569
+ _glfw.wl.client.display_dispatch_pending = (PFN_wl_display_dispatch_pending)
570
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_display_dispatch_pending");
571
+ _glfw.wl.client.display_read_events = (PFN_wl_display_read_events)
572
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_display_read_events");
573
+ _glfw.wl.client.display_disconnect = (PFN_wl_display_disconnect)
574
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_display_disconnect");
575
+ _glfw.wl.client.display_roundtrip = (PFN_wl_display_roundtrip)
576
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_display_roundtrip");
577
+ _glfw.wl.client.display_get_fd = (PFN_wl_display_get_fd)
578
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_display_get_fd");
579
+ _glfw.wl.client.display_prepare_read = (PFN_wl_display_prepare_read)
580
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_display_prepare_read");
581
+ _glfw.wl.client.proxy_marshal = (PFN_wl_proxy_marshal)
582
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_marshal");
583
+ _glfw.wl.client.proxy_add_listener = (PFN_wl_proxy_add_listener)
584
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_add_listener");
585
+ _glfw.wl.client.proxy_destroy = (PFN_wl_proxy_destroy)
586
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_destroy");
587
+ _glfw.wl.client.proxy_marshal_constructor = (PFN_wl_proxy_marshal_constructor)
588
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_marshal_constructor");
589
+ _glfw.wl.client.proxy_marshal_constructor_versioned = (PFN_wl_proxy_marshal_constructor_versioned)
590
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_marshal_constructor_versioned");
591
+ _glfw.wl.client.proxy_get_user_data = (PFN_wl_proxy_get_user_data)
592
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_get_user_data");
593
+ _glfw.wl.client.proxy_set_user_data = (PFN_wl_proxy_set_user_data)
594
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_set_user_data");
595
+ _glfw.wl.client.proxy_get_tag = (PFN_wl_proxy_get_tag)
596
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_get_tag");
597
+ _glfw.wl.client.proxy_set_tag = (PFN_wl_proxy_set_tag)
598
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_set_tag");
599
+ _glfw.wl.client.proxy_get_version = (PFN_wl_proxy_get_version)
600
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_get_version");
601
+ _glfw.wl.client.proxy_marshal_flags = (PFN_wl_proxy_marshal_flags)
602
+ _glfwPlatformGetModuleSymbol(_glfw.wl.client.handle, "wl_proxy_marshal_flags");
603
+
604
+ if (!_glfw.wl.client.display_flush ||
605
+ !_glfw.wl.client.display_cancel_read ||
606
+ !_glfw.wl.client.display_dispatch_pending ||
607
+ !_glfw.wl.client.display_read_events ||
608
+ !_glfw.wl.client.display_disconnect ||
609
+ !_glfw.wl.client.display_roundtrip ||
610
+ !_glfw.wl.client.display_get_fd ||
611
+ !_glfw.wl.client.display_prepare_read ||
612
+ !_glfw.wl.client.proxy_marshal ||
613
+ !_glfw.wl.client.proxy_add_listener ||
614
+ !_glfw.wl.client.proxy_destroy ||
615
+ !_glfw.wl.client.proxy_marshal_constructor ||
616
+ !_glfw.wl.client.proxy_marshal_constructor_versioned ||
617
+ !_glfw.wl.client.proxy_get_user_data ||
618
+ !_glfw.wl.client.proxy_set_user_data ||
619
+ !_glfw.wl.client.proxy_get_tag ||
620
+ !_glfw.wl.client.proxy_set_tag)
621
+ {
622
+ _glfwInputError(GLFW_PLATFORM_ERROR,
623
+ "Wayland: Failed to load libwayland-client entry point");
624
+ return GLFW_FALSE;
625
+ }
626
+
627
+ _glfw.wl.cursor.handle = _glfwPlatformLoadModule("libwayland-cursor.so.0");
628
+ if (!_glfw.wl.cursor.handle)
629
+ {
630
+ _glfwInputError(GLFW_PLATFORM_ERROR,
631
+ "Wayland: Failed to load libwayland-cursor");
632
+ return GLFW_FALSE;
633
+ }
634
+
635
+ _glfw.wl.cursor.theme_load = (PFN_wl_cursor_theme_load)
636
+ _glfwPlatformGetModuleSymbol(_glfw.wl.cursor.handle, "wl_cursor_theme_load");
637
+ _glfw.wl.cursor.theme_destroy = (PFN_wl_cursor_theme_destroy)
638
+ _glfwPlatformGetModuleSymbol(_glfw.wl.cursor.handle, "wl_cursor_theme_destroy");
639
+ _glfw.wl.cursor.theme_get_cursor = (PFN_wl_cursor_theme_get_cursor)
640
+ _glfwPlatformGetModuleSymbol(_glfw.wl.cursor.handle, "wl_cursor_theme_get_cursor");
641
+ _glfw.wl.cursor.image_get_buffer = (PFN_wl_cursor_image_get_buffer)
642
+ _glfwPlatformGetModuleSymbol(_glfw.wl.cursor.handle, "wl_cursor_image_get_buffer");
643
+
644
+ _glfw.wl.egl.handle = _glfwPlatformLoadModule("libwayland-egl.so.1");
645
+ if (!_glfw.wl.egl.handle)
646
+ {
647
+ _glfwInputError(GLFW_PLATFORM_ERROR,
648
+ "Wayland: Failed to load libwayland-egl");
649
+ return GLFW_FALSE;
650
+ }
651
+
652
+ _glfw.wl.egl.window_create = (PFN_wl_egl_window_create)
653
+ _glfwPlatformGetModuleSymbol(_glfw.wl.egl.handle, "wl_egl_window_create");
654
+ _glfw.wl.egl.window_destroy = (PFN_wl_egl_window_destroy)
655
+ _glfwPlatformGetModuleSymbol(_glfw.wl.egl.handle, "wl_egl_window_destroy");
656
+ _glfw.wl.egl.window_resize = (PFN_wl_egl_window_resize)
657
+ _glfwPlatformGetModuleSymbol(_glfw.wl.egl.handle, "wl_egl_window_resize");
658
+
659
+ _glfw.wl.xkb.handle = _glfwPlatformLoadModule("libxkbcommon.so.0");
660
+ if (!_glfw.wl.xkb.handle)
661
+ {
662
+ _glfwInputError(GLFW_PLATFORM_ERROR,
663
+ "Wayland: Failed to load libxkbcommon");
664
+ return GLFW_FALSE;
665
+ }
666
+
667
+ _glfw.wl.xkb.context_new = (PFN_xkb_context_new)
668
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_context_new");
669
+ _glfw.wl.xkb.context_unref = (PFN_xkb_context_unref)
670
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_context_unref");
671
+ _glfw.wl.xkb.keymap_new_from_string = (PFN_xkb_keymap_new_from_string)
672
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_keymap_new_from_string");
673
+ _glfw.wl.xkb.keymap_unref = (PFN_xkb_keymap_unref)
674
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_keymap_unref");
675
+ _glfw.wl.xkb.keymap_mod_get_index = (PFN_xkb_keymap_mod_get_index)
676
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_keymap_mod_get_index");
677
+ _glfw.wl.xkb.keymap_key_repeats = (PFN_xkb_keymap_key_repeats)
678
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_keymap_key_repeats");
679
+ _glfw.wl.xkb.keymap_key_get_syms_by_level = (PFN_xkb_keymap_key_get_syms_by_level)
680
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_keymap_key_get_syms_by_level");
681
+ _glfw.wl.xkb.state_new = (PFN_xkb_state_new)
682
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_state_new");
683
+ _glfw.wl.xkb.state_unref = (PFN_xkb_state_unref)
684
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_state_unref");
685
+ _glfw.wl.xkb.state_key_get_syms = (PFN_xkb_state_key_get_syms)
686
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_state_key_get_syms");
687
+ _glfw.wl.xkb.state_update_mask = (PFN_xkb_state_update_mask)
688
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_state_update_mask");
689
+ _glfw.wl.xkb.state_key_get_layout = (PFN_xkb_state_key_get_layout)
690
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_state_key_get_layout");
691
+ _glfw.wl.xkb.state_mod_index_is_active = (PFN_xkb_state_mod_index_is_active)
692
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_state_mod_index_is_active");
693
+ _glfw.wl.xkb.compose_table_new_from_locale = (PFN_xkb_compose_table_new_from_locale)
694
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_compose_table_new_from_locale");
695
+ _glfw.wl.xkb.compose_table_unref = (PFN_xkb_compose_table_unref)
696
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_compose_table_unref");
697
+ _glfw.wl.xkb.compose_state_new = (PFN_xkb_compose_state_new)
698
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_compose_state_new");
699
+ _glfw.wl.xkb.compose_state_unref = (PFN_xkb_compose_state_unref)
700
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_compose_state_unref");
701
+ _glfw.wl.xkb.compose_state_feed = (PFN_xkb_compose_state_feed)
702
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_compose_state_feed");
703
+ _glfw.wl.xkb.compose_state_get_status = (PFN_xkb_compose_state_get_status)
704
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_compose_state_get_status");
705
+ _glfw.wl.xkb.compose_state_get_one_sym = (PFN_xkb_compose_state_get_one_sym)
706
+ _glfwPlatformGetModuleSymbol(_glfw.wl.xkb.handle, "xkb_compose_state_get_one_sym");
707
+
708
+ if (!_glfw.wl.xkb.context_new ||
709
+ !_glfw.wl.xkb.context_unref ||
710
+ !_glfw.wl.xkb.keymap_new_from_string ||
711
+ !_glfw.wl.xkb.keymap_unref ||
712
+ !_glfw.wl.xkb.keymap_mod_get_index ||
713
+ !_glfw.wl.xkb.keymap_key_repeats ||
714
+ !_glfw.wl.xkb.keymap_key_get_syms_by_level ||
715
+ !_glfw.wl.xkb.state_new ||
716
+ !_glfw.wl.xkb.state_unref ||
717
+ !_glfw.wl.xkb.state_key_get_syms ||
718
+ !_glfw.wl.xkb.state_update_mask ||
719
+ !_glfw.wl.xkb.state_key_get_layout ||
720
+ !_glfw.wl.xkb.state_mod_index_is_active ||
721
+ !_glfw.wl.xkb.compose_table_new_from_locale ||
722
+ !_glfw.wl.xkb.compose_table_unref ||
723
+ !_glfw.wl.xkb.compose_state_new ||
724
+ !_glfw.wl.xkb.compose_state_unref ||
725
+ !_glfw.wl.xkb.compose_state_feed ||
726
+ !_glfw.wl.xkb.compose_state_get_status ||
727
+ !_glfw.wl.xkb.compose_state_get_one_sym)
728
+ {
729
+ _glfwInputError(GLFW_PLATFORM_ERROR,
730
+ "Wayland: Failed to load all entry points from libxkbcommon");
731
+ return GLFW_FALSE;
732
+ }
733
+
734
+ if (_glfw.hints.init.wl.libdecorMode == GLFW_WAYLAND_PREFER_LIBDECOR)
735
+ _glfw.wl.libdecor.handle = _glfwPlatformLoadModule("libdecor-0.so.0");
736
+
737
+ if (_glfw.wl.libdecor.handle)
738
+ {
739
+ _glfw.wl.libdecor.libdecor_new_ = (PFN_libdecor_new)
740
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_new");
741
+ _glfw.wl.libdecor.libdecor_unref_ = (PFN_libdecor_unref)
742
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_unref");
743
+ _glfw.wl.libdecor.libdecor_get_fd_ = (PFN_libdecor_get_fd)
744
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_get_fd");
745
+ _glfw.wl.libdecor.libdecor_dispatch_ = (PFN_libdecor_dispatch)
746
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_dispatch");
747
+ _glfw.wl.libdecor.libdecor_decorate_ = (PFN_libdecor_decorate)
748
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_decorate");
749
+ _glfw.wl.libdecor.libdecor_frame_unref_ = (PFN_libdecor_frame_unref)
750
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_unref");
751
+ _glfw.wl.libdecor.libdecor_frame_set_app_id_ = (PFN_libdecor_frame_set_app_id)
752
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_app_id");
753
+ _glfw.wl.libdecor.libdecor_frame_set_title_ = (PFN_libdecor_frame_set_title)
754
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_title");
755
+ _glfw.wl.libdecor.libdecor_frame_set_minimized_ = (PFN_libdecor_frame_set_minimized)
756
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_minimized");
757
+ _glfw.wl.libdecor.libdecor_frame_set_fullscreen_ = (PFN_libdecor_frame_set_fullscreen)
758
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_fullscreen");
759
+ _glfw.wl.libdecor.libdecor_frame_unset_fullscreen_ = (PFN_libdecor_frame_unset_fullscreen)
760
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_unset_fullscreen");
761
+ _glfw.wl.libdecor.libdecor_frame_map_ = (PFN_libdecor_frame_map)
762
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_map");
763
+ _glfw.wl.libdecor.libdecor_frame_commit_ = (PFN_libdecor_frame_commit)
764
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_commit");
765
+ _glfw.wl.libdecor.libdecor_frame_set_min_content_size_ = (PFN_libdecor_frame_set_min_content_size)
766
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_min_content_size");
767
+ _glfw.wl.libdecor.libdecor_frame_set_max_content_size_ = (PFN_libdecor_frame_set_max_content_size)
768
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_max_content_size");
769
+ _glfw.wl.libdecor.libdecor_frame_set_maximized_ = (PFN_libdecor_frame_set_maximized)
770
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_maximized");
771
+ _glfw.wl.libdecor.libdecor_frame_unset_maximized_ = (PFN_libdecor_frame_unset_maximized)
772
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_unset_maximized");
773
+ _glfw.wl.libdecor.libdecor_frame_set_capabilities_ = (PFN_libdecor_frame_set_capabilities)
774
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_capabilities");
775
+ _glfw.wl.libdecor.libdecor_frame_unset_capabilities_ = (PFN_libdecor_frame_unset_capabilities)
776
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_unset_capabilities");
777
+ _glfw.wl.libdecor.libdecor_frame_set_visibility_ = (PFN_libdecor_frame_set_visibility)
778
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_set_visibility");
779
+ _glfw.wl.libdecor.libdecor_frame_get_xdg_toplevel_ = (PFN_libdecor_frame_get_xdg_toplevel)
780
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_frame_get_xdg_toplevel");
781
+ _glfw.wl.libdecor.libdecor_configuration_get_content_size_ = (PFN_libdecor_configuration_get_content_size)
782
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_configuration_get_content_size");
783
+ _glfw.wl.libdecor.libdecor_configuration_get_window_state_ = (PFN_libdecor_configuration_get_window_state)
784
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_configuration_get_window_state");
785
+ _glfw.wl.libdecor.libdecor_state_new_ = (PFN_libdecor_state_new)
786
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_state_new");
787
+ _glfw.wl.libdecor.libdecor_state_free_ = (PFN_libdecor_state_free)
788
+ _glfwPlatformGetModuleSymbol(_glfw.wl.libdecor.handle, "libdecor_state_free");
789
+
790
+ if (!_glfw.wl.libdecor.libdecor_new_ ||
791
+ !_glfw.wl.libdecor.libdecor_unref_ ||
792
+ !_glfw.wl.libdecor.libdecor_get_fd_ ||
793
+ !_glfw.wl.libdecor.libdecor_dispatch_ ||
794
+ !_glfw.wl.libdecor.libdecor_decorate_ ||
795
+ !_glfw.wl.libdecor.libdecor_frame_unref_ ||
796
+ !_glfw.wl.libdecor.libdecor_frame_set_app_id_ ||
797
+ !_glfw.wl.libdecor.libdecor_frame_set_title_ ||
798
+ !_glfw.wl.libdecor.libdecor_frame_set_minimized_ ||
799
+ !_glfw.wl.libdecor.libdecor_frame_set_fullscreen_ ||
800
+ !_glfw.wl.libdecor.libdecor_frame_unset_fullscreen_ ||
801
+ !_glfw.wl.libdecor.libdecor_frame_map_ ||
802
+ !_glfw.wl.libdecor.libdecor_frame_commit_ ||
803
+ !_glfw.wl.libdecor.libdecor_frame_set_min_content_size_ ||
804
+ !_glfw.wl.libdecor.libdecor_frame_set_max_content_size_ ||
805
+ !_glfw.wl.libdecor.libdecor_frame_set_maximized_ ||
806
+ !_glfw.wl.libdecor.libdecor_frame_unset_maximized_ ||
807
+ !_glfw.wl.libdecor.libdecor_frame_set_capabilities_ ||
808
+ !_glfw.wl.libdecor.libdecor_frame_unset_capabilities_ ||
809
+ !_glfw.wl.libdecor.libdecor_frame_set_visibility_ ||
810
+ !_glfw.wl.libdecor.libdecor_frame_get_xdg_toplevel_ ||
811
+ !_glfw.wl.libdecor.libdecor_configuration_get_content_size_ ||
812
+ !_glfw.wl.libdecor.libdecor_configuration_get_window_state_ ||
813
+ !_glfw.wl.libdecor.libdecor_state_new_ ||
814
+ !_glfw.wl.libdecor.libdecor_state_free_)
815
+ {
816
+ _glfwPlatformFreeModule(_glfw.wl.libdecor.handle);
817
+ memset(&_glfw.wl.libdecor, 0, sizeof(_glfw.wl.libdecor));
818
+ }
819
+ }
820
+
821
+ _glfw.wl.registry = wl_display_get_registry(_glfw.wl.display);
822
+ wl_registry_add_listener(_glfw.wl.registry, &registryListener, NULL);
823
+
824
+ createKeyTables();
825
+
826
+ _glfw.wl.xkb.context = xkb_context_new(0);
827
+ if (!_glfw.wl.xkb.context)
828
+ {
829
+ _glfwInputError(GLFW_PLATFORM_ERROR,
830
+ "Wayland: Failed to initialize xkb context");
831
+ return GLFW_FALSE;
832
+ }
833
+
834
+ // Sync so we got all registry objects
835
+ wl_display_roundtrip(_glfw.wl.display);
836
+
837
+ // Sync so we got all initial output events
838
+ wl_display_roundtrip(_glfw.wl.display);
839
+
840
+ if (_glfw.wl.libdecor.handle)
841
+ {
842
+ _glfw.wl.libdecor.context = libdecor_new(_glfw.wl.display, &libdecorInterface);
843
+ if (_glfw.wl.libdecor.context)
844
+ {
845
+ // Perform an initial dispatch and flush to get the init started
846
+ libdecor_dispatch(_glfw.wl.libdecor.context, 0);
847
+
848
+ // Create sync point to "know" when libdecor is ready for use
849
+ _glfw.wl.libdecor.callback = wl_display_sync(_glfw.wl.display);
850
+ wl_callback_add_listener(_glfw.wl.libdecor.callback,
851
+ &libdecorReadyListener,
852
+ NULL);
853
+ }
854
+ }
855
+
856
+ if (wl_seat_get_version(_glfw.wl.seat) >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION)
857
+ {
858
+ _glfw.wl.keyRepeatTimerfd =
859
+ timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
860
+ }
861
+
862
+ if (!_glfw.wl.wmBase)
863
+ {
864
+ _glfwInputError(GLFW_PLATFORM_ERROR,
865
+ "Wayland: Failed to find xdg-shell in your compositor");
866
+ return GLFW_FALSE;
867
+ }
868
+
869
+ if (!_glfw.wl.shm)
870
+ {
871
+ _glfwInputError(GLFW_PLATFORM_ERROR,
872
+ "Wayland: Failed to find wl_shm in your compositor");
873
+ return GLFW_FALSE;
874
+ }
875
+
876
+ if (!loadCursorTheme())
877
+ return GLFW_FALSE;
878
+
879
+ if (_glfw.wl.seat && _glfw.wl.dataDeviceManager)
880
+ {
881
+ _glfw.wl.dataDevice =
882
+ wl_data_device_manager_get_data_device(_glfw.wl.dataDeviceManager,
883
+ _glfw.wl.seat);
884
+ _glfwAddDataDeviceListenerWayland(_glfw.wl.dataDevice);
885
+ }
886
+
887
+ return GLFW_TRUE;
888
+ }
889
+
890
+ void _glfwTerminateWayland(void)
891
+ {
892
+ _glfwTerminateEGL();
893
+ _glfwTerminateOSMesa();
894
+
895
+ if (_glfw.wl.libdecor.context)
896
+ {
897
+ // Allow libdecor to finish receiving all its requested globals
898
+ // and ensure the associated sync callback object is destroyed
899
+ while (!_glfw.wl.libdecor.ready)
900
+ _glfwWaitEventsWayland();
901
+
902
+ libdecor_unref(_glfw.wl.libdecor.context);
903
+ }
904
+
905
+ if (_glfw.wl.libdecor.handle)
906
+ {
907
+ _glfwPlatformFreeModule(_glfw.wl.libdecor.handle);
908
+ _glfw.wl.libdecor.handle = NULL;
909
+ }
910
+
911
+ if (_glfw.wl.egl.handle)
912
+ {
913
+ _glfwPlatformFreeModule(_glfw.wl.egl.handle);
914
+ _glfw.wl.egl.handle = NULL;
915
+ }
916
+
917
+ if (_glfw.wl.xkb.composeState)
918
+ xkb_compose_state_unref(_glfw.wl.xkb.composeState);
919
+ if (_glfw.wl.xkb.keymap)
920
+ xkb_keymap_unref(_glfw.wl.xkb.keymap);
921
+ if (_glfw.wl.xkb.state)
922
+ xkb_state_unref(_glfw.wl.xkb.state);
923
+ if (_glfw.wl.xkb.context)
924
+ xkb_context_unref(_glfw.wl.xkb.context);
925
+ if (_glfw.wl.xkb.handle)
926
+ {
927
+ _glfwPlatformFreeModule(_glfw.wl.xkb.handle);
928
+ _glfw.wl.xkb.handle = NULL;
929
+ }
930
+
931
+ if (_glfw.wl.cursorTheme)
932
+ wl_cursor_theme_destroy(_glfw.wl.cursorTheme);
933
+ if (_glfw.wl.cursorThemeHiDPI)
934
+ wl_cursor_theme_destroy(_glfw.wl.cursorThemeHiDPI);
935
+ if (_glfw.wl.cursor.handle)
936
+ {
937
+ _glfwPlatformFreeModule(_glfw.wl.cursor.handle);
938
+ _glfw.wl.cursor.handle = NULL;
939
+ }
940
+
941
+ for (unsigned int i = 0; i < _glfw.wl.offerCount; i++)
942
+ wl_data_offer_destroy(_glfw.wl.offers[i].offer);
943
+
944
+ _glfw_free(_glfw.wl.offers);
945
+
946
+ if (_glfw.wl.cursorSurface)
947
+ wl_surface_destroy(_glfw.wl.cursorSurface);
948
+ if (_glfw.wl.subcompositor)
949
+ wl_subcompositor_destroy(_glfw.wl.subcompositor);
950
+ if (_glfw.wl.compositor)
951
+ wl_compositor_destroy(_glfw.wl.compositor);
952
+ if (_glfw.wl.shm)
953
+ wl_shm_destroy(_glfw.wl.shm);
954
+ if (_glfw.wl.viewporter)
955
+ wp_viewporter_destroy(_glfw.wl.viewporter);
956
+ if (_glfw.wl.decorationManager)
957
+ zxdg_decoration_manager_v1_destroy(_glfw.wl.decorationManager);
958
+ if (_glfw.wl.wmBase)
959
+ xdg_wm_base_destroy(_glfw.wl.wmBase);
960
+ if (_glfw.wl.selectionOffer)
961
+ wl_data_offer_destroy(_glfw.wl.selectionOffer);
962
+ if (_glfw.wl.dragOffer)
963
+ wl_data_offer_destroy(_glfw.wl.dragOffer);
964
+ if (_glfw.wl.selectionSource)
965
+ wl_data_source_destroy(_glfw.wl.selectionSource);
966
+ if (_glfw.wl.dataDevice)
967
+ wl_data_device_destroy(_glfw.wl.dataDevice);
968
+ if (_glfw.wl.dataDeviceManager)
969
+ wl_data_device_manager_destroy(_glfw.wl.dataDeviceManager);
970
+ if (_glfw.wl.pointer)
971
+ wl_pointer_destroy(_glfw.wl.pointer);
972
+ if (_glfw.wl.keyboard)
973
+ wl_keyboard_destroy(_glfw.wl.keyboard);
974
+ if (_glfw.wl.seat)
975
+ wl_seat_destroy(_glfw.wl.seat);
976
+ if (_glfw.wl.relativePointerManager)
977
+ zwp_relative_pointer_manager_v1_destroy(_glfw.wl.relativePointerManager);
978
+ if (_glfw.wl.pointerConstraints)
979
+ zwp_pointer_constraints_v1_destroy(_glfw.wl.pointerConstraints);
980
+ if (_glfw.wl.idleInhibitManager)
981
+ zwp_idle_inhibit_manager_v1_destroy(_glfw.wl.idleInhibitManager);
982
+ if (_glfw.wl.activationManager)
983
+ xdg_activation_v1_destroy(_glfw.wl.activationManager);
984
+ if (_glfw.wl.fractionalScaleManager)
985
+ wp_fractional_scale_manager_v1_destroy(_glfw.wl.fractionalScaleManager);
986
+ if (_glfw.wl.registry)
987
+ wl_registry_destroy(_glfw.wl.registry);
988
+ if (_glfw.wl.display)
989
+ {
990
+ wl_display_flush(_glfw.wl.display);
991
+ wl_display_disconnect(_glfw.wl.display);
992
+ }
993
+
994
+ if (_glfw.wl.keyRepeatTimerfd >= 0)
995
+ close(_glfw.wl.keyRepeatTimerfd);
996
+ if (_glfw.wl.cursorTimerfd >= 0)
997
+ close(_glfw.wl.cursorTimerfd);
998
+
999
+ _glfw_free(_glfw.wl.clipboardString);
1000
+ }
1001
+
1002
+ #endif // _GLFW_WAYLAND
1003
+