| 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 | |
| 29 | #include <Carbon/Carbon.h> |
| 30 | #include <IOKit/hid/IOHIDLib.h> |
| 31 | |
| 32 | |
| 33 | |
| 34 | #ifndef GL_SILENCE_DEPRECATION |
| 35 | #define GL_SILENCE_DEPRECATION |
| 36 | #endif |
| 37 | |
| 38 | #if defined(__OBJC__) |
| 39 | #import <Cocoa/Cocoa.h> |
| 40 | #else |
| 41 | typedef void* id; |
| 42 | #endif |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 101400 |
| 50 | #define NSOpenGLContextParameterSwapInterval NSOpenGLCPSwapInterval |
| 51 | #define NSOpenGLContextParameterSurfaceOpacity NSOpenGLCPSurfaceOpacity |
| 52 | #endif |
| 53 | |
| 54 | #if MAC_OS_X_VERSION_MAX_ALLOWED < 101200 |
| 55 | #define NSBitmapFormatAlphaNonpremultiplied NSAlphaNonpremultipliedBitmapFormat |
| 56 | #define NSEventMaskAny NSAnyEventMask |
| 57 | #define NSEventMaskKeyUp NSKeyUpMask |
| 58 | #define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask |
| 59 | #define NSEventModifierFlagCommand NSCommandKeyMask |
| 60 | #define NSEventModifierFlagControl NSControlKeyMask |
| 61 | #define NSEventModifierFlagDeviceIndependentFlagsMask NSDeviceIndependentModifierFlagsMask |
| 62 | #define NSEventModifierFlagOption NSAlternateKeyMask |
| 63 | #define NSEventModifierFlagShift NSShiftKeyMask |
| 64 | #define NSEventTypeApplicationDefined NSApplicationDefined |
| 65 | #define NSWindowStyleMaskBorderless NSBorderlessWindowMask |
| 66 | #define NSWindowStyleMaskClosable NSClosableWindowMask |
| 67 | #define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask |
| 68 | #define NSWindowStyleMaskResizable NSResizableWindowMask |
| 69 | #define NSWindowStyleMaskTitled NSTitledWindowMask |
| 70 | #endif |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | #if MAC_OS_X_VERSION_MIN_REQUIRED < 101300 |
| 78 | #define NSPasteboardTypeURL NSURLPboardType |
| 79 | #endif |
| 80 | |
| 81 | typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; |
| 82 | typedef VkFlags VkMetalSurfaceCreateFlagsEXT; |
| 83 | |
| 84 | typedef struct VkMacOSSurfaceCreateInfoMVK |
| 85 | { |
| 86 | VkStructureType sType; |
| 87 | const void* pNext; |
| 88 | VkMacOSSurfaceCreateFlagsMVK flags; |
| 89 | const void* pView; |
| 90 | } VkMacOSSurfaceCreateInfoMVK; |
| 91 | |
| 92 | typedef struct VkMetalSurfaceCreateInfoEXT |
| 93 | { |
| 94 | VkStructureType sType; |
| 95 | const void* pNext; |
| 96 | VkMetalSurfaceCreateFlagsEXT flags; |
| 97 | const void* pLayer; |
| 98 | } VkMetalSurfaceCreateInfoEXT; |
| 99 | |
| 100 | typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacOSSurfaceCreateInfoMVK*,const VkAllocationCallbacks*,VkSurfaceKHR*); |
| 101 | typedef VkResult (APIENTRY *PFN_vkCreateMetalSurfaceEXT)(VkInstance,const VkMetalSurfaceCreateInfoEXT*,const VkAllocationCallbacks*,VkSurfaceKHR*); |
| 102 | |
| 103 | #define GLFW_COCOA_WINDOW_STATE _GLFWwindowNS ns; |
| 104 | #define GLFW_COCOA_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns; |
| 105 | #define GLFW_COCOA_MONITOR_STATE _GLFWmonitorNS ns; |
| 106 | #define GLFW_COCOA_CURSOR_STATE _GLFWcursorNS ns; |
| 107 | |
| 108 | #define GLFW_NSGL_CONTEXT_STATE _GLFWcontextNSGL nsgl; |
| 109 | #define GLFW_NSGL_LIBRARY_CONTEXT_STATE _GLFWlibraryNSGL nsgl; |
| 110 | |
| 111 | |
| 112 | #define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData |
| 113 | typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void); |
| 114 | #define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource |
| 115 | typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef); |
| 116 | #define TISGetInputSourceProperty _glfw.ns.tis.GetInputSourceProperty |
| 117 | typedef UInt8 (*PFN_LMGetKbdType)(void); |
| 118 | #define LMGetKbdType _glfw.ns.tis.GetKbdType |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | typedef struct _GLFWcontextNSGL |
| 124 | { |
| 125 | id pixelFormat; |
| 126 | id object; |
| 127 | } _GLFWcontextNSGL; |
| 128 | |
| 129 | |
| 130 | |
| 131 | typedef struct _GLFWlibraryNSGL |
| 132 | { |
| 133 | |
| 134 | CFBundleRef framework; |
| 135 | } _GLFWlibraryNSGL; |
| 136 | |
| 137 | |
| 138 | |
| 139 | typedef struct _GLFWwindowNS |
| 140 | { |
| 141 | id object; |
| 142 | id delegate; |
| 143 | id view; |
| 144 | id layer; |
| 145 | |
| 146 | GLFWbool maximized; |
| 147 | GLFWbool occluded; |
| 148 | GLFWbool scaleFramebuffer; |
| 149 | |
| 150 | |
| 151 | int width, height; |
| 152 | int fbWidth, fbHeight; |
| 153 | float xscale, yscale; |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | double cursorWarpDeltaX, cursorWarpDeltaY; |
| 159 | } _GLFWwindowNS; |
| 160 | |
| 161 | |
| 162 | |
| 163 | typedef struct _GLFWlibraryNS |
| 164 | { |
| 165 | CGEventSourceRef eventSource; |
| 166 | id delegate; |
| 167 | GLFWbool cursorHidden; |
| 168 | TISInputSourceRef inputSource; |
| 169 | IOHIDManagerRef hidManager; |
| 170 | id unicodeData; |
| 171 | id helper; |
| 172 | id keyUpMonitor; |
| 173 | id nibObjects; |
| 174 | |
| 175 | char keynames[GLFW_KEY_LAST + 1][17]; |
| 176 | short int keycodes[256]; |
| 177 | short int scancodes[GLFW_KEY_LAST + 1]; |
| 178 | char* clipboardString; |
| 179 | CGPoint cascadePoint; |
| 180 | |
| 181 | double restoreCursorPosX, restoreCursorPosY; |
| 182 | |
| 183 | _GLFWwindow* disabledCursorWindow; |
| 184 | |
| 185 | struct { |
| 186 | CFBundleRef bundle; |
| 187 | PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource; |
| 188 | PFN_TISGetInputSourceProperty GetInputSourceProperty; |
| 189 | PFN_LMGetKbdType GetKbdType; |
| 190 | CFStringRef kPropertyUnicodeKeyLayoutData; |
| 191 | } tis; |
| 192 | } _GLFWlibraryNS; |
| 193 | |
| 194 | |
| 195 | |
| 196 | typedef struct _GLFWmonitorNS |
| 197 | { |
| 198 | CGDirectDisplayID displayID; |
| 199 | CGDisplayModeRef previousMode; |
| 200 | uint32_t unitNumber; |
| 201 | id screen; |
| 202 | double fallbackRefreshRate; |
| 203 | } _GLFWmonitorNS; |
| 204 | |
| 205 | |
| 206 | |
| 207 | typedef struct _GLFWcursorNS |
| 208 | { |
| 209 | id object; |
| 210 | } _GLFWcursorNS; |
| 211 | |
| 212 | |
| 213 | GLFWbool _glfwConnectCocoa(int platformID, _GLFWplatform* platform); |
| 214 | int _glfwInitCocoa(void); |
| 215 | void _glfwTerminateCocoa(void); |
| 216 | |
| 217 | GLFWbool _glfwCreateWindowCocoa(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig); |
| 218 | void _glfwDestroyWindowCocoa(_GLFWwindow* window); |
| 219 | void _glfwSetWindowTitleCocoa(_GLFWwindow* window, const char* title); |
| 220 | void _glfwSetWindowIconCocoa(_GLFWwindow* window, int count, const GLFWimage* images); |
| 221 | void _glfwGetWindowPosCocoa(_GLFWwindow* window, int* xpos, int* ypos); |
| 222 | void _glfwSetWindowPosCocoa(_GLFWwindow* window, int xpos, int ypos); |
| 223 | void _glfwGetWindowSizeCocoa(_GLFWwindow* window, int* width, int* height); |
| 224 | void _glfwSetWindowSizeCocoa(_GLFWwindow* window, int width, int height); |
| 225 | void _glfwSetWindowSizeLimitsCocoa(_GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight); |
| 226 | void _glfwSetWindowAspectRatioCocoa(_GLFWwindow* window, int numer, int denom); |
| 227 | void _glfwGetFramebufferSizeCocoa(_GLFWwindow* window, int* width, int* height); |
| 228 | void _glfwGetWindowFrameSizeCocoa(_GLFWwindow* window, int* left, int* top, int* right, int* bottom); |
| 229 | void _glfwGetWindowContentScaleCocoa(_GLFWwindow* window, float* xscale, float* yscale); |
| 230 | void _glfwIconifyWindowCocoa(_GLFWwindow* window); |
| 231 | void _glfwRestoreWindowCocoa(_GLFWwindow* window); |
| 232 | void _glfwMaximizeWindowCocoa(_GLFWwindow* window); |
| 233 | void _glfwShowWindowCocoa(_GLFWwindow* window); |
| 234 | void _glfwHideWindowCocoa(_GLFWwindow* window); |
| 235 | void _glfwRequestWindowAttentionCocoa(_GLFWwindow* window); |
| 236 | void _glfwFocusWindowCocoa(_GLFWwindow* window); |
| 237 | void _glfwSetWindowMonitorCocoa(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); |
| 238 | GLFWbool _glfwWindowFocusedCocoa(_GLFWwindow* window); |
| 239 | GLFWbool _glfwWindowIconifiedCocoa(_GLFWwindow* window); |
| 240 | GLFWbool _glfwWindowVisibleCocoa(_GLFWwindow* window); |
| 241 | GLFWbool _glfwWindowMaximizedCocoa(_GLFWwindow* window); |
| 242 | GLFWbool _glfwWindowHoveredCocoa(_GLFWwindow* window); |
| 243 | GLFWbool _glfwFramebufferTransparentCocoa(_GLFWwindow* window); |
| 244 | void _glfwSetWindowResizableCocoa(_GLFWwindow* window, GLFWbool enabled); |
| 245 | void _glfwSetWindowDecoratedCocoa(_GLFWwindow* window, GLFWbool enabled); |
| 246 | void _glfwSetWindowFloatingCocoa(_GLFWwindow* window, GLFWbool enabled); |
| 247 | float _glfwGetWindowOpacityCocoa(_GLFWwindow* window); |
| 248 | void _glfwSetWindowOpacityCocoa(_GLFWwindow* window, float opacity); |
| 249 | void _glfwSetWindowMousePassthroughCocoa(_GLFWwindow* window, GLFWbool enabled); |
| 250 | |
| 251 | void _glfwSetRawMouseMotionCocoa(_GLFWwindow *window, GLFWbool enabled); |
| 252 | GLFWbool _glfwRawMouseMotionSupportedCocoa(void); |
| 253 | |
| 254 | void _glfwPollEventsCocoa(void); |
| 255 | void _glfwWaitEventsCocoa(void); |
| 256 | void _glfwWaitEventsTimeoutCocoa(double timeout); |
| 257 | void _glfwPostEmptyEventCocoa(void); |
| 258 | |
| 259 | void _glfwGetCursorPosCocoa(_GLFWwindow* window, double* xpos, double* ypos); |
| 260 | void _glfwSetCursorPosCocoa(_GLFWwindow* window, double xpos, double ypos); |
| 261 | void _glfwSetCursorModeCocoa(_GLFWwindow* window, int mode); |
| 262 | const char* _glfwGetScancodeNameCocoa(int scancode); |
| 263 | int _glfwGetKeyScancodeCocoa(int key); |
| 264 | GLFWbool _glfwCreateCursorCocoa(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot); |
| 265 | GLFWbool _glfwCreateStandardCursorCocoa(_GLFWcursor* cursor, int shape); |
| 266 | void _glfwDestroyCursorCocoa(_GLFWcursor* cursor); |
| 267 | void _glfwSetCursorCocoa(_GLFWwindow* window, _GLFWcursor* cursor); |
| 268 | void _glfwSetClipboardStringCocoa(const char* string); |
| 269 | const char* _glfwGetClipboardStringCocoa(void); |
| 270 | |
| 271 | EGLenum _glfwGetEGLPlatformCocoa(EGLint** attribs); |
| 272 | EGLNativeDisplayType _glfwGetEGLNativeDisplayCocoa(void); |
| 273 | EGLNativeWindowType _glfwGetEGLNativeWindowCocoa(_GLFWwindow* window); |
| 274 | |
| 275 | void _glfwGetRequiredInstanceExtensionsCocoa(char** extensions); |
| 276 | GLFWbool _glfwGetPhysicalDevicePresentationSupportCocoa(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); |
| 277 | VkResult _glfwCreateWindowSurfaceCocoa(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); |
| 278 | |
| 279 | void _glfwFreeMonitorCocoa(_GLFWmonitor* monitor); |
| 280 | void _glfwGetMonitorPosCocoa(_GLFWmonitor* monitor, int* xpos, int* ypos); |
| 281 | void _glfwGetMonitorContentScaleCocoa(_GLFWmonitor* monitor, float* xscale, float* yscale); |
| 282 | void _glfwGetMonitorWorkareaCocoa(_GLFWmonitor* monitor, int* xpos, int* ypos, int* width, int* height); |
| 283 | GLFWvidmode* _glfwGetVideoModesCocoa(_GLFWmonitor* monitor, int* count); |
| 284 | GLFWbool _glfwGetVideoModeCocoa(_GLFWmonitor* monitor, GLFWvidmode* mode); |
| 285 | GLFWbool _glfwGetGammaRampCocoa(_GLFWmonitor* monitor, GLFWgammaramp* ramp); |
| 286 | void _glfwSetGammaRampCocoa(_GLFWmonitor* monitor, const GLFWgammaramp* ramp); |
| 287 | |
| 288 | void _glfwPollMonitorsCocoa(void); |
| 289 | void _glfwSetVideoModeCocoa(_GLFWmonitor* monitor, const GLFWvidmode* desired); |
| 290 | void _glfwRestoreVideoModeCocoa(_GLFWmonitor* monitor); |
| 291 | |
| 292 | float _glfwTransformYCocoa(float y); |
| 293 | |
| 294 | void* _glfwLoadLocalVulkanLoaderCocoa(void); |
| 295 | |
| 296 | GLFWbool _glfwInitNSGL(void); |
| 297 | void _glfwTerminateNSGL(void); |
| 298 | GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, |
| 299 | const _GLFWctxconfig* ctxconfig, |
| 300 | const _GLFWfbconfig* fbconfig); |
| 301 | void _glfwDestroyContextNSGL(_GLFWwindow* window); |
| 302 | |