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
55typedef XID xcb_window_t;
56typedef XID xcb_visualid_t;
57typedef struct xcb_connection_t xcb_connection_t;
58typedef xcb_connection_t* (* XGETXCBCONNECTION_T)(Display*);
59
60typedef VkFlags VkXlibSurfaceCreateFlagsKHR;
61typedef VkFlags VkXcbSurfaceCreateFlagsKHR;
62
63typedef struct VkXlibSurfaceCreateInfoKHR
64{
65 VkStructureType sType;
66 const void* pNext;
67 VkXlibSurfaceCreateFlagsKHR flags;
68 Display* dpy;
69 Window window;
70} VkXlibSurfaceCreateInfoKHR;
71
72typedef 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
81typedef VkResult (APIENTRY *PFN_vkCreateXlibSurfaceKHR)(VkInstance,const VkXlibSurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*);
82typedef VkBool32 (APIENTRY *PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice,uint32_t,Display*,VisualID);
83typedef VkResult (APIENTRY *PFN_vkCreateXcbSurfaceKHR)(VkInstance,const VkXcbSurfaceCreateInfoKHR*,const VkAllocationCallbacks*,VkSurfaceKHR*);
84typedef 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//
108typedef 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 struct {
127 unsigned int keycode;
128 Time time;
129 } last;
130
131} _GLFWwindowX11;
132
133
134// X11-specific global data
135//
136typedef struct _GLFWlibraryX11
137{
138 Display* display;
139 int screen;
140 Window root;
141
142 // Invisible cursor for hidden cursor mode
143 Cursor cursor;
144 // Context for mapping window XIDs to _GLFWwindow pointers
145 XContext context;
146 // XIM input method
147 XIM im;
148 // Most recent error code received by X error handler
149 int errorCode;
150 // Clipboard string (while the selection is owned)
151 char* clipboardString;
152 // Key name string
153 char keyName[64];
154 // X11 keycode to GLFW key LUT
155 short int publicKeys[256];
156 // GLFW key to X11 keycode LUT
157 short int nativeKeys[GLFW_KEY_LAST + 1];
158 // Where to place the cursor when re-enabled
159 double restoreCursorPosX, restoreCursorPosY;
160 // The window whose disabled cursor mode is active
161 _GLFWwindow* disabledCursorWindow;
162
163 // Window manager atoms
164 Atom WM_PROTOCOLS;
165 Atom WM_STATE;
166 Atom WM_DELETE_WINDOW;
167 Atom NET_WM_NAME;
168 Atom NET_WM_ICON_NAME;
169 Atom NET_WM_ICON;
170 Atom NET_WM_PID;
171 Atom NET_WM_PING;
172 Atom NET_WM_WINDOW_TYPE;
173 Atom NET_WM_WINDOW_TYPE_NORMAL;
174 Atom NET_WM_STATE;
175 Atom NET_WM_STATE_ABOVE;
176 Atom NET_WM_STATE_FULLSCREEN;
177 Atom NET_WM_STATE_MAXIMIZED_VERT;
178 Atom NET_WM_STATE_MAXIMIZED_HORZ;
179 Atom NET_WM_BYPASS_COMPOSITOR;
180 Atom NET_WM_FULLSCREEN_MONITORS;
181 Atom NET_ACTIVE_WINDOW;
182 Atom NET_FRAME_EXTENTS;
183 Atom NET_REQUEST_FRAME_EXTENTS;
184 Atom MOTIF_WM_HINTS;
185
186 // Xdnd (drag and drop) atoms
187 Atom XdndAware;
188 Atom XdndEnter;
189 Atom XdndPosition;
190 Atom XdndStatus;
191 Atom XdndActionCopy;
192 Atom XdndDrop;
193 Atom XdndLeave;
194 Atom XdndFinished;
195 Atom XdndSelection;
196
197 // Selection (clipboard) atoms
198 Atom TARGETS;
199 Atom MULTIPLE;
200 Atom CLIPBOARD;
201 Atom CLIPBOARD_MANAGER;
202 Atom SAVE_TARGETS;
203 Atom NULL_;
204 Atom UTF8_STRING;
205 Atom COMPOUND_STRING;
206 Atom ATOM_PAIR;
207 Atom GLFW_SELECTION;
208
209 struct {
210 GLFWbool available;
211 int eventBase;
212 int errorBase;
213 int major;
214 int minor;
215 GLFWbool gammaBroken;
216 GLFWbool monitorBroken;
217 } randr;
218
219 struct {
220 GLFWbool available;
221 GLFWbool detectable;
222 int majorOpcode;
223 int eventBase;
224 int errorBase;
225 int major;
226 int minor;
227 } xkb;
228
229 struct {
230 int count;
231 int timeout;
232 int interval;
233 int blanking;
234 int exposure;
235 } saver;
236
237 struct {
238 Window source;
239 } xdnd;
240
241 struct {
242 GLFWbool available;
243 int major;
244 int minor;
245 } xinerama;
246
247 struct {
248 void* handle;
249 XGETXCBCONNECTION_T XGetXCBConnection;
250 } x11xcb;
251
252#if defined(_GLFW_HAS_XF86VM)
253 struct {
254 GLFWbool available;
255 int eventBase;
256 int errorBase;
257 } vidmode;
258#endif /*_GLFW_HAS_XF86VM*/
259
260} _GLFWlibraryX11;
261
262
263// X11-specific per-monitor data
264//
265typedef struct _GLFWmonitorX11
266{
267 RROutput output;
268 RRCrtc crtc;
269 RRMode oldMode;
270
271 // Index of corresponding Xinerama screen,
272 // for EWMH full screen window placement
273 int index;
274
275} _GLFWmonitorX11;
276
277
278// X11-specific per-cursor data
279//
280typedef struct _GLFWcursorX11
281{
282 Cursor handle;
283
284} _GLFWcursorX11;
285
286
287GLFWbool _glfwSetVideoModeX11(_GLFWmonitor* monitor, const GLFWvidmode* desired);
288void _glfwRestoreVideoModeX11(_GLFWmonitor* monitor);
289
290Cursor _glfwCreateCursorX11(const GLFWimage* image, int xhot, int yhot);
291
292unsigned long _glfwGetWindowPropertyX11(Window window,
293 Atom property,
294 Atom type,
295 unsigned char** value);
296
297void _glfwGrabErrorHandlerX11(void);
298void _glfwReleaseErrorHandlerX11(void);
299void _glfwInputErrorX11(int error, const char* message);
300
301#endif // _glfw3_x11_platform_h_
302