| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | #include <stdint.h> |
| 28 | #include <dlfcn.h> |
| 29 | |
| 30 | #include <Carbon/Carbon.h> |
| 31 | |
| 32 | |
| 33 | |
| 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 | |
| 43 | |
| 44 | |
| 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 | #include "egl_context.h" |
| 89 | #include "osmesa_context.h" |
| 90 | |
| 91 | #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL) |
| 92 | #define _glfw_dlclose(handle) dlclose(handle) |
| 93 | #define _glfw_dlsym(handle, name) dlsym(handle, name) |
| 94 | |
| 95 | #define _GLFW_EGL_NATIVE_WINDOW ((EGLNativeWindowType) window->ns.view) |
| 96 | #define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY |
| 97 | |
| 98 | #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS ns |
| 99 | #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns |
| 100 | #define _GLFW_PLATFORM_LIBRARY_TIMER_STATE _GLFWtimerNS ns |
| 101 | #define _GLFW_PLATFORM_MONITOR_STATE _GLFWmonitorNS ns |
| 102 | #define _GLFW_PLATFORM_CURSOR_STATE _GLFWcursorNS ns |
| 103 | |
| 104 | |
| 105 | #define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData |
| 106 | typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void); |
| 107 | #define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource |
| 108 | typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef); |
| 109 | #define TISGetInputSourceProperty _glfw.ns.tis.GetInputSourceProperty |
| 110 | typedef UInt8 (*PFN_LMGetKbdType)(void); |
| 111 | #define LMGetKbdType _glfw.ns.tis.GetKbdType |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | typedef struct _GLFWwindowNS |
| 117 | { |
| 118 | id object; |
| 119 | id delegate; |
| 120 | id view; |
| 121 | id layer; |
| 122 | |
| 123 | GLFWbool maximized; |
| 124 | GLFWbool retina; |
| 125 | |
| 126 | |
| 127 | int width, height; |
| 128 | int fbWidth, fbHeight; |
| 129 | float xscale, yscale; |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | double cursorWarpDeltaX, cursorWarpDeltaY; |
| 135 | |
| 136 | } _GLFWwindowNS; |
| 137 | |
| 138 | |
| 139 | |
| 140 | typedef struct _GLFWlibraryNS |
| 141 | { |
| 142 | CGEventSourceRef eventSource; |
| 143 | id delegate; |
| 144 | GLFWbool finishedLaunching; |
| 145 | GLFWbool cursorHidden; |
| 146 | TISInputSourceRef inputSource; |
| 147 | IOHIDManagerRef hidManager; |
| 148 | id unicodeData; |
| 149 | id helper; |
| 150 | id keyUpMonitor; |
| 151 | id nibObjects; |
| 152 | |
| 153 | char keynames[GLFW_KEY_LAST + 1][17]; |
| 154 | short int keycodes[256]; |
| 155 | short int scancodes[GLFW_KEY_LAST + 1]; |
| 156 | char* clipboardString; |
| 157 | CGPoint cascadePoint; |
| 158 | |
| 159 | double restoreCursorPosX, restoreCursorPosY; |
| 160 | |
| 161 | _GLFWwindow* disabledCursorWindow; |
| 162 | |
| 163 | struct { |
| 164 | CFBundleRef bundle; |
| 165 | PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource; |
| 166 | PFN_TISGetInputSourceProperty GetInputSourceProperty; |
| 167 | PFN_LMGetKbdType GetKbdType; |
| 168 | CFStringRef kPropertyUnicodeKeyLayoutData; |
| 169 | } tis; |
| 170 | |
| 171 | } _GLFWlibraryNS; |
| 172 | |
| 173 | |
| 174 | |
| 175 | typedef struct _GLFWmonitorNS |
| 176 | { |
| 177 | CGDirectDisplayID displayID; |
| 178 | CGDisplayModeRef previousMode; |
| 179 | uint32_t unitNumber; |
| 180 | id screen; |
| 181 | double fallbackRefreshRate; |
| 182 | |
| 183 | } _GLFWmonitorNS; |
| 184 | |
| 185 | |
| 186 | |
| 187 | typedef struct _GLFWcursorNS |
| 188 | { |
| 189 | id object; |
| 190 | |
| 191 | } _GLFWcursorNS; |
| 192 | |
| 193 | |
| 194 | |
| 195 | typedef struct _GLFWtimerNS |
| 196 | { |
| 197 | uint64_t frequency; |
| 198 | |
| 199 | } _GLFWtimerNS; |
| 200 | |
| 201 | |
| 202 | void _glfwInitTimerNS(void); |
| 203 | |
| 204 | void _glfwPollMonitorsNS(void); |
| 205 | void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired); |
| 206 | void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor); |
| 207 | |
| 208 | float _glfwTransformYNS(float y); |
| 209 | |
| 210 | void* _glfwLoadLocalVulkanLoaderNS(void); |
| 211 | |