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