cocoa_platform.h 5.67 KB
Newer Older
Camilla Berglund's avatar
Camilla Berglund committed
1
//========================================================================
2
// GLFW 3.3 macOS - www.glfw.org
Camilla Berglund's avatar
Camilla Berglund committed
3
//------------------------------------------------------------------------
Camilla Löwy's avatar
Camilla Löwy committed
4
// Copyright (c) 2009-2016 Camilla Löwy <elmindreda@glfw.org>
Camilla Berglund's avatar
Camilla Berglund committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
//    claim that you wrote the original software. If you use this software
//    in a product, an acknowledgment in the product documentation would
//    be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
//    be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
//    distribution.
//
//========================================================================

27
#include <stdint.h>
Camilla Berglund's avatar
Camilla Berglund committed
28
#include <dlfcn.h>
29

Camilla Löwy's avatar
Camilla Löwy committed
30
#include <Carbon/Carbon.h>
31
32
33
#include <CoreVideo/CVBase.h>
#include <CoreVideo/CVDisplayLink.h>

34
35
36
37
// NOTE: All of NSGL was deprecated in the 10.14 SDK
//       This disables the pointless warnings for every symbol we use
#define GL_SILENCE_DEPRECATION

Camilla Berglund's avatar
Camilla Berglund committed
38
39
40
#if defined(__OBJC__)
#import <Cocoa/Cocoa.h>
#else
41
typedef void* id;
Camilla Berglund's avatar
Camilla Berglund committed
42
43
#endif

44
45
46
47
48
49
50
51
52
53
54
55
typedef VkFlags VkMacOSSurfaceCreateFlagsMVK;

typedef struct VkMacOSSurfaceCreateInfoMVK
{
    VkStructureType                 sType;
    const void*                     pNext;
    VkMacOSSurfaceCreateFlagsMVK    flags;
    const void*                     pView;
} VkMacOSSurfaceCreateInfoMVK;

typedef VkResult (APIENTRY *PFN_vkCreateMacOSSurfaceMVK)(VkInstance,const VkMacOSSurfaceCreateInfoMVK*,const VkAllocationCallbacks*,VkSurfaceKHR*);

Camilla Löwy's avatar
Camilla Löwy committed
56
#include "posix_thread.h"
57
#include "cocoa_joystick.h"
58
#include "nsgl_context.h"
Camilla Löwy's avatar
Camilla Löwy committed
59
#include "egl_context.h"
Camilla Löwy's avatar
Camilla Löwy committed
60
#include "osmesa_context.h"
Camilla Berglund's avatar
Camilla Berglund committed
61

Camilla Berglund's avatar
Camilla Berglund committed
62
63
64
65
#define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL)
#define _glfw_dlclose(handle) dlclose(handle)
#define _glfw_dlsym(handle, name) dlsym(handle, name)

Camilla Löwy's avatar
Camilla Löwy committed
66
67
68
#define _GLFW_EGL_NATIVE_WINDOW  ((EGLNativeWindowType) window->ns.view)
#define _GLFW_EGL_NATIVE_DISPLAY EGL_DEFAULT_DISPLAY

69
70
#define _GLFW_PLATFORM_WINDOW_STATE         _GLFWwindowNS  ns
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
71
#define _GLFW_PLATFORM_LIBRARY_TIMER_STATE  _GLFWtimerNS   ns
72
#define _GLFW_PLATFORM_MONITOR_STATE        _GLFWmonitorNS ns
73
#define _GLFW_PLATFORM_CURSOR_STATE         _GLFWcursorNS  ns
74

75
76
77
78
79
80
81
82
83
// HIToolbox.framework pointer typedefs
#define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData
typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void);
#define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource
typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef);
#define TISGetInputSourceProperty _glfw.ns.tis.GetInputSourceProperty
typedef UInt8 (*PFN_LMGetKbdType)(void);
#define LMGetKbdType _glfw.ns.tis.GetKbdType

84

