1 /// Translated from C to D 2 module glfw3.x11_platform; 3 4 extern(C): @nogc: nothrow: __gshared: 5 //======================================================================== 6 // GLFW 3.3 X11 - www.glfw.org 7 //------------------------------------------------------------------------ 8 // Copyright (c) 2002-2006 Marcus Geelnard 9 // Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org> 10 // 11 // This software is provided 'as-is', without any express or implied 12 // warranty. In no event will the authors be held liable for any damages 13 // arising from the use of this software. 14 // 15 // Permission is granted to anyone to use this software for any purpose, 16 // including commercial applications, and to alter it and redistribute it 17 // freely, subject to the following restrictions: 18 // 19 // 1. The origin of this software must not be misrepresented; you must not 20 // claim that you wrote the original software. If you use this software 21 // in a product, an acknowledgment in the product documentation would 22 // be appreciated but is not required. 23 // 24 // 2. Altered source versions must be plainly marked as such, and must not 25 // be misrepresented as being the original software. 26 // 27 // 3. This notice may not be removed or altered from any source 28 // distribution. 29 // 30 //======================================================================== 31 32 import core.sys.posix.unistd; 33 import core.stdc.signal; 34 import core.stdc.stdint; 35 import core.sys.posix.dlfcn; 36 import core.stdc.config: c_long, c_ulong; 37 38 version(none) { 39 public import x11.X; 40 public import x11.Xutil; 41 public import x11.extensions.Xrender; 42 public import x11.extensions.randr; 43 public import x11.Xcursor; 44 45 public import x11.Xlib; 46 public import x11.keysym; 47 public import x11.Xatom; 48 49 // The XRandR extension provides mode setting and gamma control 50 public import x11.extensions.Xrandr; 51 52 // The Xkb extension provides improved keyboard support 53 //public import x11.XKBlib; 54 55 // The Xinerama extension provides legacy monitor indices 56 public import x11.extensions.Xinerama; 57 58 // The XInput extension provides raw mouse motion input 59 public import x11.extensions.XInput2; 60 } else { 61 public import glfw3.x11_header; 62 } 63 64 alias XRRCrtcGamma* function(int) PFN_XRRAllocGamma; 65 alias void function(XRRCrtcInfo*) PFN_XRRFreeCrtcInfo; 66 alias void function(XRRCrtcGamma*) PFN_XRRFreeGamma; 67 alias void function(XRROutputInfo*) PFN_XRRFreeOutputInfo; 68 alias void function(XRRScreenResources*) PFN_XRRFreeScreenResources; 69 alias XRRCrtcGamma* function(Display*, RRCrtc) PFN_XRRGetCrtcGamma; 70 alias int function(Display*, RRCrtc) PFN_XRRGetCrtcGammaSize; 71 alias XRRCrtcInfo* function(Display*, XRRScreenResources*, RRCrtc) PFN_XRRGetCrtcInfo; 72 alias XRROutputInfo* function(Display*, XRRScreenResources*, RROutput) PFN_XRRGetOutputInfo; 73 alias RROutput function(Display*, Window) PFN_XRRGetOutputPrimary; 74 alias XRRScreenResources* function(Display*, Window) PFN_XRRGetScreenResourcesCurrent; 75 alias Bool function(Display*, int*, int*) PFN_XRRQueryExtension; 76 alias Status function(Display*, int*, int*) PFN_XRRQueryVersion; 77 alias void function(Display*, Window, int) PFN_XRRSelectInput; 78 alias Status function(Display*, XRRScreenResources*, RRCrtc, Time, int, int, RRMode, Rotation, RROutput*, int) PFN_XRRSetCrtcConfig; 79 alias void function(Display*, RRCrtc, XRRCrtcGamma*) PFN_XRRSetCrtcGamma; 80 alias int function(XEvent*) PFN_XRRUpdateConfiguration; 81 alias XRRAllocGamma = _glfw.x11.randr.AllocGamma; 82 alias XRRFreeCrtcInfo = _glfw.x11.randr.FreeCrtcInfo; 83 alias XRRFreeGamma = _glfw.x11.randr.FreeGamma; 84 alias XRRFreeOutputInfo = _glfw.x11.randr.FreeOutputInfo; 85 alias XRRFreeScreenResources = _glfw.x11.randr.FreeScreenResources; 86 alias XRRGetCrtcGamma = _glfw.x11.randr.GetCrtcGamma; 87 alias XRRGetCrtcGammaSize = _glfw.x11.randr.GetCrtcGammaSize; 88 alias XRRGetCrtcInfo = _glfw.x11.randr.GetCrtcInfo; 89 alias XRRGetOutputInfo = _glfw.x11.randr.GetOutputInfo; 90 alias XRRGetOutputPrimary = _glfw.x11.randr.GetOutputPrimary; 91 alias XRRGetScreenResourcesCurrent = _glfw.x11.randr.GetScreenResourcesCurrent; 92 alias XRRQueryExtension = _glfw.x11.randr.QueryExtension; 93 alias XRRQueryVersion = _glfw.x11.randr.QueryVersion; 94 alias XRRSelectInput = _glfw.x11.randr.SelectInput; 95 alias XRRSetCrtcConfig = _glfw.x11.randr.SetCrtcConfig; 96 alias XRRSetCrtcGamma = _glfw.x11.randr.SetCrtcGamma; 97 alias XRRUpdateConfiguration = _glfw.x11.randr.UpdateConfiguration; 98 99 alias XcursorImage* function(int, int) PFN_XcursorImageCreate; 100 alias void function(XcursorImage*) PFN_XcursorImageDestroy; 101 alias Cursor function(Display*, const(XcursorImage)*) PFN_XcursorImageLoadCursor; 102 alias XcursorImageCreate = _glfw.x11.xcursor.ImageCreate; 103 alias XcursorImageDestroy = _glfw.x11.xcursor.ImageDestroy; 104 alias XcursorImageLoadCursor = _glfw.x11.xcursor.ImageLoadCursor; 105 106 alias Bool function(Display*) PFN_XineramaIsActive; 107 alias Bool function(Display*, int*, int*) PFN_XineramaQueryExtension; 108 alias XineramaScreenInfo* function(Display*, int*) PFN_XineramaQueryScreens; 109 alias XineramaIsActive = _glfw.x11.xinerama.IsActive; 110 alias XineramaQueryExtension = _glfw.x11.xinerama.QueryExtension; 111 alias XineramaQueryScreens = _glfw.x11.xinerama.QueryScreens; 112 113 alias XID xcb_window_t; 114 alias XID xcb_visualid_t; 115 struct xcb_connection_t ;/+alias xcb_connection_t xcb_connection_t;+/ 116 alias xcb_connection_t* function(Display*) PFN_XGetXCBConnection; 117 alias XGetXCBConnection = _glfw.x11.x11xcb.GetXCBConnection; 118 119 alias Bool function(Display*, int*, int*) PFN_XF86VidModeQueryExtension; 120 alias Bool function(Display*, int, int, ushort*, ushort*, ushort*) PFN_XF86VidModeGetGammaRamp; 121 alias Bool function(Display*, int, int, ushort*, ushort*, ushort*) PFN_XF86VidModeSetGammaRamp; 122 alias Bool function(Display*, int, int*) PFN_XF86VidModeGetGammaRampSize; 123 alias XF86VidModeQueryExtension = _glfw.x11.vidmode.QueryExtension; 124 alias XF86VidModeGetGammaRamp = _glfw.x11.vidmode.GetGammaRamp; 125 alias XF86VidModeSetGammaRamp = _glfw.x11.vidmode.SetGammaRamp; 126 alias XF86VidModeGetGammaRampSize = _glfw.x11.vidmode.GetGammaRampSize; 127 128 alias Status function(Display*, int*, int*) PFN_XIQueryVersion; 129 alias int function(Display*, Window, XIEventMask*, int) PFN_XISelectEvents; 130 alias XIQueryVersion = _glfw.x11.xi.QueryVersion; 131 alias XISelectEvents = _glfw.x11.xi.SelectEvents; 132 133 alias Bool function(Display*, int*, int*) PFN_XRenderQueryExtension; 134 alias Status function(Display* dpy, int*, int*) PFN_XRenderQueryVersion; 135 alias XRenderPictFormat* function(Display*, const(Visual)*) PFN_XRenderFindVisualFormat; 136 alias XRenderQueryExtension = _glfw.x11.xrender.QueryExtension; 137 alias XRenderQueryVersion = _glfw.x11.xrender.QueryVersion; 138 alias XRenderFindVisualFormat = _glfw.x11.xrender.FindVisualFormat; 139 140 alias VkFlags VkXlibSurfaceCreateFlagsKHR; 141 alias VkFlags VkXcbSurfaceCreateFlagsKHR; 142 143 struct VkXlibSurfaceCreateInfoKHR { 144 VkStructureType sType; 145 const(void)* pNext; 146 VkXlibSurfaceCreateFlagsKHR flags; 147 Display* dpy; 148 Window window; 149 }/+alias VkXlibSurfaceCreateInfoKHR VkXlibSurfaceCreateInfoKHR;+/ 150 151 struct VkXcbSurfaceCreateInfoKHR { 152 VkStructureType sType; 153 const(void)* pNext; 154 VkXcbSurfaceCreateFlagsKHR flags; 155 xcb_connection_t* connection; 156 xcb_window_t window; 157 }/+alias VkXcbSurfaceCreateInfoKHR VkXcbSurfaceCreateInfoKHR;+/ 158 159 alias VkResult function(VkInstance, const(VkXlibSurfaceCreateInfoKHR)*, const(VkAllocationCallbacks)*, VkSurfaceKHR*) PFN_vkCreateXlibSurfaceKHR; 160 alias VkBool32 function(VkPhysicalDevice, uint, Display*, VisualID) PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR; 161 alias VkResult function(VkInstance, const(VkXcbSurfaceCreateInfoKHR)*, const(VkAllocationCallbacks)*, VkSurfaceKHR*) PFN_vkCreateXcbSurfaceKHR; 162 alias VkBool32 function(VkPhysicalDevice, uint, xcb_connection_t*, xcb_visualid_t) PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR; 163 164 public import glfw3.posix_thread; 165 public import glfw3.posix_time; 166 public import glfw3.xkb_unicode; 167 public import glfw3.glx_context; 168 public import glfw3.egl_context; 169 public import glfw3.osmesa_context; 170 import glfw3.internal; 171 172 version (linux) { 173 public import glfw3.linux_joystick; 174 } else { 175 public import glfw3.null_joystick; 176 } 177 178 auto _glfw_dlopen(const(char)* name) {return dlopen(name, RTLD_LAZY | RTLD_LOCAL);} 179 auto _glfw_dlclose(void* handle) {return dlclose(handle);} 180 auto _glfw_dlsym(void* handle, const(char)* name) {return dlsym(handle, name);} 181 182 enum _GLFW_EGL_NATIVE_WINDOW = `(cast(EGLNativeWindowType) window.x11.handle)`; 183 enum _GLFW_EGL_NATIVE_DISPLAY = `(cast(EGLNativeDisplayType) _glfw.x11.display)`; 184 185 mixin template _GLFW_PLATFORM_WINDOW_STATE() { _GLFWwindowX11 x11;} 186 mixin template _GLFW_PLATFORM_LIBRARY_WINDOW_STATE() { _GLFWlibraryX11 x11;} 187 mixin template _GLFW_PLATFORM_MONITOR_STATE() { _GLFWmonitorX11 x11;} 188 mixin template _GLFW_PLATFORM_CURSOR_STATE() { _GLFWcursorX11 x11;} 189 190 // X11-specific per-window data 191 // 192 struct _GLFWwindowX11 { 193 Colormap colormap; 194 Window handle; 195 Window parent; 196 XIC ic; 197 198 GLFWbool overrideRedirect; 199 GLFWbool iconified; 200 GLFWbool maximized; 201 202 // Whether the visual supports framebuffer transparency 203 GLFWbool transparent; 204 205 // Cached position and size used to filter out duplicate events 206 int width;int height; 207 int xpos;int ypos; 208 209 // The last received cursor position, regardless of source 210 int lastCursorPosX;int lastCursorPosY; 211 // The last position the cursor was warped to by GLFW 212 int warpCursorPosX;int warpCursorPosY; 213 214 // The time of the last KeyPress event 215 Time lastKeyTime; 216 217 }/+alias _GLFWwindowX11 _GLFWwindowX11;+/ 218 219 // X11-specific global data 220 // 221 struct _GLFWlibraryX11 { 222 Display* display; 223 int screen; 224 Window root; 225 226 // System content scale 227 float contentScaleX;float contentScaleY; 228 // Helper window for IPC 229 Window helperWindowHandle; 230 // Invisible cursor for hidden cursor mode 231 Cursor hiddenCursorHandle; 232 // Context for mapping window XIDs to _GLFWwindow pointers 233 XContext context; 234 // XIM input method 235 XIM im; 236 // Most recent error code received by X error handler 237 int errorCode; 238 // Primary selection string (while the primary selection is owned) 239 char* primarySelectionString; 240 // Clipboard string (while the selection is owned) 241 char* clipboardString; 242 // Key name string 243 char[5][GLFW_KEY_LAST + 1] keynames; 244 // X11 keycode to GLFW key LUT 245 int[256] keycodes; 246 // GLFW key to X11 keycode LUT 247 int[GLFW_KEY_LAST + 1] scancodes; 248 // Where to place the cursor when re-enabled 249 double restoreCursorPosX;double restoreCursorPosY; 250 // The window whose disabled cursor mode is active 251 _GLFWwindow* disabledCursorWindow; 252 253 // Window manager atoms 254 Atom NET_SUPPORTED; 255 Atom NET_SUPPORTING_WM_CHECK; 256 Atom WM_PROTOCOLS; 257 Atom WM_STATE; 258 Atom WM_DELETE_WINDOW; 259 Atom NET_WM_NAME; 260 Atom NET_WM_ICON_NAME; 261 Atom NET_WM_ICON; 262 Atom NET_WM_PID; 263 Atom NET_WM_PING; 264 Atom NET_WM_WINDOW_TYPE; 265 Atom NET_WM_WINDOW_TYPE_NORMAL; 266 Atom NET_WM_STATE; 267 Atom NET_WM_STATE_ABOVE; 268 Atom NET_WM_STATE_FULLSCREEN; 269 Atom NET_WM_STATE_MAXIMIZED_VERT; 270 Atom NET_WM_STATE_MAXIMIZED_HORZ; 271 Atom NET_WM_STATE_DEMANDS_ATTENTION; 272 Atom NET_WM_BYPASS_COMPOSITOR; 273 Atom NET_WM_FULLSCREEN_MONITORS; 274 Atom NET_WM_WINDOW_OPACITY; 275 Atom NET_WM_CM_Sx; 276 Atom NET_WORKAREA; 277 Atom NET_CURRENT_DESKTOP; 278 Atom NET_ACTIVE_WINDOW; 279 Atom NET_FRAME_EXTENTS; 280 Atom NET_REQUEST_FRAME_EXTENTS; 281 Atom MOTIF_WM_HINTS; 282 283 // Xdnd (drag and drop) atoms 284 Atom XdndAware; 285 Atom XdndEnter; 286 Atom XdndPosition; 287 Atom XdndStatus; 288 Atom XdndActionCopy; 289 Atom XdndDrop; 290 Atom XdndFinished; 291 Atom XdndSelection; 292 Atom XdndTypeList; 293 Atom text_uri_list; 294 295 // Selection (clipboard) atoms 296 Atom TARGETS; 297 Atom MULTIPLE; 298 Atom INCR; 299 Atom CLIPBOARD; 300 Atom PRIMARY; 301 Atom CLIPBOARD_MANAGER; 302 Atom SAVE_TARGETS; 303 Atom NULL_; 304 Atom UTF8_STRING; 305 Atom COMPOUND_STRING; 306 Atom ATOM_PAIR; 307 Atom GLFW_SELECTION; 308 309 struct _Randr { 310 GLFWbool available; 311 void* handle; 312 int eventBase; 313 int errorBase; 314 int major; 315 int minor; 316 GLFWbool gammaBroken; 317 GLFWbool monitorBroken; 318 PFN_XRRAllocGamma AllocGamma; 319 PFN_XRRFreeCrtcInfo FreeCrtcInfo; 320 PFN_XRRFreeGamma FreeGamma; 321 PFN_XRRFreeOutputInfo FreeOutputInfo; 322 PFN_XRRFreeScreenResources FreeScreenResources; 323 PFN_XRRGetCrtcGamma GetCrtcGamma; 324 PFN_XRRGetCrtcGammaSize GetCrtcGammaSize; 325 PFN_XRRGetCrtcInfo GetCrtcInfo; 326 PFN_XRRGetOutputInfo GetOutputInfo; 327 PFN_XRRGetOutputPrimary GetOutputPrimary; 328 PFN_XRRGetScreenResourcesCurrent GetScreenResourcesCurrent; 329 PFN_XRRQueryExtension QueryExtension; 330 PFN_XRRQueryVersion QueryVersion; 331 PFN_XRRSelectInput SelectInput; 332 PFN_XRRSetCrtcConfig SetCrtcConfig; 333 PFN_XRRSetCrtcGamma SetCrtcGamma; 334 PFN_XRRUpdateConfiguration UpdateConfiguration; 335 }_Randr randr; 336 337 struct _Xkb { 338 GLFWbool available; 339 GLFWbool detectable; 340 int majorOpcode; 341 int eventBase; 342 int errorBase; 343 int major; 344 int minor; 345 uint group; 346 }_Xkb xkb; 347 348 struct _Saver { 349 int count; 350 int timeout; 351 int interval; 352 int blanking; 353 int exposure; 354 }_Saver saver; 355 356 struct _Xdnd { 357 int version_; 358 Window source; 359 Atom format; 360 }_Xdnd xdnd; 361 362 struct _Xcursor { 363 void* handle; 364 PFN_XcursorImageCreate ImageCreate; 365 PFN_XcursorImageDestroy ImageDestroy; 366 PFN_XcursorImageLoadCursor ImageLoadCursor; 367 }_Xcursor xcursor; 368 369 struct _Xinerama { 370 GLFWbool available; 371 void* handle; 372 int major; 373 int minor; 374 PFN_XineramaIsActive IsActive; 375 PFN_XineramaQueryExtension QueryExtension; 376 PFN_XineramaQueryScreens QueryScreens; 377 }_Xinerama xinerama; 378 379 struct _X11xcb { 380 void* handle; 381 PFN_XGetXCBConnection GetXCBConnection; 382 }_X11xcb x11xcb; 383 384 struct _Vidmode { 385 GLFWbool available; 386 void* handle; 387 int eventBase; 388 int errorBase; 389 PFN_XF86VidModeQueryExtension QueryExtension; 390 PFN_XF86VidModeGetGammaRamp GetGammaRamp; 391 PFN_XF86VidModeSetGammaRamp SetGammaRamp; 392 PFN_XF86VidModeGetGammaRampSize GetGammaRampSize; 393 }_Vidmode vidmode; 394 395 struct _Xi { 396 GLFWbool available; 397 void* handle; 398 int majorOpcode; 399 int eventBase; 400 int errorBase; 401 int major; 402 int minor; 403 PFN_XIQueryVersion QueryVersion; 404 PFN_XISelectEvents SelectEvents; 405 }_Xi xi; 406 407 struct _Xrender { 408 GLFWbool available; 409 void* handle; 410 int major; 411 int minor; 412 int eventBase; 413 int errorBase; 414 PFN_XRenderQueryExtension QueryExtension; 415 PFN_XRenderQueryVersion QueryVersion; 416 PFN_XRenderFindVisualFormat FindVisualFormat; 417 }_Xrender xrender; 418 419 }/+alias _GLFWlibraryX11 _GLFWlibraryX11;+/ 420 421 // X11-specific per-monitor data 422 // 423 struct _GLFWmonitorX11 { 424 RROutput output; 425 RRCrtc crtc; 426 RRMode oldMode; 427 428 // Index of corresponding Xinerama screen, 429 // for EWMH full screen window placement 430 int index; 431 432 }/+alias _GLFWmonitorX11 _GLFWmonitorX11;+/ 433 434 // X11-specific per-cursor data 435 // 436 struct _GLFWcursorX11 { 437 Cursor handle; 438 439 }/+alias _GLFWcursorX11 _GLFWcursorX11;+/ 440 441 442 void _glfwPollMonitorsX11(); 443 void _glfwSetVideoModeX11(_GLFWmonitor* monitor, const(GLFWvidmode)* desired); 444 void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor); 445 446 Cursor _glfwCreateCursorX11(const(GLFWimage)* image, int xhot, int yhot); 447 448 c_ulong _glfwGetWindowPropertyX11(Window window, Atom property, Atom type, ubyte** value); 449 GLFWbool _glfwIsVisualTransparentX11(Visual* visual); 450 451 void _glfwGrabErrorHandlerX11(); 452 void _glfwReleaseErrorHandlerX11(); 453 void _glfwInputErrorX11(int error, const(char)* message); 454 455 void _glfwPushSelectionToManagerX11();