• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //========================================================================
2 // GLFW 3.2 OS X - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2009-2016 Camilla Berglund <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 #ifndef _glfw3_cocoa_platform_h_
28 #define _glfw3_cocoa_platform_h_
29 
30 #include <stdint.h>
31 #include <dlfcn.h>
32 
33 #if defined(__OBJC__)
34 #import <Carbon/Carbon.h>
35 #import <Cocoa/Cocoa.h>
36 #else
37 #include <Carbon/Carbon.h>
38 #include <ApplicationServices/ApplicationServices.h>
39 typedef void* id;
40 #endif
41 
42 #include "posix_tls.h"
43 #include "cocoa_joystick.h"
44 #include "nsgl_context.h"
45 
46 #define _glfw_dlopen(name) dlopen(name, RTLD_LAZY | RTLD_LOCAL)
47 #define _glfw_dlclose(handle) dlclose(handle)
48 #define _glfw_dlsym(handle, name) dlsym(handle, name)
49 
50 #define _GLFW_PLATFORM_WINDOW_STATE         _GLFWwindowNS  ns
51 #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 #define _GLFW_EGL_CONTEXT_STATE
57 #define _GLFW_EGL_LIBRARY_CONTEXT_STATE
58 
59 // HIToolbox.framework pointer typedefs
60 #define kTISPropertyUnicodeKeyLayoutData _glfw.ns.tis.kPropertyUnicodeKeyLayoutData
61 #define kTISNotifySelectedKeyboardInputSourceChanged _glfw.ns.tis.kNotifySelectedKeyboardInputSourceChanged
62 typedef TISInputSourceRef (*PFN_TISCopyCurrentKeyboardLayoutInputSource)(void);
63 #define TISCopyCurrentKeyboardLayoutInputSource _glfw.ns.tis.CopyCurrentKeyboardLayoutInputSource
64 typedef void* (*PFN_TISGetInputSourceProperty)(TISInputSourceRef,CFStringRef);
65 #define TISGetInputSourceProperty _glfw.ns.tis.GetInputSourceProperty
66 typedef UInt8 (*PFN_LMGetKbdType)(void);
67 #define LMGetKbdType _glfw.ns.tis.GetKbdType
68 
69 
70 // Cocoa-specific per-window data
71 //
72 typedef struct _GLFWwindowNS
73 {
74     id              object;
75     id              delegate;
76     id              view;
77 
78     // The total sum of the distances the cursor has been warped
79     // since the last cursor motion event was processed
80     // This is kept to counteract Cocoa doing the same internally
81     double          cursorWarpDeltaX, cursorWarpDeltaY;
82 
83 } _GLFWwindowNS;
84 
85 // Cocoa-specific global data
86 //
87 typedef struct _GLFWlibraryNS
88 {
89     CGEventSourceRef    eventSource;
90     id                  delegate;
91     id                  autoreleasePool;
92     id                  cursor;
93     TISInputSourceRef   inputSource;
94     IOHIDManagerRef     hidManager;
95     id                  unicodeData;
96     id                  listener;
97 
98     char                keyName[64];
99     short int           publicKeys[256];
100     short int           nativeKeys[GLFW_KEY_LAST + 1];
101     char*               clipboardString;
102     // Where to place the cursor when re-enabled
103     double              restoreCursorPosX, restoreCursorPosY;
104     // The window whose disabled cursor mode is active
105     _GLFWwindow*        disabledCursorWindow;
106 
107     struct {
108         CFBundleRef     bundle;
109         PFN_TISCopyCurrentKeyboardLayoutInputSource CopyCurrentKeyboardLayoutInputSource;
110         PFN_TISGetInputSourceProperty GetInputSourceProperty;
111         PFN_LMGetKbdType GetKbdType;
112         CFStringRef     kPropertyUnicodeKeyLayoutData;
113         CFStringRef     kNotifySelectedKeyboardInputSourceChanged;
114     } tis;
115 
116 } _GLFWlibraryNS;
117 
118 // Cocoa-specific per-monitor data
119 //
120 typedef struct _GLFWmonitorNS
121 {
122     CGDirectDisplayID   displayID;
123     CGDisplayModeRef    previousMode;
124     uint32_t            unitNumber;
125 
126 } _GLFWmonitorNS;
127 
128 // Cocoa-specific per-cursor data
129 //
130 typedef struct _GLFWcursorNS
131 {
132     id              object;
133 
134 } _GLFWcursorNS;
135 
136 // Cocoa-specific global timer data
137 //
138 typedef struct _GLFWtimeNS
139 {
140     uint64_t        frequency;
141 
142 } _GLFWtimeNS;
143 
144 
145 void _glfwInitTimerNS(void);
146 
147 GLFWbool _glfwSetVideoModeNS(_GLFWmonitor* monitor, const GLFWvidmode* desired);
148 void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor);
149 
150 #endif // _glfw3_cocoa_platform_h_
151