Camilla Berglund's avatar
Camilla Berglund committed
85
86
// Cocoa-specific per-window data
//
87
88
typedef struct _GLFWwindowNS
{
Camilla Berglund's avatar
Camilla Berglund committed
89
    id              object;
Camilla Berglund's avatar
Camilla Berglund committed
90
    id              delegate;
Camilla Berglund's avatar
Camilla Berglund committed
91
    id              view;
92
    id              layer;
Camilla Berglund's avatar
Camilla Berglund committed
93

94
95
    GLFWbool        maximized;

96
    // Cached window properties to filter out duplicate events
97
98
    int             width, height;
    int             fbWidth, fbHeight;
99
    float           xscale, yscale;
100

101
102
103
    // The total sum of the distances the cursor has been warped
    // since the last cursor motion event was processed
    // This is kept to counteract Cocoa doing the same internally
104
    double          cursorWarpDeltaX, cursorWarpDeltaY;
105

106
} _GLFWwindowNS;
Camilla Berglund's avatar
Camilla Berglund committed
107

Camilla Berglund's avatar
Camilla Berglund committed
108
109
// Cocoa-specific global data
//
110
111
typedef struct _GLFWlibraryNS
{
Camilla Berglund's avatar
Camilla Berglund committed
112
113
    CGEventSourceRef    eventSource;
    id                  delegate;
114
    GLFWbool            finishedLaunching;
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
115
    GLFWbool            cursorHidden;
Camilla Berglund's avatar
Camilla Berglund committed
116
    TISInputSourceRef   inputSource;
117
    IOHIDManagerRef     hidManager;
Camilla Berglund's avatar
Camilla Berglund committed
118
    id                  unicodeData;
119
120
121
    id                  helper;
    id                  keyUpMonitor;
    id                  nibObjects;
Camilla Berglund's avatar
Camilla Berglund committed
122
123

    char                keyName[64];
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
124
125
    short int           keycodes[256];
    short int           scancodes[GLFW_KEY_LAST + 1];
Camilla Berglund's avatar
Camilla Berglund committed
126
    char*               clipboardString;
127
    CGPoint             cascadePoint;
128
129
    // Where to place the cursor when re-enabled
    double              restoreCursorPosX, restoreCursorPosY;
130
131
    // The window whose disabled cursor mode is active
    _GLFWwindow*        disabledCursorWindow;
132

133
134
135
136
137
138
139
140
    struct {
        CFBundleRef     bundle;
        PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource;
        PFN_TISGetInputSourceProperty GetInputSourceProperty;
        PFN_LMGetKbdType GetKbdType;
        CFStringRef     kPropertyUnicodeKeyLayoutData;
    } tis;

141
} _GLFWlibraryNS;
Camilla Berglund's avatar
Camilla Berglund committed
142

Camilla Berglund's avatar
Camilla Berglund committed
143
144
// Cocoa-specific per-monitor data
//
145
146
typedef struct _GLFWmonitorNS
{
147
148
    CGDirectDisplayID   displayID;
    CGDisplayModeRef    previousMode;
149
    uint32_t            unitNumber;
Camilla Löwy's avatar
Camilla Löwy committed
150
    id                  screen;
151
152
153

} _GLFWmonitorNS;

Camilla Berglund's avatar
Camilla Berglund committed
154
155
// Cocoa-specific per-cursor data
//
156
157
typedef struct _GLFWcursorNS
{
Camilla Berglund's avatar
Camilla Berglund committed
158
159
    id              object;

160
161
} _GLFWcursorNS;

Camilla Berglund's avatar
Camilla Berglund committed
162
163
// Cocoa-specific global timer data
//
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
164
typedef struct _GLFWtimerNS
165
{
166
    uint64_t        frequency;
167

Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
168
} _GLFWtimerNS;
169

170

171
void _glfwInitTimerNS(void);
172

173
void _glfwPollMonitorsNS(void);
Camilla Löwy's avatar
Cleanup    
Camilla Löwy committed
174
void _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired);
175
void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor);
176

177
178
float _glfwTransformYNS(float y);