1 //========================================================================
2 // GLFW 3.4 - 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 #pragma once
29 
30 #include "../kitty/monotonic.h"
31 
32 #if defined(_GLFW_USE_CONFIG_H)
33  #include "glfw_config.h"
34 #endif
35 
36 #define arraysz(x) (sizeof(x)/sizeof(x[0]))
37 
38 #if defined(GLFW_INCLUDE_GLCOREARB) || \
39     defined(GLFW_INCLUDE_ES1)       || \
40     defined(GLFW_INCLUDE_ES2)       || \
41     defined(GLFW_INCLUDE_ES3)       || \
42     defined(GLFW_INCLUDE_ES31)      || \
43     defined(GLFW_INCLUDE_ES32)      || \
44     defined(GLFW_INCLUDE_NONE)      || \
45     defined(GLFW_INCLUDE_GLEXT)     || \
46     defined(GLFW_INCLUDE_GLU)       || \
47     defined(GLFW_INCLUDE_VULKAN)    || \
48     defined(GLFW_DLL)
49  #error "You must not define any header option macros when compiling GLFW"
50 #endif
51 
52 #define GLFW_INCLUDE_NONE
53 #include "glfw3.h"
54 
55 #define _GLFW_INSERT_FIRST      0
56 #define _GLFW_INSERT_LAST       1
57 
58 #define _GLFW_POLL_PRESENCE     0
59 #define _GLFW_POLL_AXES         1
60 #define _GLFW_POLL_BUTTONS      2
61 #define _GLFW_POLL_ALL          (_GLFW_POLL_AXES | _GLFW_POLL_BUTTONS)
62 
63 #define _GLFW_MESSAGE_SIZE      1024
64 
65 typedef unsigned long long GLFWid;
66 
67 typedef struct _GLFWerror       _GLFWerror;
68 typedef struct _GLFWinitconfig  _GLFWinitconfig;
69 typedef struct _GLFWwndconfig   _GLFWwndconfig;
70 typedef struct _GLFWctxconfig   _GLFWctxconfig;
71 typedef struct _GLFWfbconfig    _GLFWfbconfig;
72 typedef struct _GLFWcontext     _GLFWcontext;
73 typedef struct _GLFWwindow      _GLFWwindow;
74 typedef struct _GLFWlibrary     _GLFWlibrary;
75 typedef struct _GLFWmonitor     _GLFWmonitor;
76 typedef struct _GLFWcursor      _GLFWcursor;
77 typedef struct _GLFWmapelement  _GLFWmapelement;
78 typedef struct _GLFWmapping     _GLFWmapping;
79 typedef struct _GLFWjoystick    _GLFWjoystick;
80 typedef struct _GLFWtls         _GLFWtls;
81 typedef struct _GLFWmutex       _GLFWmutex;
82 
83 typedef void (* _GLFWmakecontextcurrentfun)(_GLFWwindow*);
84 typedef void (* _GLFWswapbuffersfun)(_GLFWwindow*);
85 typedef void (* _GLFWswapintervalfun)(int);
86 typedef int (* _GLFWextensionsupportedfun)(const char*);
87 typedef GLFWglproc (* _GLFWgetprocaddressfun)(const char*);
88 typedef void (* _GLFWdestroycontextfun)(_GLFWwindow*);
89 
90 #define GL_VERSION 0x1f02
91 #define GL_NONE 0
92 #define GL_COLOR_BUFFER_BIT 0x00004000
93 #define GL_UNSIGNED_BYTE 0x1401
94 #define GL_EXTENSIONS 0x1f03
95 #define GL_NUM_EXTENSIONS 0x821d
96 #define GL_CONTEXT_FLAGS 0x821e
97 #define GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT 0x00000001
98 #define GL_CONTEXT_FLAG_DEBUG_BIT 0x00000002
99 #define GL_CONTEXT_PROFILE_MASK 0x9126
100 #define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
101 #define GL_CONTEXT_CORE_PROFILE_BIT 0x00000001
102 #define GL_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
103 #define GL_LOSE_CONTEXT_ON_RESET_ARB 0x8252
104 #define GL_NO_RESET_NOTIFICATION_ARB 0x8261
105 #define GL_CONTEXT_RELEASE_BEHAVIOR 0x82fb
106 #define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82fc
107 #define GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR 0x00000008
108 
109 typedef int GLint;
110 typedef unsigned int GLuint;
111 typedef unsigned int GLenum;
112 typedef unsigned int GLbitfield;
113 typedef unsigned char GLubyte;
114 
115 typedef void (APIENTRY * PFNGLCLEARPROC)(GLbitfield);
116 typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGPROC)(GLenum);
117 typedef void (APIENTRY * PFNGLGETINTEGERVPROC)(GLenum,GLint*);
118 typedef const GLubyte* (APIENTRY * PFNGLGETSTRINGIPROC)(GLenum,GLuint);
119 
120 #define VK_NULL_HANDLE 0
121 
122 typedef void* VkInstance;
123 typedef void* VkPhysicalDevice;
124 typedef uint64_t VkSurfaceKHR;
125 typedef uint32_t VkFlags;
126 typedef uint32_t VkBool32;
127 
128 typedef enum VkStructureType
129 {
130     VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR = 1000004000,
131     VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR = 1000005000,
132     VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR = 1000006000,
133     VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR = 1000009000,
134     VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK = 1000123000,
135     VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT = 1000217000,
136     VK_STRUCTURE_TYPE_MAX_ENUM = 0x7FFFFFFF
137 } VkStructureType;
138 
139 typedef enum VkResult
140 {
141     VK_SUCCESS = 0,
142     VK_NOT_READY = 1,
143     VK_TIMEOUT = 2,
144     VK_EVENT_SET = 3,
145     VK_EVENT_RESET = 4,
146     VK_INCOMPLETE = 5,
147     VK_ERROR_OUT_OF_HOST_MEMORY = -1,
148     VK_ERROR_OUT_OF_DEVICE_MEMORY = -2,
149     VK_ERROR_INITIALIZATION_FAILED = -3,
150     VK_ERROR_DEVICE_LOST = -4,
151     VK_ERROR_MEMORY_MAP_FAILED = -5,
152     VK_ERROR_LAYER_NOT_PRESENT = -6,
153     VK_ERROR_EXTENSION_NOT_PRESENT = -7,
154     VK_ERROR_FEATURE_NOT_PRESENT = -8,
155     VK_ERROR_INCOMPATIBLE_DRIVER = -9,
156     VK_ERROR_TOO_MANY_OBJECTS = -10,
157     VK_ERROR_FORMAT_NOT_SUPPORTED = -11,
158     VK_ERROR_SURFACE_LOST_KHR = -1000000000,
159     VK_SUBOPTIMAL_KHR = 1000001003,
160     VK_ERROR_OUT_OF_DATE_KHR = -1000001004,
161     VK_ERROR_INCOMPATIBLE_DISPLAY_KHR = -1000003001,
162     VK_ERROR_NATIVE_WINDOW_IN_USE_KHR = -1000000001,
163     VK_ERROR_VALIDATION_FAILED_EXT = -1000011001,
164     VK_RESULT_MAX_ENUM = 0x7FFFFFFF
165 } VkResult;
166 
167 typedef struct VkAllocationCallbacks VkAllocationCallbacks;
168 
169 typedef struct VkExtensionProperties
170 {
171     char            extensionName[256];
172     uint32_t        specVersion;
173 } VkExtensionProperties;
174 
175 typedef void (APIENTRY * PFN_vkVoidFunction)(void);
176 
177 #if defined(_GLFW_VULKAN_STATIC)
178   PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance,const char*);
179   VkResult vkEnumerateInstanceExtensionProperties(const char*,uint32_t*,VkExtensionProperties*);
180 #else
181   typedef PFN_vkVoidFunction (APIENTRY * PFN_vkGetInstanceProcAddr)(VkInstance,const char*);
182   typedef VkResult (APIENTRY * PFN_vkEnumerateInstanceExtensionProperties)(const char*,uint32_t*,VkExtensionProperties*);
183   #define vkEnumerateInstanceExtensionProperties _glfw.vk.EnumerateInstanceExtensionProperties
184   #define vkGetInstanceProcAddr _glfw.vk.GetInstanceProcAddr
185 #endif
186 
187 #if defined(_GLFW_COCOA)
188  #include "cocoa_platform.h"
189 #elif defined(_GLFW_WIN32)
190  #include "win32_platform.h"
191 #elif defined(_GLFW_X11)
192  #include "x11_platform.h"
193 #elif defined(_GLFW_WAYLAND)
194  #include "wl_platform.h"
195 #elif defined(_GLFW_OSMESA)
196  #include "null_platform.h"
197 #else
198  #error "No supported window creation API selected"
199 #endif
200 
201 #include "egl_context.h"
202 #include "osmesa_context.h"
203 
204 #define remove_i_from_array(array, i, count) { \
205     (count)--; \
206     if ((i) < (count)) { \
207         memmove((array) + (i), (array) + (i) + 1, sizeof((array)[0]) * ((count) - (i))); \
208     }}
209 
210 
211 // Constructs a version number string from the public header macros
212 #define _GLFW_CONCAT_VERSION(m, n, r) #m "." #n "." #r
213 #define _GLFW_MAKE_VERSION(m, n, r) _GLFW_CONCAT_VERSION(m, n, r)
214 #define _GLFW_VERSION_NUMBER _GLFW_MAKE_VERSION(GLFW_VERSION_MAJOR, \
215                                                 GLFW_VERSION_MINOR, \
216                                                 GLFW_VERSION_REVISION)
217 
218 // Checks for whether the library has been initialized
219 #define _GLFW_REQUIRE_INIT()                         \
220     if (!_glfw.initialized)                          \
221     {                                                \
222         _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
223         return;                                      \
224     }
225 #define _GLFW_REQUIRE_INIT_OR_RETURN(x)              \
226     if (!_glfw.initialized)                          \
227     {                                                \
228         _glfwInputError(GLFW_NOT_INITIALIZED, NULL); \
229         return x;                                    \
230     }
231 
232 // Swaps the provided pointers
233 #define _GLFW_SWAP_POINTERS(x, y) \
234     do{                           \
235         __typeof__(x) t;          \
236         t = x;                    \
237         x = y;                    \
238         y = t;                    \
239     }while(0)
240 
241 
242 // Suppress some pedantic warnings
243 #ifdef __clang__
244 #define START_ALLOW_CASE_RANGE _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wpedantic\"")
245 #define END_ALLOW_CASE_RANGE _Pragma("clang diagnostic pop")
246 #define ALLOW_UNUSED_RESULT _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wunused-result\"")
247 #define END_ALLOW_UNUSED_RESULT _Pragma("clang diagnostic pop")
248 #else
249 #define START_ALLOW_CASE_RANGE _Pragma("GCC diagnostic ignored \"-Wpedantic\"")
250 #define END_ALLOW_CASE_RANGE _Pragma("GCC diagnostic pop")
251 #define ALLOW_UNUSED_RESULT _Pragma("GCC diagnostic ignored \"-Wunused-result\"")
252 #define END_ALLOW_UNUSED_RESULT _Pragma("GCC diagnostic pop")
253 #endif
254 
255 // dlsym that works with -Wpedantic
256 #define glfw_dlsym(dest, handle, name) do {*(void **)&(dest) = _glfw_dlsym(handle, name);}while (0)
257 
258 // Mark function arguments as unused
259 #define UNUSED __attribute__ ((unused))
260 
261 // Per-thread error structure
262 //
263 struct _GLFWerror
264 {
265     _GLFWerror*     next;
266     int             code;
267     char            description[_GLFW_MESSAGE_SIZE];
268 };
269 
270 // Initialization configuration
271 //
272 // Parameters relating to the initialization of the library
273 //
274 struct _GLFWinitconfig
275 {
276     bool          hatButtons;
277     int           angleType;
278     bool          debugKeyboard;
279     bool          debugRendering;
280     struct {
281         bool      menubar;
282         bool      chdir;
283     } ns;
284 };
285 
286 // Window configuration
287 //
288 // Parameters relating to the creation of the window but not directly related
289 // to the framebuffer.  This is used to pass window creation parameters from
290 // shared code to the platform API.
291 //
292 struct _GLFWwndconfig
293 {
294     int           width;
295     int           height;
296     const char*   title;
297     bool          resizable;
298     bool          visible;
299     bool          decorated;
300     bool          focused;
301     bool          autoIconify;
302     bool          floating;
303     bool          maximized;
304     bool          centerCursor;
305     bool          focusOnShow;
306     bool          mousePassthrough;
307     bool          scaleToMonitor;
308     struct {
309         bool      retina;
310         char      frameName[256];
311     } ns;
312     struct {
313         char      className[256];
314         char      instanceName[256];
315     } x11;
316     struct {
317         char      appId[256];
318     } wl;
319 };
320 
321 // Context configuration
322 //
323 // Parameters relating to the creation of the context but not directly related
324 // to the framebuffer.  This is used to pass context creation parameters from
325 // shared code to the platform API.
326 //
327 struct _GLFWctxconfig
328 {
329     int           client;
330     int           source;
331     int           major;
332     int           minor;
333     bool          forward;
334     bool          debug;
335     bool          noerror;
336     int           profile;
337     int           robustness;
338     int           release;
339     _GLFWwindow*  share;
340     struct {
341         bool      offline;
342     } nsgl;
343 };
344 
345 // Framebuffer configuration
346 //
347 // This describes buffers and their sizes.  It also contains
348 // a platform-specific ID used to map back to the backend API object.
349 //
350 // It is used to pass framebuffer parameters from shared code to the platform
351 // API and also to enumerate and select available framebuffer configs.
352 //
353 struct _GLFWfbconfig
354 {
355     int         redBits;
356     int         greenBits;
357     int         blueBits;
358     int         alphaBits;
359     int         depthBits;
360     int         stencilBits;
361     int         accumRedBits;
362     int         accumGreenBits;
363     int         accumBlueBits;
364     int         accumAlphaBits;
365     int         auxBuffers;
366     bool        stereo;
367     int         samples;
368     bool        sRGB;
369     bool        doublebuffer;
370     bool        transparent;
371     uintptr_t   handle;
372 };
373 
374 // Context structure
375 //
376 struct _GLFWcontext
377 {
378     int                 client;
379     int                 source;
380     int                 major, minor, revision;
381     bool                forward, debug, noerror;
382     int                 profile;
383     int                 robustness;
384     int                 release;
385 
386     PFNGLGETSTRINGIPROC GetStringi;
387     PFNGLGETINTEGERVPROC GetIntegerv;
388     PFNGLGETSTRINGPROC  GetString;
389 
390     _GLFWmakecontextcurrentfun  makeCurrent;
391     _GLFWswapbuffersfun         swapBuffers;
392     _GLFWswapintervalfun        swapInterval;
393     _GLFWextensionsupportedfun  extensionSupported;
394     _GLFWgetprocaddressfun      getProcAddress;
395     _GLFWdestroycontextfun      destroy;
396 
397     // This is defined in the context API's context.h
398     _GLFW_PLATFORM_CONTEXT_STATE
399     // This is defined in egl_context.h
400     _GLFWcontextEGL egl;
401     // This is defined in osmesa_context.h
402     _GLFWcontextOSMesa osmesa;
403 };
404 
405 typedef struct GLFWKeyState {
406     uint32_t key;
407     char action;
408 } GLFWKeyState;
409 
410 // Window and context structure
411 //
412 struct _GLFWwindow
413 {
414     struct _GLFWwindow* next;
415 
416     // Window settings and state
417     bool                resizable;
418     bool                decorated;
419     bool                autoIconify;
420     bool                floating;
421     bool                focusOnShow;
422     bool                mousePassthrough;
423     bool                shouldClose;
424     void*               userPointer;
425     GLFWid              id;
426     GLFWvidmode         videoMode;
427     _GLFWmonitor*       monitor;
428     _GLFWcursor*        cursor;
429 
430     int                 minwidth, minheight;
431     int                 maxwidth, maxheight;
432     int                 numer, denom;
433     int                 widthincr, heightincr;
434 
435     bool                stickyKeys;
436     bool                stickyMouseButtons;
437     bool                lockKeyMods;
438     int                 cursorMode;
439     char                mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1];
440     GLFWKeyState        activated_keys[16];
441     // Virtual cursor position when cursor is disabled
442     double              virtualCursorPosX, virtualCursorPosY;
443     bool                rawMouseMotion;
444 
445     _GLFWcontext        context;
446 
447     struct {
448         GLFWwindowposfun        pos;
449         GLFWwindowsizefun       size;
450         GLFWwindowclosefun      close;
451         GLFWwindowrefreshfun    refresh;
452         GLFWwindowfocusfun      focus;
453         GLFWwindowocclusionfun  occlusion;
454         GLFWwindowiconifyfun    iconify;
455         GLFWwindowmaximizefun   maximize;
456         GLFWframebuffersizefun  fbsize;
457         GLFWwindowcontentscalefun scale;
458         GLFWmousebuttonfun      mouseButton;
459         GLFWcursorposfun        cursorPos;
460         GLFWcursorenterfun      cursorEnter;
461         GLFWscrollfun           scroll;
462         GLFWkeyboardfun         keyboard;
463         GLFWdropfun             drop;
464         GLFWliveresizefun       liveResize;
465     } callbacks;
466 
467     // This is defined in the window API's platform.h
468     _GLFW_PLATFORM_WINDOW_STATE;
469 };
470 
471 // Monitor structure
472 //
473 struct _GLFWmonitor
474 {
475     char*           name;
476     void*           userPointer;
477 
478     // Physical dimensions in millimeters.
479     int             widthMM, heightMM;
480 
481     // The window whose video mode is current on this monitor
482     _GLFWwindow*    window;
483 
484     GLFWvidmode*    modes;
485     int             modeCount;
486     GLFWvidmode     currentMode;
487 
488     GLFWgammaramp   originalRamp;
489     GLFWgammaramp   currentRamp;
490 
491     // This is defined in the window API's platform.h
492     _GLFW_PLATFORM_MONITOR_STATE;
493 };
494 
495 // Cursor structure
496 //
497 struct _GLFWcursor
498 {
499     _GLFWcursor*    next;
500 
501     // This is defined in the window API's platform.h
502     _GLFW_PLATFORM_CURSOR_STATE;
503 };
504 
505 // Gamepad mapping element structure
506 //
507 struct _GLFWmapelement
508 {
509     uint8_t         type;
510     uint8_t         index;
511     int8_t          axisScale;
512     int8_t          axisOffset;
513 };
514 
515 // Gamepad mapping structure
516 //
517 struct _GLFWmapping
518 {
519     char            name[128];
520     char            guid[33];
521     _GLFWmapelement buttons[15];
522     _GLFWmapelement axes[6];
523 };
524 
525 // Joystick structure
526 //
527 struct _GLFWjoystick
528 {
529     bool            present;
530     float*          axes;
531     int             axisCount;
532     unsigned char*  buttons;
533     int             buttonCount;
534     unsigned char*  hats;
535     int             hatCount;
536     char*           name;
537     void*           userPointer;
538     char            guid[33];
539     _GLFWmapping*   mapping;
540 
541     // This is defined in the joystick API's joystick.h
542     _GLFW_PLATFORM_JOYSTICK_STATE;
543 };
544 
545 // Thread local storage structure
546 //
547 struct _GLFWtls
548 {
549     // This is defined in the platform's thread.h
550     _GLFW_PLATFORM_TLS_STATE;
551 };
552 
553 // Mutex structure
554 //
555 struct _GLFWmutex
556 {
557     // This is defined in the platform's thread.h
558     _GLFW_PLATFORM_MUTEX_STATE;
559 };
560 
561 // Library global data
562 //
563 struct _GLFWlibrary
564 {
565     bool                initialized;
566 
567     struct {
568         _GLFWinitconfig init;
569         _GLFWfbconfig   framebuffer;
570         _GLFWwndconfig  window;
571         _GLFWctxconfig  context;
572         int             refreshRate;
573     } hints;
574 
575     _GLFWerror*         errorListHead;
576     _GLFWcursor*        cursorListHead;
577     _GLFWwindow*        windowListHead;
578     GLFWid              focusedWindowId;
579 
580     _GLFWmonitor**      monitors;
581     int                 monitorCount;
582 
583     bool                joysticksInitialized;
584     _GLFWjoystick       joysticks[GLFW_JOYSTICK_LAST + 1];
585     _GLFWmapping*       mappings;
586     int                 mappingCount;
587 
588     _GLFWtls            errorSlot;
589     _GLFWtls            contextSlot;
590     _GLFWmutex          errorLock;
591 
592     struct {
593         bool            available;
594         void*           handle;
595         char*           extensions[2];
596 #if !defined(_GLFW_VULKAN_STATIC)
597         PFN_vkEnumerateInstanceExtensionProperties EnumerateInstanceExtensionProperties;
598         PFN_vkGetInstanceProcAddr GetInstanceProcAddr;
599 #endif
600         bool            KHR_surface;
601 #if defined(_GLFW_WIN32)
602         bool            KHR_win32_surface;
603 #elif defined(_GLFW_COCOA)
604         bool            MVK_macos_surface;
605         bool            EXT_metal_surface;
606 #elif defined(_GLFW_X11)
607         bool            KHR_xlib_surface;
608         bool            KHR_xcb_surface;
609 #elif defined(_GLFW_WAYLAND)
610         bool            KHR_wayland_surface;
611 #endif
612     } vk;
613 
614     struct {
615         GLFWmonitorfun  monitor;
616         GLFWjoystickfun joystick;
617         GLFWapplicationclosefun application_close;
618         GLFWdrawtextfun draw_text;
619     } callbacks;
620 
621 
622     // This is defined in the window API's platform.h
623     _GLFW_PLATFORM_LIBRARY_WINDOW_STATE;
624     // This is defined in the context API's context.h
625     _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE
626     // This is defined in the platform's joystick.h
627     _GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE
628     // This is defined in egl_context.h
629     _GLFWlibraryEGL egl;
630     // This is defined in osmesa_context.h
631     _GLFWlibraryOSMesa osmesa;
632 };
633 
634 // Global state shared between compilation units of GLFW
635 //
636 extern _GLFWlibrary _glfw;
637 
638 
639 //////////////////////////////////////////////////////////////////////////
640 //////                       GLFW platform API                      //////
641 //////////////////////////////////////////////////////////////////////////
642 
643 int _glfwPlatformInit(void);
644 void _glfwPlatformTerminate(void);
645 const char* _glfwPlatformGetVersionString(void);
646 
647 void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos);
648 void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos);
649 void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
650 void _glfwPlatformSetRawMouseMotion(_GLFWwindow *window, bool enabled);
651 bool _glfwPlatformRawMouseMotionSupported(void);
652 int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
653                               const GLFWimage* image, int xhot, int yhot, int count);
654 int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, GLFWCursorShape shape);
655 void _glfwPlatformDestroyCursor(_GLFWcursor* cursor);
656 void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor);
657 
658 const char* _glfwPlatformGetNativeKeyName(int native_key);
659 int _glfwPlatformGetNativeKeyForKey(uint32_t key);
660 
661 void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor);
662 void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos);
663 void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor,
664                                          float* xscale, float* yscale);
665 void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor, int* xpos, int* ypos, int *width, int *height);
666 GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count);
667 void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode);
668 bool _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp);
669 void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp);
670 
671 void _glfwPlatformSetClipboardString(const char* string);
672 const char* _glfwPlatformGetClipboardString(void);
673 #if defined(_GLFW_X11) || defined(_GLFW_WAYLAND)
674 void _glfwPlatformSetPrimarySelectionString(const char* string);
675 const char* _glfwPlatformGetPrimarySelectionString(void);
676 #endif
677 
678 bool _glfwPlatformInitJoysticks(void);
679 void _glfwPlatformTerminateJoysticks(void);
680 int _glfwPlatformPollJoystick(_GLFWjoystick* js, int mode);
681 void _glfwPlatformUpdateGamepadGUID(char* guid);
682 
683 int _glfwPlatformCreateWindow(_GLFWwindow* window,
684                               const _GLFWwndconfig* wndconfig,
685                               const _GLFWctxconfig* ctxconfig,
686                               const _GLFWfbconfig* fbconfig);
687 void _glfwPlatformDestroyWindow(_GLFWwindow* window);
688 void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
689 void _glfwPlatformSetWindowIcon(_GLFWwindow* window,
690                                 int count, const GLFWimage* images);
691 void _glfwPlatformGetWindowPos(_GLFWwindow* window, int* xpos, int* ypos);
692 void _glfwPlatformSetWindowPos(_GLFWwindow* window, int xpos, int ypos);
693 void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height);
694 void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);
695 void _glfwPlatformSetWindowSizeLimits(_GLFWwindow* window,
696                                       int minwidth, int minheight,
697                                       int maxwidth, int maxheight);
698 void _glfwPlatformSetWindowAspectRatio(_GLFWwindow* window, int numer, int denom);
699 void _glfwPlatformSetWindowSizeIncrements(_GLFWwindow* window, int widthincr, int heightincr);
700 void _glfwPlatformGetFramebufferSize(_GLFWwindow* window, int* width, int* height);
701 void _glfwInputLiveResize(_GLFWwindow* window, bool started);
702 void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window,
703                                      int* left, int* top,
704                                      int* right, int* bottom);
705 void _glfwPlatformGetWindowContentScale(_GLFWwindow* window,
706                                         float* xscale, float* yscale);
707 monotonic_t _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window);
708 void _glfwPlatformIconifyWindow(_GLFWwindow* window);
709 void _glfwPlatformRestoreWindow(_GLFWwindow* window);
710 void _glfwPlatformMaximizeWindow(_GLFWwindow* window);
711 void _glfwPlatformShowWindow(_GLFWwindow* window);
712 void _glfwPlatformHideWindow(_GLFWwindow* window);
713 void _glfwPlatformRequestWindowAttention(_GLFWwindow* window);
714 int _glfwPlatformWindowBell(_GLFWwindow* window);
715 void _glfwPlatformFocusWindow(_GLFWwindow* window);
716 void _glfwPlatformSetWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor,
717                                    int xpos, int ypos, int width, int height,
718                                    int refreshRate);
719 bool _glfwPlatformToggleFullscreen(_GLFWwindow *w, unsigned int flags);
720 int _glfwPlatformWindowFocused(_GLFWwindow* window);
721 int _glfwPlatformWindowOccluded(_GLFWwindow* window);
722 int _glfwPlatformWindowIconified(_GLFWwindow* window);
723 int _glfwPlatformWindowVisible(_GLFWwindow* window);
724 int _glfwPlatformWindowMaximized(_GLFWwindow* window);
725 int _glfwPlatformWindowHovered(_GLFWwindow* window);
726 int _glfwPlatformFramebufferTransparent(_GLFWwindow* window);
727 float _glfwPlatformGetWindowOpacity(_GLFWwindow* window);
728 void _glfwPlatformSetWindowResizable(_GLFWwindow* window, bool enabled);
729 void _glfwPlatformSetWindowDecorated(_GLFWwindow* window, bool enabled);
730 void _glfwPlatformSetWindowFloating(_GLFWwindow* window, bool enabled);
731 void _glfwPlatformSetWindowMousePassthrough(_GLFWwindow* window, bool enabled);
732 void _glfwPlatformSetWindowOpacity(_GLFWwindow* window, float opacity);
733 void _glfwPlatformUpdateIMEState(_GLFWwindow *w, const GLFWIMEUpdateEvent *ev);
734 void _glfwPlatformChangeCursorTheme(void);
735 
736 void _glfwPlatformPollEvents(void);
737 void _glfwPlatformWaitEvents(void);
738 void _glfwPlatformWaitEventsTimeout(monotonic_t timeout);
739 void _glfwPlatformPostEmptyEvent(void);
740 
741 EGLenum _glfwPlatformGetEGLPlatform(EGLint** attribs);
742 EGLNativeDisplayType _glfwPlatformGetEGLNativeDisplay(void);
743 EGLNativeWindowType _glfwPlatformGetEGLNativeWindow(_GLFWwindow* window);
744 
745 void _glfwPlatformGetRequiredInstanceExtensions(char** extensions);
746 int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
747                                                       VkPhysicalDevice device,
748                                                       uint32_t queuefamily);
749 VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
750                                           _GLFWwindow* window,
751                                           const VkAllocationCallbacks* allocator,
752                                           VkSurfaceKHR* surface);
753 
754 bool _glfwPlatformCreateTls(_GLFWtls* tls);
755 void _glfwPlatformDestroyTls(_GLFWtls* tls);
756 void* _glfwPlatformGetTls(_GLFWtls* tls);
757 void _glfwPlatformSetTls(_GLFWtls* tls, void* value);
758 
759 bool _glfwPlatformCreateMutex(_GLFWmutex* mutex);
760 void _glfwPlatformDestroyMutex(_GLFWmutex* mutex);
761 void _glfwPlatformLockMutex(_GLFWmutex* mutex);
762 void _glfwPlatformUnlockMutex(_GLFWmutex* mutex);
763 
764 
765 //////////////////////////////////////////////////////////////////////////
766 //////                         GLFW event API                       //////
767 //////////////////////////////////////////////////////////////////////////
768 
769 void _glfwInputWindowFocus(_GLFWwindow* window, bool focused);
770 void _glfwInputWindowOcclusion(_GLFWwindow* window, bool occluded);
771 void _glfwInputWindowPos(_GLFWwindow* window, int xpos, int ypos);
772 void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
773 void _glfwInputFramebufferSize(_GLFWwindow* window, int width, int height);
774 void _glfwInputWindowContentScale(_GLFWwindow* window,
775                                   float xscale, float yscale);
776 void _glfwInputWindowIconify(_GLFWwindow* window, bool iconified);
777 void _glfwInputWindowMaximize(_GLFWwindow* window, bool maximized);
778 void _glfwInputWindowDamage(_GLFWwindow* window);
779 void _glfwInputWindowCloseRequest(_GLFWwindow* window);
780 void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor);
781 
782 void _glfwInputKeyboard(_GLFWwindow *window, GLFWkeyevent *ev);
783 void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset, int flags, int mods);
784 void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods);
785 void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos);
786 void _glfwInputCursorEnter(_GLFWwindow* window, bool entered);
787 int _glfwInputDrop(_GLFWwindow* window, const char *mime, const char *text, size_t sz);
788 void _glfwInputJoystick(_GLFWjoystick* js, int event);
789 void _glfwInputJoystickAxis(_GLFWjoystick* js, int axis, float value);
790 void _glfwInputJoystickButton(_GLFWjoystick* js, int button, char value);
791 void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value);
792 
793 void _glfwInputMonitor(_GLFWmonitor* monitor, int action, int placement);
794 void _glfwInputMonitorWindow(_GLFWmonitor* monitor, _GLFWwindow* window);
795 
796 #if defined(__GNUC__) || defined(__clang__)
797 void _glfwInputError(int code, const char* format, ...)
798     __attribute__((format(printf, 2, 3)));
799 void _glfwDebug(const char* format, ...)
800     __attribute__((format(printf, 1, 2)));
801 #else
802 void _glfwInputError(int code, const char* format, ...);
803 void _glfwDebug(const char* format, ...);
804 #endif
805 
806 #ifdef DEBUG_EVENT_LOOP
807 #define EVDBG(...) _glfwDebug(__VA_ARGS__)
808 #else
809 #define EVDBG(...)
810 #endif
811 
812 //////////////////////////////////////////////////////////////////////////
813 //////                       GLFW internal API                      //////
814 //////////////////////////////////////////////////////////////////////////
815 
816 bool _glfwStringInExtensionString(const char* string, const char* extensions);
817 bool _glfwRefreshContextAttribs(_GLFWwindow* window,
818                                     const _GLFWctxconfig* ctxconfig);
819 bool _glfwIsValidContextConfig(const _GLFWctxconfig* ctxconfig);
820 
821 const GLFWvidmode* _glfwChooseVideoMode(_GLFWmonitor* monitor,
822                                         const GLFWvidmode* desired);
823 int _glfwCompareVideoModes(const GLFWvidmode* first, const GLFWvidmode* second);
824 _GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM);
825 void _glfwFreeMonitor(_GLFWmonitor* monitor);
826 void _glfwAllocGammaArrays(GLFWgammaramp* ramp, unsigned int size);
827 void _glfwFreeGammaArrays(GLFWgammaramp* ramp);
828 void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
829 
830 _GLFWjoystick* _glfwAllocJoystick(const char* name,
831                                   const char* guid,
832                                   int axisCount,
833                                   int buttonCount,
834                                   int hatCount);
835 void _glfwFreeJoystick(_GLFWjoystick* js);
836 const char* _glfwGetKeyName(int key);
837 void _glfwCenterCursorInContentArea(_GLFWwindow* window);
838 
839 bool _glfwInitVulkan(int mode);
840 void _glfwTerminateVulkan(void);
841 const char* _glfwGetVulkanResultString(VkResult result);
842 _GLFWwindow* _glfwFocusedWindow(void);
843 _GLFWwindow* _glfwWindowForId(GLFWid id);
844 void _glfwPlatformRunMainLoop(GLFWtickcallback, void*);
845 void _glfwPlatformStopMainLoop(void);
846 unsigned long long _glfwPlatformAddTimer(monotonic_t interval, bool repeats, GLFWuserdatafun callback, void *callback_data, GLFWuserdatafun free_callback);
847 void _glfwPlatformUpdateTimer(unsigned long long timer_id, monotonic_t interval, bool enabled);
848 void _glfwPlatformRemoveTimer(unsigned long long timer_id);
849 
850 char* _glfw_strdup(const char* source);
851