cocoa_platform.h 4.86 KB
Newer Older
Camilla Berglund's avatar
Camilla Berglund committed
1
//========================================================================
Camilla Berglund's avatar
Camilla Berglund committed
2
// GLFW 3.3 OS X - www.glfw.org
Camilla Berglund's avatar
Camilla Berglund committed
3
//------------------------------------------------------------------------
Camilla Berglund's avatar
Camilla Berglund committed
4
// Copyright (c) 2009-2016 Camilla Berglund <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
#include "posix_tls.h"
43
#include "cocoa_joystick.h"
44
#include "nsgl_context.h"
Camilla Berglund's avatar
Camilla Berglund committed
45

Camilla Berglund's avatar
Camilla Berglund committed
46
47
48
49
#define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL)
#define _glfw_dlclose(handle) dlclose(handle)
#define _glfw_dlsym(handle, name) dlsym(handle, name)

50
51
#define _GLFW_PLATFORM_WINDOW_STATE         _GLFWwindowNS  ns
#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS ns
52
#define _GLFW_PLATFORM_LIBRARY_TIME_STATE   _GLFWtimeNS    ns_time
53
#define _GLFW_PLATFORM_MONITOR_STATE        _GLFWmonitorNS ns
54
#define _GLFW_PLATFORM_CURSOR_STATE         _GLFWcursorNS  ns
55

56
57
58
#define _GLFW_EGL_CONTEXT_STATE
#define _GLFW_EGL_LIBRARY_CONTEXT_STATE

59
60
// HIToolbox.framework pointer typedefs
#define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData
61
#define kTISNotifySelectedKeyboardInputSourceChanged _glfw.ns.tis.kNotifySelectedKeyboardInputSourceChanged
62
63
64
65
66
67
68
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

69

Camilla Berglund's avatar
Camilla Berglund committed
70
71
// Cocoa-specific per-window data
//
72
73
typedef struct _GLFWwindowNS
{
Camilla Berglund's avatar
Camilla Berglund committed
74
    id              object;
Camilla Berglund's avatar
Camilla Berglund committed
75
    id              delegate;
Camilla Berglund's avatar
Camilla Berglund committed
76
    id              view;
Camilla Berglund's avatar
Camilla Berglund committed
77

78
79
    GLFWbool        maximized;

80
81
82
    // 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
83
    double          cursorWarpDeltaX, cursorWarpDeltaY;
84

85
} _GLFWwindowNS;
Camilla Berglund's avatar
Camilla Berglund committed
86

Camilla Berglund's avatar
Camilla Berglund committed
87
88
// Cocoa-specific global data
//
89
90
typedef struct _GLFWlibraryNS
{
Camilla Berglund's avatar
Camilla Berglund committed
91
92
93
94
95
    CGEventSourceRef    eventSource;
    id                  delegate;
    id                  autoreleasePool;
    id                  cursor;
    TISInputSourceRef   inputSource;
96
    IOHIDManagerRef     hidManager;
Camilla Berglund's avatar
Camilla Berglund committed
97
    id                  unicodeData;
98
    id                  listener;
Camilla Berglund's avatar
Camilla Berglund committed
99
100

    char                keyName[64];
Camilla Berglund's avatar
Cleanup    
Camilla Berglund committed
101
102
    short int           keycodes[256];
    short int           scancodes[GLFW_KEY_LAST + 1];
Camilla Berglund's avatar
Camilla Berglund committed
103
    char*               clipboardString;
104
105
    // Where to place the cursor when re-enabled
    double              restoreCursorPosX, restoreCursorPosY;
106
107
    // The window whose disabled cursor mode is active
    _GLFWwindow*        disabledCursorWindow;
108

109
110
111
112
113
114
    struct {
        CFBundleRef     bundle;
        PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource;
        PFN_TISGetInputSourceProperty GetInputSourceProperty;
        PFN_LMGetKbdType GetKbdType;
        CFStringRef     kPropertyUnicodeKeyLayoutData;
115
        CFStringRef     kNotifySelectedKeyboardInputSourceChanged;
116
117
    } tis;

118
} _GLFWlibraryNS;
Camilla Berglund's avatar
Camilla Berglund committed
119

Camilla Berglund's avatar
Camilla Berglund committed
120
121
// Cocoa-specific per-monitor data
//
122
123
typedef struct _GLFWmonitorNS
{
124
125
    CGDirectDisplayID   displayID;
    CGDisplayModeRef    previousMode;
126
    uint32_t            unitNumber;
127
128
129

} _GLFWmonitorNS;

Camilla Berglund's avatar
Camilla Berglund committed
130
131
// Cocoa-specific per-cursor data
//
132
133
typedef struct _GLFWcursorNS
{
Camilla Berglund's avatar
Camilla Berglund committed
134
135
    id              object;

136
137
} _GLFWcursorNS;

Camilla Berglund's avatar
Camilla Berglund committed
138
139
// Cocoa-specific global timer data
//
140
141
typedef struct _GLFWtimeNS
{
142
    uint64_t        frequency;
143

Camilla Berglund's avatar
Camilla Berglund committed
144
} _GLFWtimeNS;
145

146

147
void _glfwInitTimerNS(void);
148

149
150
GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired);
void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor);
151

152
#endif // _glfw3_cocoa_platform_h_