1 /// Translated from C to D
2 module glfw3.wl_platform;
3 
4 extern(C): @nogc: nothrow: __gshared:
5 //========================================================================
6 // GLFW 3.3 Wayland - www.glfw.org
7 //------------------------------------------------------------------------
8 // Copyright (c) 2014 Jonas Ådahl <jadahl@gmail.com>
9 //
10 // This software is provided 'as-is', without any express or implied
11 // warranty. In no event will the authors be held liable for any damages
12 // arising from the use of this software.
13 //
14 // Permission is granted to anyone to use this software for any purpose,
15 // including commercial applications, and to alter it and redistribute it
16 // freely, subject to the following restrictions:
17 //
18 // 1. The origin of this software must not be misrepresented; you must not
19 //    claim that you wrote the original software. If you use this software
20 //    in a product, an acknowledgment in the product documentation would
21 //    be appreciated but is not required.
22 //
23 // 2. Altered source versions must be plainly marked as such, and must not
24 //    be misrepresented as being the original software.
25 //
26 // 3. This notice may not be removed or altered from any source
27 //    distribution.
28 //
29 //========================================================================
30 
31 //public import wayland.client;
32 //public import xkbcommon.xkbcommon;
33 version (HAVE_XKBCOMMON_COMPOSE_H) {
34     public import xkbcommon.xkbcommon_compose;
35 }
36 import xkbcommon.xkbcommon;
37 public import core.sys.posix.dlfcn;
38 import glfw3.internal;
39 
40 alias VkFlags VkWaylandSurfaceCreateFlagsKHR;
41 
42 struct VkWaylandSurfaceCreateInfoKHR {
43     VkStructureType sType;
44     const(void)* pNext;
45     VkWaylandSurfaceCreateFlagsKHR flags;
46     wl_display* display;
47     wl_surface* surface;
48 }
49 
50 alias VkResult function(VkInstance, const(VkWaylandSurfaceCreateInfoKHR)*, const(VkAllocationCallbacks)*, VkSurfaceKHR*) PFN_vkCreateWaylandSurfaceKHR;
51 alias VkBool32 function(VkPhysicalDevice, uint, wl_display*) PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR;
52 
53 public import glfw3.posix_thread;
54 public import glfw3.posix_time;
55 version (linux) {
56     public import glfw3.linux_joystick;
57 } else {
58     public import glfw3.null_joystick;
59 }
60 public import glfw3.xkb_unicode;
61 public import glfw3.egl_context;
62 public import glfw3.osmesa_context;
63 public import glfw3.wayland;
64 //public import wayland.client;
65 //public import wayland-xdg-shell-client-protocol;
66 //public import wayland-xdg-decoration-client-protocol;
67 //public import wayland-viewporter-client-protocol;
68 //public import wayland-relative-pointer-unstable-v1-client-protocol;
69 //public import wayland-pointer-constraints-unstable-v1-client-protocol;
70 //public import wayland-idle-inhibit-unstable-v1-client-protocol;
71 
72 auto _glfw_dlopen(const(char)* name) {return dlopen(name, RTLD_LAZY | RTLD_LOCAL);}
73 auto _glfw_dlclose(void* handle) {return dlclose(handle);}
74 auto _glfw_dlsym(void* handle, const(char)* name) {return dlsym(handle, name);}
75 
76 enum _GLFW_EGL_NATIVE_WINDOW =  `(cast(EGLNativeWindowType) window.wl.native)`;
77 enum _GLFW_EGL_NATIVE_DISPLAY = `(cast(EGLNativeDisplayType) _glfw.wl.display)`;
78 
79 mixin template _GLFW_PLATFORM_WINDOW_STATE() {       _GLFWwindowWayland  wl;}
80 mixin template _GLFW_PLATFORM_LIBRARY_WINDOW_STATE() {_GLFWlibraryWayland wl;}
81 mixin template _GLFW_PLATFORM_MONITOR_STATE() {      _GLFWmonitorWayland wl;}
82 mixin template _GLFW_PLATFORM_CURSOR_STATE() {       _GLFWcursorWayland  wl;}
83 
84 mixin template _GLFW_PLATFORM_CONTEXT_STATE() { int dummyContext; }
85 mixin template _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE() { int dummyLibraryContext; }
86 
87 struct wl_cursor_image {
88     uint width;
89     uint height;
90     uint hotspot_x;
91     uint hotspot_y;
92     uint delay;
93 }
94 struct wl_cursor {
95     uint image_count;
96     wl_cursor_image** images;
97     char* name;
98 }
99 alias wl_cursor_theme* function(const(char)*, int, wl_shm*) PFN_wl_cursor_theme_load;
100 alias void function(wl_cursor_theme*) PFN_wl_cursor_theme_destroy;
101 alias wl_cursor* function(wl_cursor_theme*, const(char)*) PFN_wl_cursor_theme_get_cursor;
102 alias wl_buffer* function(wl_cursor_image*) PFN_wl_cursor_image_get_buffer;
103 // wl_cursor_theme_load = _glfw.wl.cursor.theme_load;
104 // wl_cursor_theme_destroy = _glfw.wl.cursor.theme_destroy;
105 // wl_cursor_theme_get_cursor = _glfw.wl.cursor.theme_get_cursor;
106 // wl_cursor_image_get_buffer = _glfw.wl.cursor.image_get_buffer;
107 // wl_egl_window_create = _glfw.wl.egl.window_create;
108 // wl_egl_window_destroy = _glfw.wl.egl.window_destroy;
109 // wl_egl_window_resize = _glfw.wl.egl.window_resize;
110 // xkb_context_new = _glfw.wl.xkb.context_new;
111 // xkb_context_unref = _glfw.wl.xkb.context_unref;
112 // xkb_keymap_new_from_string = _glfw.wl.xkb.keymap_new_from_string;
113 // xkb_keymap_unref = _glfw.wl.xkb.keymap_unref;
114 // xkb_keymap_mod_get_index = _glfw.wl.xkb.keymap_mod_get_index;
115 // xkb_keymap_key_repeats = _glfw.wl.xkb.keymap_key_repeats;
116 // xkb_state_new = _glfw.wl.xkb.state_new;
117 // xkb_state_unref = _glfw.wl.xkb.state_unref;
118 // xkb_state_key_get_syms = _glfw.wl.xkb.state_key_get_syms;
119 // xkb_state_update_mask = _glfw.wl.xkb.state_update_mask;
120 // xkb_state_serialize_mods = _glfw.wl.xkb.state_serialize_mods;
121 
122 alias wl_egl_window* function(wl_surface*, int, int) PFN_wl_egl_window_create;
123 alias void function(wl_egl_window*) PFN_wl_egl_window_destroy;
124 alias void function(wl_egl_window*, int, int, int, int) PFN_wl_egl_window_resize;
125 
126 alias xkb_context* function(xkb_context_flags) PFN_xkb_context_new;
127 alias void function(xkb_context*) PFN_xkb_context_unref;
128 alias xkb_keymap* function(xkb_context*, const(char)*, xkb_keymap_format, xkb_keymap_compile_flags) PFN_xkb_keymap_new_from_string;
129 alias void function(xkb_keymap*) PFN_xkb_keymap_unref;
130 alias xkb_mod_index_t function(xkb_keymap*, const(char)*) PFN_xkb_keymap_mod_get_index;
131 alias int function(xkb_keymap*, xkb_keycode_t) PFN_xkb_keymap_key_repeats;
132 alias xkb_state* function(xkb_keymap*) PFN_xkb_state_new;
133 alias void function(xkb_state*) PFN_xkb_state_unref;
134 alias int function(xkb_state*, xkb_keycode_t, const(xkb_keysym_t)**) PFN_xkb_state_key_get_syms;
135 alias xkb_state_component function(xkb_state*, xkb_mod_mask_t, xkb_mod_mask_t, xkb_mod_mask_t, xkb_layout_index_t, xkb_layout_index_t, xkb_layout_index_t) PFN_xkb_state_update_mask;
136 alias xkb_mod_mask_t function(xkb_state*, xkb_state_component) PFN_xkb_state_serialize_mods;
137 
138 version (HAVE_XKBCOMMON_COMPOSE_H) {
139     alias xkb_compose_table* function(xkb_context*, const(char)*, xkb_compose_compile_flags) PFN_xkb_compose_table_new_from_locale;
140     alias void function(xkb_compose_table*) PFN_xkb_compose_table_unref;
141     alias xkb_compose_state* function(xkb_compose_table*, xkb_compose_state_flags) PFN_xkb_compose_state_new;
142     alias void function(xkb_compose_state*) PFN_xkb_compose_state_unref;
143     alias xkb_compose_feed_result function(xkb_compose_state*, xkb_keysym_t) PFN_xkb_compose_state_feed;
144     alias xkb_compose_status function(xkb_compose_state*) PFN_xkb_compose_state_get_status;
145     alias xkb_keysym_t function(xkb_compose_state*) PFN_xkb_compose_state_get_one_sym;
146     //enum xkb_compose_table_new_from_locale = _glfw.wl.xkb.compose_table_new_from_locale;
147     //enum xkb_compose_table_unref = _glfw.wl.xkb.compose_table_unref;
148     //enum xkb_compose_state_new = _glfw.wl.xkb.compose_state_new;
149     //enum xkb_compose_state_unref = _glfw.wl.xkb.compose_state_unref;
150     //enum xkb_compose_state_feed = _glfw.wl.xkb.compose_state_feed;
151     //enum xkb_compose_state_get_status = _glfw.wl.xkb.compose_state_get_status;
152     //enum xkb_compose_state_get_one_sym = _glfw.wl.xkb.compose_state_get_one_sym;
153 }
154 
155 enum _GLFW_DECORATION_WIDTH = 4;
156 enum _GLFW_DECORATION_TOP = 24;
157 enum _GLFW_DECORATION_VERTICAL = (_GLFW_DECORATION_TOP + _GLFW_DECORATION_WIDTH);
158 enum _GLFW_DECORATION_HORIZONTAL = (2 * _GLFW_DECORATION_WIDTH);
159 
160 enum _GLFWdecorationSideWayland {
161     mainWindow,
162     topDecoration,
163     leftDecoration,
164     rightDecoration,
165     bottomDecoration,
166 
167 }
168 alias mainWindow = _GLFWdecorationSideWayland.mainWindow;
169 alias topDecoration = _GLFWdecorationSideWayland.topDecoration;
170 alias leftDecoration = _GLFWdecorationSideWayland.leftDecoration;
171 alias rightDecoration = _GLFWdecorationSideWayland.rightDecoration;
172 alias bottomDecoration = _GLFWdecorationSideWayland.bottomDecoration;
173 
174 struct _GLFWdecorationWayland {
175     wl_surface* surface;
176     wl_subsurface* subsurface;
177     wp_viewport* viewport;
178 
179 }/+alias _GLFWdecorationWayland _GLFWdecorationWayland;+/
180 
181 // Wayland-specific per-window data
182 //
183 struct _GLFWwindowWayland {
184     int width;int height;
185     GLFWbool visible;
186     GLFWbool maximized;
187     GLFWbool hovered;
188     GLFWbool transparent;
189     wl_surface* surface;
190     wl_egl_window* native;
191     wl_shell_surface* shellSurface;
192     wl_callback* callback;
193 
194     struct _Xdg {
195         xdg_surface* surface;
196         xdg_toplevel* toplevel;
197         zxdg_toplevel_decoration_v1* decoration;
198     }_Xdg xdg;
199 
200     _GLFWcursor* currentCursor;
201     double cursorPosX;double cursorPosY;
202 
203     char* title;
204 
205     // We need to track the monitors the window spans on to calculate the
206     // optimal scaling factor.
207     int scale;
208     _GLFWmonitor** monitors;
209     int monitorsCount;
210     int monitorsSize;
211 
212     struct _PointerLock {
213         zwp_relative_pointer_v1* relativePointer;
214         zwp_locked_pointer_v1* lockedPointer;
215     }_PointerLock pointerLock;
216 
217     zwp_idle_inhibitor_v1* idleInhibitor;
218 
219     GLFWbool wasFullscreen;
220 
221     struct _Decorations {
222         GLFWbool serverSide;
223         wl_buffer* buffer;
224         _GLFWdecorationWayland top;_GLFWdecorationWayland left;_GLFWdecorationWayland right;_GLFWdecorationWayland bottom;
225         int focus;
226     }_Decorations decorations;
227 
228 }/+alias _GLFWwindowWayland _GLFWwindowWayland;+/
229 
230 // Wayland-specific global data
231 //
232 struct _GLFWlibraryWayland {
233     wl_display* display;
234     wl_registry* registry;
235     wl_compositor* compositor;
236     wl_subcompositor* subcompositor;
237     wl_shell* shell;
238     wl_shm* shm;
239     wl_seat* seat;
240     wl_pointer* pointer;
241     wl_keyboard* keyboard;
242     wl_data_device_manager* dataDeviceManager;
243     wl_data_device* dataDevice;
244     wl_data_offer* dataOffer;
245     wl_data_source* dataSource;
246     xdg_wm_base* wmBase;
247     zxdg_decoration_manager_v1* decorationManager;
248     wp_viewporter* viewporter;
249     zwp_relative_pointer_manager_v1* relativePointerManager;
250     zwp_pointer_constraints_v1* pointerConstraints;
251     zwp_idle_inhibit_manager_v1* idleInhibitManager;
252 
253     int compositorVersion;
254     int seatVersion;
255 
256     wl_cursor_theme* cursorTheme;
257     wl_cursor_theme* cursorThemeHiDPI;
258     wl_surface* cursorSurface;
259     const(char)* cursorPreviousName;
260     int cursorTimerfd;
261     uint serial;
262 
263     int keyboardRepeatRate;
264     int keyboardRepeatDelay;
265     int keyboardLastKey;
266     int keyboardLastScancode;
267     char* clipboardString;
268     size_t clipboardSize;
269     char* clipboardSendString;
270     size_t clipboardSendSize;
271     int timerfd;
272     int[256] keycodes;
273     int[GLFW_KEY_LAST + 1] scancodes;
274 
275     struct _Xkb {
276         void* handle;
277         xkb_context* context;
278         xkb_keymap* keymap;
279         xkb_state* state;
280 
281 version (HAVE_XKBCOMMON_COMPOSE_H) {
282         xkb_compose_state* composeState;
283 }
284 
285         xkb_mod_mask_t controlMask;
286         xkb_mod_mask_t altMask;
287         xkb_mod_mask_t shiftMask;
288         xkb_mod_mask_t superMask;
289         xkb_mod_mask_t capsLockMask;
290         xkb_mod_mask_t numLockMask;
291         uint modifiers;
292 
293         PFN_xkb_context_new context_new;
294         PFN_xkb_context_unref context_unref;
295         PFN_xkb_keymap_new_from_string keymap_new_from_string;
296         PFN_xkb_keymap_unref keymap_unref;
297         PFN_xkb_keymap_mod_get_index keymap_mod_get_index;
298         PFN_xkb_keymap_key_repeats keymap_key_repeats;
299         PFN_xkb_state_new state_new;
300         PFN_xkb_state_unref state_unref;
301         PFN_xkb_state_key_get_syms state_key_get_syms;
302         PFN_xkb_state_update_mask state_update_mask;
303         PFN_xkb_state_serialize_mods state_serialize_mods;
304 
305 version (HAVE_XKBCOMMON_COMPOSE_H) {
306         PFN_xkb_compose_table_new_from_locale compose_table_new_from_locale;
307         PFN_xkb_compose_table_unref compose_table_unref;
308         PFN_xkb_compose_state_new compose_state_new;
309         PFN_xkb_compose_state_unref compose_state_unref;
310         PFN_xkb_compose_state_feed compose_state_feed;
311         PFN_xkb_compose_state_get_status compose_state_get_status;
312         PFN_xkb_compose_state_get_one_sym compose_state_get_one_sym;
313 }
314     }_Xkb xkb;
315 
316     _GLFWwindow* pointerFocus;
317     _GLFWwindow* keyboardFocus;
318 
319     struct _Cursor {
320         void* handle;
321 
322         PFN_wl_cursor_theme_load theme_load;
323         PFN_wl_cursor_theme_destroy theme_destroy;
324         PFN_wl_cursor_theme_get_cursor theme_get_cursor;
325         PFN_wl_cursor_image_get_buffer image_get_buffer;
326     }_Cursor cursor;
327 
328     struct _Egl {
329         void* handle;
330 
331         PFN_wl_egl_window_create window_create;
332         PFN_wl_egl_window_destroy window_destroy;
333         PFN_wl_egl_window_resize window_resize;
334     }_Egl egl;
335 
336 }/+alias _GLFWlibraryWayland _GLFWlibraryWayland;+/
337 
338 // Wayland-specific per-monitor data
339 //
340 struct _GLFWmonitorWayland {
341     wl_output* output;
342     uint name;
343     int currentMode;
344 
345     int x;
346     int y;
347     int scale;
348 
349 }/+alias _GLFWmonitorWayland _GLFWmonitorWayland;+/
350 
351 // Wayland-specific per-cursor data
352 //
353 struct _GLFWcursorWayland {
354     wl_cursor* cursor;
355     wl_cursor* cursorHiDPI;
356     wl_buffer* buffer;
357     int width;int height;
358     int xhot;int yhot;
359     int currentImage;
360 }/+alias _GLFWcursorWayland _GLFWcursorWayland;+/
361 
362 
363 void _glfwAddOutputWayland(uint name, uint version_);