1 //======================================================================== 2 // GLFW 3.2 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 #ifndef _glfw3_wayland_platform_h_ 28 #define _glfw3_wayland_platform_h_ 29 30 #include <wayland-client.h> 31 #include <xkbcommon/xkbcommon.h> 32 #include <dlfcn.h> 33 34 typedef VkFlags VkWaylandSurfaceCreateFlagsKHR; 35 36 typedef struct VkWaylandSurfaceCreateInfoKHR 37 { 38 VkStructureType sType; 39 const void* pNext; 40 VkWaylandSurfaceCreateFlagsKHR flags; 41 struct wl_display* display; 42 struct wl_surface* surface; 43 } VkWaylandSurfaceCreateInfoKHR; 44 45 typedef VkResult (APIENTRY *PFN_vkCreateWaylandSurfaceKHR)(VkInstance,const VkWaylandSurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*); 46 typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice,uint32_t,struct wl_display*); 47 48 #include "posix_tls.h" 49 #include "posix_time.h" 50 #include "linux_joystick.h" 51 #include "xkb_unicode.h" 52 #include "egl_context.h" 53 54 #include "wayland-relative-pointer-unstable-v1-client-protocol.h" 55 #include "wayland-pointer-constraints-unstable-v1-client-protocol.h" 56 57 #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 58 #define _glfw_dlclose(handle) dlclose(handle) 59 #define _glfw_dlsym(handle, name) dlsym(handle, name) 60 61 #define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->wl.native) 62 #define _GLFW_EGL_NATIVE_DISPLAY ((EGLNativeDisplayType) _glfw.wl.display) 63 64 #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWayland wl 65 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWayland wl 66 #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorWayland wl 67 #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorWayland wl 68 69 #define _GLFW_PLATFORM_CONTEXT_STATE 70 #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE 71 72 73 // Wayland-specific video mode data 74 // 75 typedef struct _GLFWvidmodeWayland _GLFWvidmodeWayland; 76 77 // Wayland-specific per-window data 78 // 79 typedef struct _GLFWwindowWayland 80 { 81 int width, height; 82 GLFWbool visible; 83 GLFWbool maximized; 84 struct wl_surface* surface; 85 struct wl_egl_window* native; 86 struct wl_shell_surface* shell_surface; 87 struct wl_callback* callback; 88 89 _GLFWcursor* currentCursor; 90 double cursorPosX, cursorPosY; 91 92 char* title; 93 94 // We need to track the monitors the window spans on to calculate the 95 // optimal scaling factor. 96 int scale; 97 _GLFWmonitor** monitors; 98 int monitorsCount; 99 int monitorsSize; 100 101 struct { 102 struct zwp_relative_pointer_v1* relativePointer; 103 struct zwp_locked_pointer_v1* lockedPointer; 104 } pointerLock; 105 } _GLFWwindowWayland; 106 107 // Wayland-specific global data 108 // 109 typedef struct _GLFWlibraryWayland 110 { 111 struct wl_display* display; 112 struct wl_registry* registry; 113 struct wl_compositor* compositor; 114 struct wl_shell* shell; 115 struct wl_shm* shm; 116 struct wl_seat* seat; 117 struct wl_pointer* pointer; 118 struct wl_keyboard* keyboard; 119 struct zwp_relative_pointer_manager_v1* relativePointerManager; 120 struct zwp_pointer_constraints_v1* pointerConstraints; 121 122 int wl_compositor_version; 123 124 struct wl_cursor_theme* cursorTheme; 125 struct wl_surface* cursorSurface; 126 uint32_t pointerSerial; 127 128 _GLFWmonitor** monitors; 129 int monitorsCount; 130 int monitorsSize; 131 132 short int publicKeys[256]; 133 134 struct { 135 struct xkb_context* context; 136 struct xkb_keymap* keymap; 137 struct xkb_state* state; 138 xkb_mod_mask_t control_mask; 139 xkb_mod_mask_t alt_mask; 140 xkb_mod_mask_t shift_mask; 141 xkb_mod_mask_t super_mask; 142 unsigned int modifiers; 143 } xkb; 144 145 _GLFWwindow* pointerFocus; 146 _GLFWwindow* keyboardFocus; 147 148 } _GLFWlibraryWayland; 149 150 // Wayland-specific per-monitor data 151 // 152 typedef struct _GLFWmonitorWayland 153 { 154 struct wl_output* output; 155 156 _GLFWvidmodeWayland* modes; 157 int modesCount; 158 int modesSize; 159 GLFWbool done; 160 161 int x; 162 int y; 163 int scale; 164 } _GLFWmonitorWayland; 165 166 // Wayland-specific per-cursor data 167 // 168 typedef struct _GLFWcursorWayland 169 { 170 struct wl_cursor_image* image; 171 struct wl_buffer* buffer; 172 int width, height; 173 int xhot, yhot; 174 } _GLFWcursorWayland; 175 176 177 void _glfwAddOutputWayland(uint32_t name, uint32_t version); 178 179 #endif // _glfw3_wayland_platform_h_ 180