]> git.sesse.net Git - pistorm/blob - raylib/external/glfw/src/cocoa_platform.h
Update raylib files and Makefile for Pi 4 testing
[pistorm] / raylib / external / glfw / src / cocoa_platform.h
1 //========================================================================
2 // GLFW 3.4 macOS - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2009-2019 Camilla Löwy <elmindreda@glfw.org>
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 //    claim that you wrote the original software. If you use this software
16 //    in a product, an acknowledgment in the product documentation would
17 //    be appreciated but is not required.
18 //
19 // 2. Altered source versions must be plainly marked as such, and must not
20 //    be misrepresented as being the original software.
21 //
22 // 3. This notice may not be removed or altered from any source
23 //    distribution.
24 //
25 //========================================================================
26
27 #include <stdint.h>
28 #include <dlfcn.h>
29
30 #include <Carbon/Carbon.h>
31
32 // NOTE: All of NSGL was deprecated in the 10.14 SDK
33 //       This disables the pointless warnings for every symbol we use
34 #define GL_SILENCE_DEPRECATION
35
36 #if defined(__OBJC__)
37 #import <Cocoa/Cocoa.h>
38 #else
39 typedef void* id;
40 #endif
41
42 // NOTE: Many Cocoa enum values have been renamed and we need to build across
43 //       SDK versions where one is unavailable or the other deprecated
44 //       We use the newer names in code and these macros to handle compatibility
45 #if MAC_OS_X_VERSION_MAX_ALLOWED < 101200
46  #define NSBitmapFormatAlphaNonpremultiplied NSAlphaNonpremultipliedBitmapFormat
47  #define NSEventMaskAny NSAnyEventMask
48  #define NSEventMaskKeyUp NSKeyUpMask
49  #define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask
50  #define NSEventModifierFlagCommand NSCommandKeyMask
51  #define NSEventModifierFlagControl NSControlKeyMask
52  #define NSEventModifierFlagDeviceIndependentFlagsMask NSDeviceIndependentModifierFlagsMask
53  #define NSEventModifierFlagOption NSAlternateKeyMask
54  #define NSEventModifierFlagShift NSShiftKeyMask
55  #define NSEventTypeApplicationDefined NSApplicationDefined
56  #define NSWindowStyleMaskBorderless NSBorderlessWindowMask
57  #define NSWindowStyleMaskClosable NSClosableWindowMask
58  #define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask
59  #define NSWindowStyleMaskResizable NSResizableWindowMask
60  #define NSWindowStyleMaskTitled NSTitledWindowMask
61 #endif
62
63 typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;
64 typedef VkFlags VkMetalSurfaceCreateFlagsEXT;
65
66 typedef struct VkMacOSSurfaceCreateInfoMVK
67 {
68     VkStructureType                 sType;
69     const void*                     pNext;
70     VkMacOSSurfaceCreateFlagsMVK    flags;
71     const void*                     pView;
72 } VkMacOSSurfaceCreateInfoMVK;
73
74 typedef struct VkMetalSurfaceCreateInfoEXT
75 {
76     VkStructureType                 sType;
77     const void*                     pNext;
78     VkMetalSurfaceCreateFlagsEXT    flags;
79     const void*                     pLayer;
80 } VkMetalSurfaceCreateInfoEXT;
81
82 typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacOSSurfaceCreateInfoMVK*,const VkAllocationCallbacks*,VkSurfaceKHR*);
83 typedef VkResult (APIENTRY *PFN_vkCreateMetalSurfaceEXT)(VkInstance,const VkMetalSurfaceCreateInfoEXT*,const VkAllocationCallbacks*,VkSurfaceKHR*);
84
85 #include "posix_thread.h"
86 #include "cocoa_joystick.h"
87 #include "nsgl_context.h"
88
89 #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL)
90 #define _glfw_dlclose(handle) dlclose(handle)
91 #define _glfw_dlsym(handle, name) dlsym(handle, name)
92
93 #define _GLFW_PLATFORM_WINDOW_STATE         _GLFWwindowNS  ns
94 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns
95 #define _GLFW_PLATFORM_LIBRARY_TIMER_STATE  _GLFWtimerNS   ns
96 #define _GLFW_PLATFORM_MONITOR_STATE        _GLFWmonitorNS ns
97 #define _GLFW_PLATFORM_CURSOR_STATE         _GLFWcursorNS  ns
98
99 // HIToolbox.framework pointer typedefs
100 #define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData
101 typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void);
102 #define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource
103 typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef);
104 #define TISGetInputSourceProperty _glfw.ns.tis.GetInputSourceProperty
105 typedef UInt8 (*PFN_LMGetKbdType)(void);
106 #define LMGetKbdType _glfw.ns.tis.GetKbdType
107
108
109 // Cocoa-specific per-window data
110 //
111 typedef struct _GLFWwindowNS
112 {
113     id              object;
114     id              delegate;
115     id              view;
116     id              layer;
117
118     GLFWbool        maximized;
119     GLFWbool        occluded;
120     GLFWbool        retina;
121
122     // Cached window properties to filter out duplicate events
123     int             width, height;
124     int             fbWidth, fbHeight;
125     float           xscale, yscale;
126
127     // The total sum of the distances the cursor has been warped
128     // since the last cursor motion event was processed
129     // This is kept to counteract Cocoa doing the same internally
130     double          cursorWarpDeltaX, cursorWarpDeltaY;
131
132 } _GLFWwindowNS;
133
134 // Cocoa-specific global data
135 //
136 typedef struct _GLFWlibraryNS
137 {
138     CGEventSourceRef    eventSource;
139     id                  delegate;
140     GLFWbool            cursorHidden;
141     TISInputSourceRef   inputSource;
142     IOHIDManagerRef     hidManager;
143     id                  unicodeData;
144     id                  helper;
145     id                  keyUpMonitor;
146     id                  nibObjects;
147
148     char                keynames[GLFW_KEY_LAST + 1][17];
149     short int           keycodes[256];
150     short int           scancodes[GLFW_KEY_LAST + 1];
151     char*               clipboardString;
152     CGPoint             cascadePoint;
153     // Where to place the cursor when re-enabled
154     double              restoreCursorPosX, restoreCursorPosY;
155     // The window whose disabled cursor mode is active
156     _GLFWwindow*        disabledCursorWindow;
157
158     struct {
159         CFBundleRef     bundle;
160         PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource;
161         PFN_TISGetInputSourceProperty GetInputSourceProperty;
162         PFN_LMGetKbdType GetKbdType;
163         CFStringRef     kPropertyUnicodeKeyLayoutData;
164     } tis;
165
166 } _GLFWlibraryNS;
167
168 // Cocoa-specific per-monitor data
169 //
170 typedef struct _GLFWmonitorNS
171 {
172     CGDirectDisplayID   displayID;
173     CGDisplayModeRef    previousMode;
174     uint32_t            unitNumber;
175     id                  screen;
176     double              fallbackRefreshRate;
177
178 } _GLFWmonitorNS;
179
180 // Cocoa-specific per-cursor data
181 //
182 typedef struct _GLFWcursorNS
183 {
184     id              object;
185
186 } _GLFWcursorNS;
187
188 // Cocoa-specific global timer data
189 //
190 typedef struct _GLFWtimerNS
191 {
192     uint64_t        frequency;
193
194 } _GLFWtimerNS;
195
196
197 void _glfwInitTimerNS(void);
198
199 void _glfwPollMonitorsNS(void);
200 void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired);
201 void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor);
202
203 float _glfwTransformYNS(float y);
204
205 void* _glfwLoadLocalVulkanLoaderNS(void);
206