1 //======================================================================== 2 // GLFW 3.2 X11 - www.glfw.org 3 //------------------------------------------------------------------------ 4 // Copyright (c) 2002-2006 Marcus Geelnard 5 // Copyright (c) 2006-2016 Camilla Berglund <elmindreda@glfw.org> 6 // 7 // This software is provided 'as-is', without any express or implied 8 // warranty. In no event will the authors be held liable for any damages 9 // arising from the use of this software. 10 // 11 // Permission is granted to anyone to use this software for any purpose, 12 // including commercial applications, and to alter it and redistribute it 13 // freely, subject to the following restrictions: 14 // 15 // 1. The origin of this software must not be misrepresented; you must not 16 // claim that you wrote the original software. If you use this software 17 // in a product, an acknowledgment in the product documentation would 18 // be appreciated but is not required. 19 // 20 // 2. Altered source versions must be plainly marked as such, and must not 21 // be misrepresented as being the original software. 22 // 23 // 3. This notice may not be removed or altered from any source 24 // distribution. 25 // 26 //======================================================================== 27 28 #ifndef _glfw3_x11_platform_h_ 29 #define _glfw3_x11_platform_h_ 30 31 #include <unistd.h> 32 #include <signal.h> 33 #include <stdint.h> 34 #include <dlfcn.h> 35 36 #include <X11/Xlib.h> 37 #include <X11/keysym.h> 38 #include <X11/Xatom.h> 39 #include <X11/Xcursor/Xcursor.h> 40 41 // The XRandR extension provides mode setting and gamma control 42 #include <X11/extensions/Xrandr.h> 43 44 // The Xkb extension provides improved keyboard support 45 #include <X11/XKBlib.h> 46 47 // The Xinerama extension provides legacy monitor indices 48 #include <X11/extensions/Xinerama.h> 49 50 #if defined(_GLFW_HAS_XF86VM) 51 // The Xf86VidMode extension provides fallback gamma control 52 #include <X11/extensions/xf86vmode.h> 53 #endif 54 55 typedef XID xcb_window_t; 56 typedef XID xcb_visualid_t; 57 typedef struct xcb_connection_t xcb_connection_t; 58 typedef xcb_connection_t* (* XGETXCBCONNECTION_T)(Display*); 59 60 typedef VkFlags VkXlibSurfaceCreateFlagsKHR; 61 typedef VkFlags VkXcbSurfaceCreateFlagsKHR; 62 63 typedef struct VkXlibSurfaceCreateInfoKHR 64 { 65 VkStructureType sType; 66 const void* pNext; 67 VkXlibSurfaceCreateFlagsKHR flags; 68 Display* dpy; 69 Window window; 70 } VkXlibSurfaceCreateInfoKHR; 71 72 typedef struct VkXcbSurfaceCreateInfoKHR 73 { 74 VkStructureType sType; 75 const void* pNext; 76 VkXcbSurfaceCreateFlagsKHR flags; 77 xcb_connection_t* connection; 78 xcb_window_t window; 79 } VkXcbSurfaceCreateInfoKHR; 80 81 typedef VkResult (APIENTRY *PFN_vkCreateXlibSurfaceKHR)(VkInstance,const VkXlibSurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*); 82 typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice,uint32_t,Display*,VisualID); 83 typedef VkResult (APIENTRY *PFN_vkCreateXcbSurfaceKHR)(VkInstance,const VkXcbSurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*); 84 typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice,uint32_t,xcb_connection_t*,xcb_visualid_t); 85 86 #include "posix_tls.h" 87 #include "posix_time.h" 88 #include "linux_joystick.h" 89 #include "xkb_unicode.h" 90 #include "glx_context.h" 91 #include "egl_context.h" 92 93 #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) 94 #define _glfw_dlclose(handle) dlclose(handle) 95 #define _glfw_dlsym(handle, name) dlsym(handle, name) 96 97 #define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->x11.handle) 98 #define _GLFW_EGL_NATIVE_DISPLAY ((EGLNativeDisplayType) _glfw.x11.display) 99 100 #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 x11 101 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryX11 x11 102 #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorX11 x11 103 #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorX11 x11 104 105 106 // X11-specific per-window data 107 // 108 typedef struct _GLFWwindowX11 109 { 110 Colormap colormap; 111 Window handle; 112 XIC ic; 113 114 GLFWbool overrideRedirect; 115 116 // Cached position and size used to filter out duplicate events 117 int width, height; 118 int xpos, ypos; 119 120 // The last received cursor position, regardless of source 121 int lastCursorPosX, lastCursorPosY; 122 // The last position the cursor was warped to by GLFW 123 int warpCursorPosX, warpCursorPosY; 124 125 // The information from the last KeyPress event 126 unsigned int lastKeyCode; 127 Time lastKeyTime; 128 129 } _GLFWwindowX11; 130 131 // X11-specific global data 132 // 133 typedef struct _GLFWlibraryX11 134 { 135 Display* display; 136 int screen; 137 Window root; 138 139 // Invisible cursor for hidden cursor mode 140 Cursor cursor; 141 // Context for mapping window XIDs to _GLFWwindow pointers 142 XContext context; 143 // XIM input method 144 XIM im; 145 // Most recent error code received by X error handler 146 int errorCode; 147 // Clipboard string (while the selection is owned) 148 char* clipboardString; 149 // Key name string 150 char keyName[64]; 151 // X11 keycode to GLFW key LUT 152 short int publicKeys[256]; 153 // GLFW key to X11 keycode LUT 154 short int nativeKeys[GLFW_KEY_LAST + 1]; 155 // Where to place the cursor when re-enabled 156 double restoreCursorPosX, restoreCursorPosY; 157 // The window whose disabled cursor mode is active 158 _GLFWwindow* disabledCursorWindow; 159 160 // Window manager atoms 161 Atom WM_PROTOCOLS; 162 Atom WM_STATE; 163 Atom WM_DELETE_WINDOW; 164 Atom NET_WM_NAME; 165 Atom NET_WM_ICON_NAME; 166 Atom NET_WM_ICON; 167 Atom NET_WM_PID; 168 Atom NET_WM_PING; 169 Atom NET_WM_WINDOW_TYPE; 170 Atom NET_WM_WINDOW_TYPE_NORMAL; 171 Atom NET_WM_STATE; 172 Atom NET_WM_STATE_ABOVE; 173 Atom NET_WM_STATE_FULLSCREEN; 174 Atom NET_WM_STATE_MAXIMIZED_VERT; 175 Atom NET_WM_STATE_MAXIMIZED_HORZ; 176 Atom NET_WM_BYPASS_COMPOSITOR; 177 Atom NET_WM_FULLSCREEN_MONITORS; 178 Atom NET_ACTIVE_WINDOW; 179 Atom NET_FRAME_EXTENTS; 180 Atom NET_REQUEST_FRAME_EXTENTS; 181 Atom MOTIF_WM_HINTS; 182 183 // Xdnd (drag and drop) atoms 184 Atom XdndAware; 185 Atom XdndEnter; 186 Atom XdndPosition; 187 Atom XdndStatus; 188 Atom XdndActionCopy; 189 Atom XdndDrop; 190 Atom XdndLeave; 191 Atom XdndFinished; 192 Atom XdndSelection; 193 194 // Selection (clipboard) atoms 195 Atom TARGETS; 196 Atom MULTIPLE; 197 Atom CLIPBOARD; 198 Atom CLIPBOARD_MANAGER; 199 Atom SAVE_TARGETS; 200 Atom NULL_; 201 Atom UTF8_STRING; 202 Atom COMPOUND_STRING; 203 Atom ATOM_PAIR; 204 Atom GLFW_SELECTION; 205 206 struct { 207 GLFWbool available; 208 int eventBase; 209 int errorBase; 210 int major; 211 int minor; 212 GLFWbool gammaBroken; 213 GLFWbool monitorBroken; 214 } randr; 215 216 struct { 217 GLFWbool available; 218 GLFWbool detectable; 219 int majorOpcode; 220 int eventBase; 221 int errorBase; 222 int major; 223 int minor; 224 } xkb; 225 226 struct { 227 int count; 228 int timeout; 229 int interval; 230 int blanking; 231 int exposure; 232 } saver; 233 234 struct { 235 Window source; 236 } xdnd; 237 238 struct { 239 GLFWbool available; 240 int major; 241 int minor; 242 } xinerama; 243 244 struct { 245 void* handle; 246 XGETXCBCONNECTION_T XGetXCBConnection; 247 } x11xcb; 248 249 #if defined(_GLFW_HAS_XF86VM) 250 struct { 251 GLFWbool available; 252 int eventBase; 253 int errorBase; 254 } vidmode; 255 #endif /*_GLFW_HAS_XF86VM*/ 256 257 } _GLFWlibraryX11; 258 259 // X11-specific per-monitor data 260 // 261 typedef struct _GLFWmonitorX11 262 { 263 RROutput output; 264 RRCrtc crtc; 265 RRMode oldMode; 266 267 // Index of corresponding Xinerama screen, 268 // for EWMH full screen window placement 269 int index; 270 271 } _GLFWmonitorX11; 272 273 // X11-specific per-cursor data 274 // 275 typedef struct _GLFWcursorX11 276 { 277 Cursor handle; 278 279 } _GLFWcursorX11; 280 281 282 GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired); 283 void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor); 284 285 Cursor _glfwCreateCursorX11(const GLFWimage* image, int xhot, int yhot); 286 287 unsigned long _glfwGetWindowPropertyX11(Window window, 288 Atom property, 289 Atom type, 290 unsigned char** value); 291 292 void _glfwGrabErrorHandlerX11(void); 293 void _glfwReleaseErrorHandlerX11(void); 294 void _glfwInputErrorX11(int error, const char* message); 295 296 #endif // _glfw3_x11_platform_h_ 297