medfall

A super great game engine
Log | Files | Refs

cocoa_platform.h (5346B)


      1 //========================================================================
      2 // GLFW 3.3 macOS - www.glfw.org
      3 //------------------------------------------------------------------------
      4 // Copyright (c) 2009-2016 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 #if defined(__OBJC__)
     31 #import <Carbon/Carbon.h>
     32 #import <Cocoa/Cocoa.h>
     33 #else
     34 #include <Carbon/Carbon.h>
     35 #include <ApplicationServices/ApplicationServices.h>
     36 typedef void* id;
     37 #endif
     38 
     39 typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;
     40 
     41 typedef struct VkMacOSSurfaceCreateInfoMVK
     42 {
     43     VkStructureType                 sType;
     44     const void*                     pNext;
     45     VkMacOSSurfaceCreateFlagsMVK    flags;
     46     const void*                     pView;
     47 } VkMacOSSurfaceCreateInfoMVK;
     48 
     49 typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacOSSurfaceCreateInfoMVK*,const VkAllocationCallbacks*,VkSurfaceKHR*);
     50 
     51 #include "posix_thread.h"
     52 #include "cocoa_joystick.h"
     53 #include "nsgl_context.h"
     54 #include "egl_context.h"
     55 #include "osmesa_context.h"
     56 
     57 #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL)
     58 #define _glfw_dlclose(handle) dlclose(handle)
     59 #define _glfw_dlsym(handle, name) dlsym(handle, name)
     60 
     61 #define _GLFW_EGL_NATIVE_WINDOW  ((EGLNativeWindowType) window->ns.view)
     62 #define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY
     63 
     64 #define _GLFW_PLATFORM_WINDOW_STATE         _GLFWwindowNS  ns
     65 #define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns
     66 #define _GLFW_PLATFORM_LIBRARY_TIMER_STATE  _GLFWtimerNS   ns
     67 #define _GLFW_PLATFORM_MONITOR_STATE        _GLFWmonitorNS ns
     68 #define _GLFW_PLATFORM_CURSOR_STATE         _GLFWcursorNS  ns
     69 
     70 // HIToolbox.framework pointer typedefs
     71 #define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData
     72 typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void);
     73 #define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource
     74 typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef);
     75 #define TISGetInputSourceProperty _glfw.ns.tis.GetInputSourceProperty
     76 typedef UInt8 (*PFN_LMGetKbdType)(void);
     77 #define LMGetKbdType _glfw.ns.tis.GetKbdType
     78 
     79 
     80 // Cocoa-specific per-window data
     81 //
     82 typedef struct _GLFWwindowNS
     83 {
     84     id              object;
     85     id              delegate;
     86     id              view;
     87     id              layer;
     88 
     89     GLFWbool        maximized;
     90 
     91     // The total sum of the distances the cursor has been warped
     92     // since the last cursor motion event was processed
     93     // This is kept to counteract Cocoa doing the same internally
     94     double          cursorWarpDeltaX, cursorWarpDeltaY;
     95 
     96 } _GLFWwindowNS;
     97 
     98 // Cocoa-specific global data
     99 //
    100 typedef struct _GLFWlibraryNS
    101 {
    102     CGEventSourceRef    eventSource;
    103     id                  delegate;
    104     id                  autoreleasePool;
    105     id                  cursor;
    106     TISInputSourceRef   inputSource;
    107     IOHIDManagerRef     hidManager;
    108     id                  unicodeData;
    109     id                  listener;
    110 
    111     char                keyName[64];
    112     short int           keycodes[256];
    113     short int           scancodes[GLFW_KEY_LAST + 1];
    114     char*               clipboardString;
    115     CGPoint             cascadePoint;
    116     // Where to place the cursor when re-enabled
    117     double              restoreCursorPosX, restoreCursorPosY;
    118     // The window whose disabled cursor mode is active
    119     _GLFWwindow*        disabledCursorWindow;
    120 
    121     struct {
    122         CFBundleRef     bundle;
    123         PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource;
    124         PFN_TISGetInputSourceProperty GetInputSourceProperty;
    125         PFN_LMGetKbdType GetKbdType;
    126         CFStringRef     kPropertyUnicodeKeyLayoutData;
    127     } tis;
    128 
    129 } _GLFWlibraryNS;
    130 
    131 // Cocoa-specific per-monitor data
    132 //
    133 typedef struct _GLFWmonitorNS
    134 {
    135     CGDirectDisplayID   displayID;
    136     CGDisplayModeRef    previousMode;
    137     uint32_t            unitNumber;
    138 
    139 } _GLFWmonitorNS;
    140 
    141 // Cocoa-specific per-cursor data
    142 //
    143 typedef struct _GLFWcursorNS
    144 {
    145     id              object;
    146 
    147 } _GLFWcursorNS;
    148 
    149 // Cocoa-specific global timer data
    150 //
    151 typedef struct _GLFWtimerNS
    152 {
    153     uint64_t        frequency;
    154 
    155 } _GLFWtimerNS;
    156 
    157 
    158 void _glfwInitTimerNS(void);
    159 
    160 void _glfwPollMonitorsNS(void);
    161 GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired);
    162 void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor);
    163