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