1 //========================================================================
2 // GLFW 3.4 macOS - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2009-2019 Camilla Löwy <elmindreda@glfw.org>
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.
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:
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.
19 // 2. Altered source versions must be plainly marked as such, and must not
20 // be misrepresented as being the original software.
22 // 3. This notice may not be removed or altered from any source
25 //========================================================================
30 #include <Carbon/Carbon.h>
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
37 #import <Cocoa/Cocoa.h>
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
63 typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;
64 typedef VkFlags VkMetalSurfaceCreateFlagsEXT;
66 typedef struct VkMacOSSurfaceCreateInfoMVK
68 VkStructureType sType;
70 VkMacOSSurfaceCreateFlagsMVK flags;
72 } VkMacOSSurfaceCreateInfoMVK;
74 typedef struct VkMetalSurfaceCreateInfoEXT
76 VkStructureType sType;
78 VkMetalSurfaceCreateFlagsEXT flags;
80 } VkMetalSurfaceCreateInfoEXT;
82 typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacOSSurfaceCreateInfoMVK*,const VkAllocationCallbacks*,VkSurfaceKHR*);
83 typedef VkResult (APIENTRY *PFN_vkCreateMetalSurfaceEXT)(VkInstance,const VkMetalSurfaceCreateInfoEXT*,const VkAllocationCallbacks*,VkSurfaceKHR*);
85 #include "posix_thread.h"
86 #include "cocoa_joystick.h"
87 #include "nsgl_context.h"
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)
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
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
109 // Cocoa-specific per-window data
111 typedef struct _GLFWwindowNS
122 // Cached window properties to filter out duplicate events
124 int fbWidth, fbHeight;
125 float xscale, yscale;
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;
134 // Cocoa-specific global data
136 typedef struct _GLFWlibraryNS
138 CGEventSourceRef eventSource;
140 GLFWbool cursorHidden;
141 TISInputSourceRef inputSource;
142 IOHIDManagerRef hidManager;
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;
160 PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource;
161 PFN_TISGetInputSourceProperty GetInputSourceProperty;
162 PFN_LMGetKbdType GetKbdType;
163 CFStringRef kPropertyUnicodeKeyLayoutData;
168 // Cocoa-specific per-monitor data
170 typedef struct _GLFWmonitorNS
172 CGDirectDisplayID displayID;
173 CGDisplayModeRef previousMode;
176 double fallbackRefreshRate;
180 // Cocoa-specific per-cursor data
182 typedef struct _GLFWcursorNS
188 // Cocoa-specific global timer data
190 typedef struct _GLFWtimerNS
197 void _glfwInitTimerNS(void);
199 void _glfwPollMonitorsNS(void);
200 void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired);
201 void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor);
203 float _glfwTransformYNS(float y);
205 void* _glfwLoadLocalVulkanLoaderNS(void);