twitchapon-anim

Basic Twitchapon Receiver/Visuals
git clone git://bsandro.tech/twitchapon-anim
Log | Files | Refs | README | LICENSE

cocoa_platform.h (7470B)


      1 //========================================================================
      2 // GLFW 3.3 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 #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 // HIToolbox.framework pointer typedefs
    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 // Cocoa-specific per-window data
    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     // Cached window properties to filter out duplicate events
    127     int             width, height;
    128     int             fbWidth, fbHeight;
    129     float           xscale, yscale;
    130 
    131     // The total sum of the distances the cursor has been warped
    132     // since the last cursor motion event was processed
    133     // This is kept to counteract Cocoa doing the same internally
    134     double          cursorWarpDeltaX, cursorWarpDeltaY;
    135 
    136 } _GLFWwindowNS;
    137 
    138 // Cocoa-specific global data
    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     // Where to place the cursor when re-enabled
    159     double              restoreCursorPosX, restoreCursorPosY;
    160     // The window whose disabled cursor mode is active
    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 // Cocoa-specific per-monitor data
    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 // Cocoa-specific per-cursor data
    186 //
    187 typedef struct _GLFWcursorNS
    188 {
    189     id              object;
    190 
    191 } _GLFWcursorNS;
    192 
    193 // Cocoa-specific global timer data
    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