cocoa_platform.h 5.22 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
28
#ifndef _glfw3_cocoa_platform_h_
#define _glfw3_cocoa_platform_h_
Camilla Berglund's avatar
Camilla Berglund committed
29

30
#include <stdint.h>
Camilla Berglund's avatar
Camilla Berglund committed
31
#include <dlfcn.h>
32

Camilla Berglund's avatar
Camilla Berglund committed
33
#if defined(__OBJC__)
Camilla Berglund's avatar
Camilla Berglund committed
34
#import <Carbon/Carbon.h>
Camilla Berglund's avatar
Camilla Berglund committed
35
36
#import <Cocoa/Cocoa.h>
#else
Camilla Berglund's avatar
Camilla Berglund committed
37
#include <Carbon/Carbon.h>
38
#include <ApplicationServices/ApplicationServices.h>
39
typedef void* id;
Camilla Berglund's avatar
Camilla Berglund committed
40
41
#endif

42
43
44
45
46
47
48
49
50
51
52
53
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*);

54
#include "posix_tls.h"
55
#include "cocoa_joystick.h"
56
#include "nsgl_context.h"
Camilla Berglund's avatar
Camilla Berglund committed
57

Camilla Berglund's avatar
Camilla Berglund committed
58
59
60
61
#define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL)
#define _glfw_dlclose(handle) dlclose(handle)
#define _glfw_dlsym(handle, name) dlsym(handle, name)

62
63
#define _GLFW_PLATFORM_WINDOW_STATE         _GLFWwindowNS  ns
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns
64
#define _GLFW_PLATFORM_LIBRARY_TIME_STATE   _GLFWtimeNS    ns_time
65
#define _GLFW_PLATFORM_MONITOR_STATE        _GLFWmonitorNS ns
66
#define _GLFW_PLATFORM_CURSOR_STATE         _GLFWcursorNS  ns
67

68
69
70
#define _GLFW_EGL_CONTEXT_STATE
#define _GLFW_EGL_LIBRARY_CONTEXT_STATE

71
72
73
74
75
76
77
78
79
// 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

80

Camilla Berglund's avatar
Camilla Berglund committed
81
82
// Cocoa-specific per-window data
//
83
84
typedef struct _GLFWwindowNS
{
Camilla Berglund's avatar
Camilla Berglund committed
85
    id              object;
Camilla Berglund's avatar
Camilla Berglund committed
86
    id              delegate;
Camilla Berglund's avatar
Camilla Berglund committed
87
    id              view;
88
    id              layer;
Camilla Berglund's avatar
Camilla Berglund committed
89

90
91
    GLFWbool        maximized;

92
93
94
    // 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
95
    double          cursorWarpDeltaX, cursorWarpDeltaY;
96

97
} _GLFWwindowNS;
Camilla Berglund's avatar
Camilla Berglund committed
98

Camilla Berglund's avatar
Camilla Berglund committed
99
100
// Cocoa-specific global data
//
101
102
typedef struct _GLFWlibraryNS
{
Camilla Berglund's avatar
Camilla Berglund committed
103
104
105
106
107
    CGEventSourceRef    eventSource;
    id                  delegate;
    id                  autoreleasePool;
    id                  cursor;
    TISInputSourceRef   inputSource;
108
    IOHIDManagerRef     hidManager;
Camilla Berglund's avatar
Camilla Berglund committed
109
    id                  unicodeData;
110
    id                  listener;
Camilla Berglund's avatar
Camilla Berglund committed
111
112

    char                keyName[64];
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
113
114
    short int           keycodes[256];
    short int           scancodes[GLFW_KEY_LAST + 1];
Camilla Berglund's avatar
Camilla Berglund committed
115
    char*               clipboardString;
116
    CGPoint             cascadePoint;
117
118
    // Where to place the cursor when re-enabled
    double              restoreCursorPosX, restoreCursorPosY;
119
120
    // The window whose disabled cursor mode is active
    _GLFWwindow*        disabledCursorWindow;
121

122
123
124
125
126
127
128
129
    struct {
        CFBundleRef     bundle;
        PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource;
        PFN_TISGetInputSourceProperty GetInputSourceProperty;
        PFN_LMGetKbdType GetKbdType;
        CFStringRef     kPropertyUnicodeKeyLayoutData;
    } tis;

130
} _GLFWlibraryNS;
Camilla Berglund's avatar
Camilla Berglund committed
131

Camilla Berglund's avatar
Camilla Berglund committed
132
133
// Cocoa-specific per-monitor data
//
134
135
typedef struct _GLFWmonitorNS
{
136
137
    CGDirectDisplayID   displayID;
    CGDisplayModeRef    previousMode;
138
    uint32_t            unitNumber;
139
140
141

} _GLFWmonitorNS;

Camilla Berglund's avatar
Camilla Berglund committed
142
143
// Cocoa-specific per-cursor data
//
144
145
typedef struct _GLFWcursorNS
{
Camilla Berglund's avatar
Camilla Berglund committed
146
147
    id              object;

148
149
} _GLFWcursorNS;

Camilla Berglund's avatar
Camilla Berglund committed
150
151
// Cocoa-specific global timer data
//
152
153
typedef struct _GLFWtimeNS
{
154
    uint64_t        frequency;
155

Camilla Berglund's avatar
Camilla Berglund committed
156
} _GLFWtimeNS;
157

158

159
void _glfwInitTimerNS(void);
160

161
void _glfwPollMonitorsNS(void);
162
163
GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor);
164

165
#endif // _glfw3_cocoa_platform_h_