slouken@1933
|
1 |
/*
|
slouken@5535
|
2 |
Simple DirectMedia Layer
|
slouken@9619
|
3 |
Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
|
slouken@1933
|
4 |
|
slouken@5535
|
5 |
This software is provided 'as-is', without any express or implied
|
slouken@5535
|
6 |
warranty. In no event will the authors be held liable for any damages
|
slouken@5535
|
7 |
arising from the use of this software.
|
slouken@1933
|
8 |
|
slouken@5535
|
9 |
Permission is granted to anyone to use this software for any purpose,
|
slouken@5535
|
10 |
including commercial applications, and to alter it and redistribute it
|
slouken@5535
|
11 |
freely, subject to the following restrictions:
|
slouken@1933
|
12 |
|
slouken@5535
|
13 |
1. The origin of this software must not be misrepresented; you must not
|
slouken@5535
|
14 |
claim that you wrote the original software. If you use this software
|
slouken@5535
|
15 |
in a product, an acknowledgment in the product documentation would be
|
slouken@5535
|
16 |
appreciated but is not required.
|
slouken@5535
|
17 |
2. Altered source versions must be plainly marked as such, and must not be
|
slouken@5535
|
18 |
misrepresented as being the original software.
|
slouken@5535
|
19 |
3. This notice may not be removed or altered from any source distribution.
|
slouken@1933
|
20 |
*/
|
icculus@8093
|
21 |
#include "../../SDL_internal.h"
|
slouken@1933
|
22 |
|
slouken@6044
|
23 |
#if SDL_VIDEO_DRIVER_COCOA
|
slouken@6044
|
24 |
|
slouken@8083
|
25 |
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
|
slouken@8083
|
26 |
# error SDL for Mac OS X must be built with a 10.7 SDK or above.
|
slouken@8083
|
27 |
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1070 */
|
slouken@8083
|
28 |
|
slouken@1933
|
29 |
#include "SDL_syswm.h"
|
slouken@5398
|
30 |
#include "SDL_timer.h" /* For SDL_GetTicks() */
|
slouken@7915
|
31 |
#include "SDL_hints.h"
|
slouken@1933
|
32 |
#include "../SDL_sysvideo.h"
|
slouken@1933
|
33 |
#include "../../events/SDL_keyboard_c.h"
|
slouken@1933
|
34 |
#include "../../events/SDL_mouse_c.h"
|
slouken@4673
|
35 |
#include "../../events/SDL_touch_c.h"
|
slouken@1933
|
36 |
#include "../../events/SDL_windowevents_c.h"
|
jorgen@9237
|
37 |
#include "../../events/SDL_dropevents_c.h"
|
slouken@1933
|
38 |
#include "SDL_cocoavideo.h"
|
eligottlieb@4811
|
39 |
#include "SDL_cocoashape.h"
|
gzjjgod@5057
|
40 |
#include "SDL_cocoamouse.h"
|
jorgen@7594
|
41 |
#include "SDL_cocoaopengl.h"
|
icculus@8295
|
42 |
#include "SDL_assert.h"
|
slouken@1933
|
43 |
|
jorgen@8261
|
44 |
/* #define DEBUG_COCOAWINDOW */
|
jorgen@8261
|
45 |
|
jorgen@8261
|
46 |
#ifdef DEBUG_COCOAWINDOW
|
jorgen@8261
|
47 |
#define DLog(fmt, ...) printf("%s: " fmt "\n", __func__, ##__VA_ARGS__)
|
jorgen@8261
|
48 |
#else
|
jorgen@8261
|
49 |
#define DLog(...) do { } while (0)
|
jorgen@8261
|
50 |
#endif
|
jorgen@8261
|
51 |
|
jorgen@8261
|
52 |
|
slouken@8801
|
53 |
#define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
|
slouken@8801
|
54 |
|
slouken@8801
|
55 |
|
jorgen@9237
|
56 |
@interface SDLWindow : NSWindow <NSDraggingDestination>
|
jorgen@8260
|
57 |
/* These are needed for borderless/fullscreen windows */
|
jorgen@8260
|
58 |
- (BOOL)canBecomeKeyWindow;
|
jorgen@8260
|
59 |
- (BOOL)canBecomeMainWindow;
|
jorgen@8260
|
60 |
- (void)sendEvent:(NSEvent *)event;
|
slouken@8809
|
61 |
- (void)doCommandBySelector:(SEL)aSelector;
|
jorgen@9237
|
62 |
|
jorgen@9237
|
63 |
/* Handle drag-and-drop of files onto the SDL window. */
|
jorgen@9237
|
64 |
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
|
jorgen@9237
|
65 |
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
|
jorgen@9237
|
66 |
- (BOOL)wantsPeriodicDraggingUpdates;
|
jorgen@8260
|
67 |
@end
|
jorgen@8260
|
68 |
|
jorgen@8260
|
69 |
@implementation SDLWindow
|
jorgen@9237
|
70 |
|
jorgen@8260
|
71 |
- (BOOL)canBecomeKeyWindow
|
jorgen@8260
|
72 |
{
|
jorgen@8260
|
73 |
return YES;
|
jorgen@8260
|
74 |
}
|
jorgen@8260
|
75 |
|
jorgen@8260
|
76 |
- (BOOL)canBecomeMainWindow
|
jorgen@8260
|
77 |
{
|
jorgen@8260
|
78 |
return YES;
|
jorgen@8260
|
79 |
}
|
jorgen@8260
|
80 |
|
jorgen@8260
|
81 |
- (void)sendEvent:(NSEvent *)event
|
jorgen@8260
|
82 |
{
|
jorgen@8260
|
83 |
[super sendEvent:event];
|
jorgen@8260
|
84 |
|
jorgen@8260
|
85 |
if ([event type] != NSLeftMouseUp) {
|
jorgen@8260
|
86 |
return;
|
jorgen@8260
|
87 |
}
|
jorgen@8260
|
88 |
|
jorgen@8260
|
89 |
id delegate = [self delegate];
|
jorgen@8260
|
90 |
if (![delegate isKindOfClass:[Cocoa_WindowListener class]]) {
|
jorgen@8260
|
91 |
return;
|
jorgen@8260
|
92 |
}
|
jorgen@8260
|
93 |
|
jorgen@8260
|
94 |
if ([delegate isMoving]) {
|
jorgen@8260
|
95 |
[delegate windowDidFinishMoving];
|
jorgen@8260
|
96 |
}
|
jorgen@8260
|
97 |
}
|
slouken@8809
|
98 |
|
slouken@8809
|
99 |
/* We'll respond to selectors by doing nothing so we don't beep.
|
slouken@8809
|
100 |
* The escape key gets converted to a "cancel" selector, etc.
|
slouken@8809
|
101 |
*/
|
slouken@8809
|
102 |
- (void)doCommandBySelector:(SEL)aSelector
|
slouken@8809
|
103 |
{
|
slouken@8809
|
104 |
/*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
|
slouken@8809
|
105 |
}
|
jorgen@9237
|
106 |
|
jorgen@9237
|
107 |
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
|
jorgen@9237
|
108 |
{
|
jorgen@9237
|
109 |
return NSDragOperationGeneric;
|
jorgen@9237
|
110 |
}
|
jorgen@9237
|
111 |
|
jorgen@9237
|
112 |
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
|
jorgen@9237
|
113 |
{
|
jorgen@9237
|
114 |
NSURL *fileURL = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
|
jorgen@9237
|
115 |
NSNumber *isAlias = nil;
|
jorgen@9237
|
116 |
|
jorgen@9237
|
117 |
if (fileURL == nil) {
|
jorgen@9237
|
118 |
return NO;
|
jorgen@9237
|
119 |
}
|
jorgen@9237
|
120 |
|
jorgen@9237
|
121 |
/* Functionality for resolving URL aliases was added with OS X 10.6. */
|
jorgen@9237
|
122 |
if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
|
jorgen@9237
|
123 |
[fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
|
jorgen@9237
|
124 |
}
|
jorgen@9237
|
125 |
|
jorgen@9237
|
126 |
/* If the URL is an alias, resolve it. */
|
jorgen@9237
|
127 |
if ([isAlias boolValue]) {
|
jorgen@9237
|
128 |
NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
|
jorgen@9237
|
129 |
NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
|
jorgen@9237
|
130 |
if (bookmark != nil) {
|
jorgen@9237
|
131 |
NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
|
jorgen@9237
|
132 |
options:opts
|
jorgen@9237
|
133 |
relativeToURL:nil
|
jorgen@9237
|
134 |
bookmarkDataIsStale:nil
|
jorgen@9237
|
135 |
error:nil];
|
jorgen@9237
|
136 |
|
jorgen@9237
|
137 |
if (resolvedURL != nil) {
|
jorgen@9237
|
138 |
fileURL = resolvedURL;
|
jorgen@9237
|
139 |
}
|
jorgen@9237
|
140 |
}
|
jorgen@9237
|
141 |
}
|
jorgen@9237
|
142 |
|
jorgen@9237
|
143 |
return (BOOL) SDL_SendDropFile([[fileURL path] UTF8String]);
|
jorgen@9237
|
144 |
}
|
jorgen@9237
|
145 |
|
jorgen@9237
|
146 |
- (BOOL)wantsPeriodicDraggingUpdates
|
jorgen@9237
|
147 |
{
|
jorgen@9237
|
148 |
return NO;
|
jorgen@9237
|
149 |
}
|
jorgen@9237
|
150 |
|
jorgen@8260
|
151 |
@end
|
jorgen@8260
|
152 |
|
jorgen@8260
|
153 |
|
slouken@5398
|
154 |
static Uint32 s_moveHack;
|
slouken@5398
|
155 |
|
slouken@8801
|
156 |
static void ConvertNSRect(NSScreen *screen, BOOL fullscreen, NSRect *r)
|
slouken@1933
|
157 |
{
|
slouken@9086
|
158 |
r->origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - r->origin.y - r->size.height;
|
slouken@1933
|
159 |
}
|
slouken@1933
|
160 |
|
slouken@7952
|
161 |
static void
|
slouken@7952
|
162 |
ScheduleContextUpdates(SDL_WindowData *data)
|
jorgen@7595
|
163 |
{
|
jorgen@8258
|
164 |
NSOpenGLContext *currentContext = [NSOpenGLContext currentContext];
|
jorgen@7595
|
165 |
NSMutableArray *contexts = data->nscontexts;
|
jorgen@7595
|
166 |
@synchronized (contexts) {
|
jorgen@7595
|
167 |
for (SDLOpenGLContext *context in contexts) {
|
jorgen@8258
|
168 |
if (context == currentContext) {
|
jorgen@8258
|
169 |
[context update];
|
jorgen@8258
|
170 |
} else {
|
jorgen@8258
|
171 |
[context scheduleUpdate];
|
jorgen@8258
|
172 |
}
|
jorgen@7595
|
173 |
}
|
jorgen@7595
|
174 |
}
|
jorgen@7595
|
175 |
}
|
jorgen@7595
|
176 |
|
slouken@7952
|
177 |
static int
|
slouken@7952
|
178 |
GetHintCtrlClickEmulateRightClick()
|
slouken@7915
|
179 |
{
|
slouken@7915
|
180 |
const char *hint = SDL_GetHint( SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK );
|
slouken@7915
|
181 |
return hint != NULL && *hint != '0';
|
slouken@7915
|
182 |
}
|
slouken@7915
|
183 |
|
slouken@7952
|
184 |
static unsigned int
|
slouken@7952
|
185 |
GetWindowStyle(SDL_Window * window)
|
slouken@7952
|
186 |
{
|
slouken@7952
|
187 |
unsigned int style;
|
slouken@7952
|
188 |
|
icculus@8295
|
189 |
if (window->flags & SDL_WINDOW_FULLSCREEN) {
|
slouken@7952
|
190 |
style = NSBorderlessWindowMask;
|
slouken@7952
|
191 |
} else {
|
slouken@7952
|
192 |
if (window->flags & SDL_WINDOW_BORDERLESS) {
|
slouken@7952
|
193 |
style = NSBorderlessWindowMask;
|
slouken@7952
|
194 |
} else {
|
slouken@7952
|
195 |
style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
|
slouken@7952
|
196 |
}
|
slouken@7952
|
197 |
if (window->flags & SDL_WINDOW_RESIZABLE) {
|
slouken@7952
|
198 |
style |= NSResizableWindowMask;
|
slouken@7952
|
199 |
}
|
slouken@7952
|
200 |
}
|
slouken@7952
|
201 |
return style;
|
slouken@7952
|
202 |
}
|
slouken@7952
|
203 |
|
slouken@7990
|
204 |
static SDL_bool
|
slouken@7990
|
205 |
SetWindowStyle(SDL_Window * window, unsigned int style)
|
slouken@7990
|
206 |
{
|
slouken@7990
|
207 |
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
slouken@7990
|
208 |
NSWindow *nswindow = data->nswindow;
|
slouken@7990
|
209 |
|
slouken@7990
|
210 |
if (![nswindow respondsToSelector: @selector(setStyleMask:)]) {
|
slouken@7990
|
211 |
return SDL_FALSE;
|
slouken@7990
|
212 |
}
|
slouken@7990
|
213 |
|
slouken@7990
|
214 |
/* The view responder chain gets messed with during setStyleMask */
|
slouken@7990
|
215 |
if ([[nswindow contentView] nextResponder] == data->listener) {
|
slouken@7990
|
216 |
[[nswindow contentView] setNextResponder:nil];
|
slouken@7990
|
217 |
}
|
slouken@7990
|
218 |
|
slouken@7990
|
219 |
[nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)style];
|
slouken@7990
|
220 |
|
slouken@7990
|
221 |
/* The view responder chain gets messed with during setStyleMask */
|
slouken@7990
|
222 |
if ([[nswindow contentView] nextResponder] != data->listener) {
|
slouken@7990
|
223 |
[[nswindow contentView] setNextResponder:data->listener];
|
slouken@7990
|
224 |
}
|
slouken@7990
|
225 |
|
slouken@7990
|
226 |
return SDL_TRUE;
|
slouken@7990
|
227 |
}
|
slouken@7990
|
228 |
|
slouken@7952
|
229 |
|
slouken@1933
|
230 |
@implementation Cocoa_WindowListener
|
slouken@1933
|
231 |
|
slouken@1933
|
232 |
- (void)listen:(SDL_WindowData *)data
|
slouken@1933
|
233 |
{
|
slouken@1933
|
234 |
NSNotificationCenter *center;
|
slouken@5371
|
235 |
NSWindow *window = data->nswindow;
|
slouken@5371
|
236 |
NSView *view = [window contentView];
|
slouken@1933
|
237 |
|
slouken@1933
|
238 |
_data = data;
|
jorgen@7087
|
239 |
observingVisible = YES;
|
slouken@7740
|
240 |
wasCtrlLeft = NO;
|
jorgen@7087
|
241 |
wasVisible = [window isVisible];
|
slouken@7967
|
242 |
isFullscreenSpace = NO;
|
slouken@7952
|
243 |
inFullscreenTransition = NO;
|
slouken@7963
|
244 |
pendingWindowOperation = PENDING_OPERATION_NONE;
|
jorgen@8260
|
245 |
isMoving = NO;
|
icculus@8931
|
246 |
isDragAreaRunning = NO;
|
slouken@1933
|
247 |
|
slouken@1933
|
248 |
center = [NSNotificationCenter defaultCenter];
|
slouken@1933
|
249 |
|
slouken@5374
|
250 |
if ([window delegate] != nil) {
|
slouken@5374
|
251 |
[center addObserver:self selector:@selector(windowDidExpose:) name:NSWindowDidExposeNotification object:window];
|
slouken@5374
|
252 |
[center addObserver:self selector:@selector(windowDidMove:) name:NSWindowDidMoveNotification object:window];
|
slouken@5374
|
253 |
[center addObserver:self selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:window];
|
slouken@5374
|
254 |
[center addObserver:self selector:@selector(windowDidMiniaturize:) name:NSWindowDidMiniaturizeNotification object:window];
|
slouken@5374
|
255 |
[center addObserver:self selector:@selector(windowDidDeminiaturize:) name:NSWindowDidDeminiaturizeNotification object:window];
|
slouken@5374
|
256 |
[center addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:window];
|
slouken@5374
|
257 |
[center addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:window];
|
slime73@9643
|
258 |
[center addObserver:self selector:@selector(windowDidChangeBackingProperties:) name:NSWindowDidChangeBackingPropertiesNotification object:window];
|
slouken@7952
|
259 |
[center addObserver:self selector:@selector(windowWillEnterFullScreen:) name:NSWindowWillEnterFullScreenNotification object:window];
|
slouken@7952
|
260 |
[center addObserver:self selector:@selector(windowDidEnterFullScreen:) name:NSWindowDidEnterFullScreenNotification object:window];
|
slouken@7952
|
261 |
[center addObserver:self selector:@selector(windowWillExitFullScreen:) name:NSWindowWillExitFullScreenNotification object:window];
|
slouken@7952
|
262 |
[center addObserver:self selector:@selector(windowDidExitFullScreen:) name:NSWindowDidExitFullScreenNotification object:window];
|
slouken@5374
|
263 |
} else {
|
slouken@5374
|
264 |
[window setDelegate:self];
|
slouken@5374
|
265 |
}
|
slouken@1933
|
266 |
|
slouken@7191
|
267 |
/* Haven't found a delegate / notification that triggers when the window is
|
slouken@7191
|
268 |
* ordered out (is not visible any more). You can be ordered out without
|
slouken@7191
|
269 |
* minimizing, so DidMiniaturize doesn't work. (e.g. -[NSWindow orderOut:])
|
slouken@7191
|
270 |
*/
|
jorgen@7084
|
271 |
[window addObserver:self
|
jorgen@7084
|
272 |
forKeyPath:@"visible"
|
jorgen@7084
|
273 |
options:NSKeyValueObservingOptionNew
|
jorgen@7084
|
274 |
context:NULL];
|
jorgen@7084
|
275 |
|
slouken@5371
|
276 |
[window setNextResponder:self];
|
slouken@5371
|
277 |
[window setAcceptsMouseMovedEvents:YES];
|
slouken@5371
|
278 |
|
slouken@5371
|
279 |
[view setNextResponder:self];
|
icculus@6108
|
280 |
|
icculus@6108
|
281 |
if ([view respondsToSelector:@selector(setAcceptsTouchEvents:)]) {
|
icculus@6108
|
282 |
[view setAcceptsTouchEvents:YES];
|
icculus@6108
|
283 |
}
|
slouken@1933
|
284 |
}
|
slouken@1933
|
285 |
|
jorgen@7084
|
286 |
- (void)observeValueForKeyPath:(NSString *)keyPath
|
jorgen@7084
|
287 |
ofObject:(id)object
|
jorgen@7084
|
288 |
change:(NSDictionary *)change
|
jorgen@7084
|
289 |
context:(void *)context
|
jorgen@7084
|
290 |
{
|
jorgen@7087
|
291 |
if (!observingVisible) {
|
jorgen@7087
|
292 |
return;
|
jorgen@7087
|
293 |
}
|
jorgen@7087
|
294 |
|
jorgen@7084
|
295 |
if (object == _data->nswindow && [keyPath isEqualToString:@"visible"]) {
|
jorgen@7084
|
296 |
int newVisibility = [[change objectForKey:@"new"] intValue];
|
jorgen@7084
|
297 |
if (newVisibility) {
|
jorgen@7084
|
298 |
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
|
jorgen@7084
|
299 |
} else {
|
jorgen@7084
|
300 |
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
|
jorgen@7084
|
301 |
}
|
jorgen@7084
|
302 |
}
|
jorgen@7084
|
303 |
}
|
jorgen@7084
|
304 |
|
jorgen@7087
|
305 |
-(void) pauseVisibleObservation
|
jorgen@7087
|
306 |
{
|
jorgen@7087
|
307 |
observingVisible = NO;
|
jorgen@7087
|
308 |
wasVisible = [_data->nswindow isVisible];
|
jorgen@7087
|
309 |
}
|
jorgen@7087
|
310 |
|
jorgen@7087
|
311 |
-(void) resumeVisibleObservation
|
jorgen@7087
|
312 |
{
|
jorgen@7087
|
313 |
BOOL isVisible = [_data->nswindow isVisible];
|
jorgen@7087
|
314 |
observingVisible = YES;
|
jorgen@7087
|
315 |
if (wasVisible != isVisible) {
|
jorgen@7087
|
316 |
if (isVisible) {
|
jorgen@7087
|
317 |
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
|
jorgen@7087
|
318 |
} else {
|
jorgen@7087
|
319 |
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
|
jorgen@7087
|
320 |
}
|
jorgen@7087
|
321 |
|
jorgen@7087
|
322 |
wasVisible = isVisible;
|
jorgen@7087
|
323 |
}
|
jorgen@7087
|
324 |
}
|
jorgen@7087
|
325 |
|
icculus@8284
|
326 |
-(BOOL) setFullscreenSpace:(BOOL) state
|
slouken@7952
|
327 |
{
|
slouken@7961
|
328 |
SDL_Window *window = _data->window;
|
slouken@7961
|
329 |
NSWindow *nswindow = _data->nswindow;
|
icculus@8295
|
330 |
SDL_VideoData *videodata = ((SDL_WindowData *) window->driverdata)->videodata;
|
slouken@7961
|
331 |
|
icculus@8295
|
332 |
if (!videodata->allow_spaces) {
|
icculus@8295
|
333 |
return NO; /* Spaces are forcibly disabled. */
|
icculus@8295
|
334 |
} else if (state && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
|
icculus@8292
|
335 |
return NO; /* we only allow you to make a Space on FULLSCREEN_DESKTOP windows. */
|
slouken@8798
|
336 |
} else if (!state && ((window->last_fullscreen_flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)) {
|
slouken@8798
|
337 |
return NO; /* we only handle leaving the Space on windows that were previously FULLSCREEN_DESKTOP. */
|
icculus@8284
|
338 |
} else if (state == isFullscreenSpace) {
|
icculus@8284
|
339 |
return YES; /* already there. */
|
slouken@7961
|
340 |
}
|
slouken@7961
|
341 |
|
slouken@7961
|
342 |
if (inFullscreenTransition) {
|
slouken@7961
|
343 |
if (state) {
|
slouken@7963
|
344 |
[self addPendingWindowOperation:PENDING_OPERATION_ENTER_FULLSCREEN];
|
slouken@7961
|
345 |
} else {
|
slouken@7963
|
346 |
[self addPendingWindowOperation:PENDING_OPERATION_LEAVE_FULLSCREEN];
|
slouken@7961
|
347 |
}
|
slouken@7961
|
348 |
return YES;
|
slouken@7961
|
349 |
}
|
slouken@7968
|
350 |
inFullscreenTransition = YES;
|
slouken@7968
|
351 |
|
icculus@8295
|
352 |
/* you need to be FullScreenPrimary, or toggleFullScreen doesn't work. Unset it again in windowDidExitFullScreen. */
|
icculus@8284
|
353 |
[nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
slouken@7965
|
354 |
[nswindow performSelectorOnMainThread: @selector(toggleFullScreen:) withObject:nswindow waitUntilDone:NO];
|
slouken@7961
|
355 |
return YES;
|
slouken@7952
|
356 |
}
|
slouken@7952
|
357 |
|
slouken@7968
|
358 |
-(BOOL) isInFullscreenSpace
|
slouken@7968
|
359 |
{
|
slouken@7968
|
360 |
return isFullscreenSpace;
|
slouken@7968
|
361 |
}
|
slouken@7968
|
362 |
|
slouken@7968
|
363 |
-(BOOL) isInFullscreenSpaceTransition
|
slouken@7963
|
364 |
{
|
slouken@7963
|
365 |
return inFullscreenTransition;
|
slouken@7963
|
366 |
}
|
slouken@7963
|
367 |
|
slouken@7963
|
368 |
-(void) addPendingWindowOperation:(PendingWindowOperation) operation
|
slouken@7963
|
369 |
{
|
slouken@7963
|
370 |
pendingWindowOperation = operation;
|
slouken@7963
|
371 |
}
|
slouken@7963
|
372 |
|
slouken@1933
|
373 |
- (void)close
|
slouken@1933
|
374 |
{
|
slouken@1933
|
375 |
NSNotificationCenter *center;
|
slouken@5371
|
376 |
NSWindow *window = _data->nswindow;
|
slouken@5371
|
377 |
NSView *view = [window contentView];
|
slouken@1933
|
378 |
|
slouken@1933
|
379 |
center = [NSNotificationCenter defaultCenter];
|
slouken@1933
|
380 |
|
slouken@5374
|
381 |
if ([window delegate] != self) {
|
slouken@5374
|
382 |
[center removeObserver:self name:NSWindowDidExposeNotification object:window];
|
slouken@5374
|
383 |
[center removeObserver:self name:NSWindowDidMoveNotification object:window];
|
slouken@5374
|
384 |
[center removeObserver:self name:NSWindowDidResizeNotification object:window];
|
slouken@5374
|
385 |
[center removeObserver:self name:NSWindowDidMiniaturizeNotification object:window];
|
slouken@5374
|
386 |
[center removeObserver:self name:NSWindowDidDeminiaturizeNotification object:window];
|
slouken@5374
|
387 |
[center removeObserver:self name:NSWindowDidBecomeKeyNotification object:window];
|
slouken@5374
|
388 |
[center removeObserver:self name:NSWindowDidResignKeyNotification object:window];
|
slime73@9643
|
389 |
[center removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
|
slouken@7952
|
390 |
[center removeObserver:self name:NSWindowWillEnterFullScreenNotification object:window];
|
slouken@7952
|
391 |
[center removeObserver:self name:NSWindowDidEnterFullScreenNotification object:window];
|
slouken@7952
|
392 |
[center removeObserver:self name:NSWindowWillExitFullScreenNotification object:window];
|
slouken@7952
|
393 |
[center removeObserver:self name:NSWindowDidExitFullScreenNotification object:window];
|
slouken@5374
|
394 |
} else {
|
slouken@5374
|
395 |
[window setDelegate:nil];
|
slouken@5374
|
396 |
}
|
slouken@5371
|
397 |
|
slouken@7961
|
398 |
[window removeObserver:self forKeyPath:@"visible"];
|
jorgen@7084
|
399 |
|
slouken@5374
|
400 |
if ([window nextResponder] == self) {
|
slouken@5374
|
401 |
[window setNextResponder:nil];
|
slouken@5374
|
402 |
}
|
slouken@5374
|
403 |
if ([view nextResponder] == self) {
|
slouken@5374
|
404 |
[view setNextResponder:nil];
|
slouken@5374
|
405 |
}
|
slouken@1933
|
406 |
}
|
slouken@1933
|
407 |
|
jorgen@8260
|
408 |
- (BOOL)isMoving
|
jorgen@8260
|
409 |
{
|
jorgen@8260
|
410 |
return isMoving;
|
jorgen@8260
|
411 |
}
|
jorgen@8260
|
412 |
|
jorgen@8260
|
413 |
-(void) setPendingMoveX:(int)x Y:(int)y
|
jorgen@8260
|
414 |
{
|
jorgen@8260
|
415 |
pendingWindowWarpX = x;
|
jorgen@8260
|
416 |
pendingWindowWarpY = y;
|
jorgen@8260
|
417 |
}
|
jorgen@8260
|
418 |
|
jorgen@8260
|
419 |
- (void)windowDidFinishMoving
|
jorgen@8260
|
420 |
{
|
slouken@8986
|
421 |
if ([self isMoving]) {
|
jorgen@8260
|
422 |
isMoving = NO;
|
jorgen@8260
|
423 |
|
jorgen@8260
|
424 |
SDL_Mouse *mouse = SDL_GetMouse();
|
slouken@9086
|
425 |
if (pendingWindowWarpX != INT_MAX && pendingWindowWarpY != INT_MAX) {
|
slouken@9086
|
426 |
mouse->WarpMouseGlobal(pendingWindowWarpX, pendingWindowWarpY);
|
slouken@9086
|
427 |
pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
|
jorgen@8260
|
428 |
}
|
slouken@9086
|
429 |
if (mouse->relative_mode && !mouse->relative_mode_warp && mouse->focus == _data->window) {
|
jorgen@8260
|
430 |
mouse->SetRelativeMouseMode(SDL_TRUE);
|
jorgen@8260
|
431 |
}
|
jorgen@8260
|
432 |
}
|
jorgen@8260
|
433 |
}
|
jorgen@8260
|
434 |
|
slouken@1933
|
435 |
- (BOOL)windowShouldClose:(id)sender
|
slouken@1933
|
436 |
{
|
slouken@3685
|
437 |
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
|
slouken@1933
|
438 |
return NO;
|
slouken@1933
|
439 |
}
|
slouken@1933
|
440 |
|
slouken@1933
|
441 |
- (void)windowDidExpose:(NSNotification *)aNotification
|
slouken@1933
|
442 |
{
|
slouken@3685
|
443 |
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
|
slouken@1933
|
444 |
}
|
slouken@1933
|
445 |
|
jorgen@8260
|
446 |
- (void)windowWillMove:(NSNotification *)aNotification
|
jorgen@8260
|
447 |
{
|
jorgen@8260
|
448 |
if ([_data->nswindow isKindOfClass:[SDLWindow class]]) {
|
slouken@9086
|
449 |
pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
|
jorgen@8260
|
450 |
isMoving = YES;
|
jorgen@8260
|
451 |
}
|
jorgen@8260
|
452 |
}
|
jorgen@8260
|
453 |
|
slouken@1933
|
454 |
- (void)windowDidMove:(NSNotification *)aNotification
|
slouken@1933
|
455 |
{
|
slouken@1933
|
456 |
int x, y;
|
slouken@5398
|
457 |
SDL_Window *window = _data->window;
|
slouken@5398
|
458 |
NSWindow *nswindow = _data->nswindow;
|
slouken@8801
|
459 |
BOOL fullscreen = window->flags & FULLSCREEN_MASK;
|
slouken@5398
|
460 |
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
slouken@8801
|
461 |
ConvertNSRect([nswindow screen], fullscreen, &rect);
|
slouken@5398
|
462 |
|
slouken@5398
|
463 |
if (s_moveHack) {
|
slouken@5398
|
464 |
SDL_bool blockMove = ((SDL_GetTicks() - s_moveHack) < 500);
|
slouken@5398
|
465 |
|
slouken@5398
|
466 |
s_moveHack = 0;
|
slouken@5398
|
467 |
|
slouken@5398
|
468 |
if (blockMove) {
|
slouken@5398
|
469 |
/* Cocoa is adjusting the window in response to a mode change */
|
slouken@5398
|
470 |
rect.origin.x = window->x;
|
slouken@5398
|
471 |
rect.origin.y = window->y;
|
slouken@8801
|
472 |
ConvertNSRect([nswindow screen], fullscreen, &rect);
|
slouken@5398
|
473 |
[nswindow setFrameOrigin:rect.origin];
|
slouken@5398
|
474 |
return;
|
slouken@5398
|
475 |
}
|
slouken@5398
|
476 |
}
|
slouken@5398
|
477 |
|
slouken@3507
|
478 |
x = (int)rect.origin.x;
|
slouken@3507
|
479 |
y = (int)rect.origin.y;
|
icculus@5564
|
480 |
|
jorgen@7595
|
481 |
ScheduleContextUpdates(_data);
|
icculus@5564
|
482 |
|
slouken@5398
|
483 |
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
|
slouken@1933
|
484 |
}
|
slouken@1933
|
485 |
|
slouken@1933
|
486 |
- (void)windowDidResize:(NSNotification *)aNotification
|
slouken@1933
|
487 |
{
|
icculus@8284
|
488 |
if (inFullscreenTransition) {
|
icculus@8284
|
489 |
/* We'll take care of this at the end of the transition */
|
icculus@8284
|
490 |
return;
|
icculus@8284
|
491 |
}
|
icculus@8284
|
492 |
|
slouken@7963
|
493 |
SDL_Window *window = _data->window;
|
slouken@7963
|
494 |
NSWindow *nswindow = _data->nswindow;
|
slouken@6231
|
495 |
int x, y, w, h;
|
slouken@7963
|
496 |
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
slouken@8801
|
497 |
ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
|
slouken@6231
|
498 |
x = (int)rect.origin.x;
|
slouken@6231
|
499 |
y = (int)rect.origin.y;
|
slouken@1933
|
500 |
w = (int)rect.size.width;
|
slouken@1933
|
501 |
h = (int)rect.size.height;
|
slouken@7952
|
502 |
|
slouken@7963
|
503 |
if (SDL_IsShapedWindow(window)) {
|
slouken@7963
|
504 |
Cocoa_ResizeWindowShape(window);
|
slouken@7952
|
505 |
}
|
icculus@5564
|
506 |
|
jorgen@7595
|
507 |
ScheduleContextUpdates(_data);
|
icculus@5564
|
508 |
|
slouken@6231
|
509 |
/* The window can move during a resize event, such as when maximizing
|
slouken@6231
|
510 |
or resizing from a corner */
|
slouken@7963
|
511 |
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y);
|
slouken@7963
|
512 |
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, w, h);
|
icculus@7566
|
513 |
|
slouken@7963
|
514 |
const BOOL zoomed = [nswindow isZoomed];
|
icculus@7566
|
515 |
if (!zoomed) {
|
slouken@7963
|
516 |
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
|
icculus@7566
|
517 |
} else if (zoomed) {
|
slouken@7963
|
518 |
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
|
icculus@7566
|
519 |
}
|
slouken@1933
|
520 |
}
|
slouken@1933
|
521 |
|
slouken@1933
|
522 |
- (void)windowDidMiniaturize:(NSNotification *)aNotification
|
slouken@1933
|
523 |
{
|
slouken@3685
|
524 |
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
|
slouken@1933
|
525 |
}
|
slouken@1933
|
526 |
|
slouken@1933
|
527 |
- (void)windowDidDeminiaturize:(NSNotification *)aNotification
|
slouken@1933
|
528 |
{
|
slouken@3685
|
529 |
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
|
slouken@1933
|
530 |
}
|
slouken@1933
|
531 |
|
slouken@1933
|
532 |
- (void)windowDidBecomeKey:(NSNotification *)aNotification
|
slouken@1933
|
533 |
{
|
slouken@5367
|
534 |
SDL_Window *window = _data->window;
|
jorgen@7271
|
535 |
SDL_Mouse *mouse = SDL_GetMouse();
|
icculus@9628
|
536 |
|
icculus@9628
|
537 |
/* We're going to get keyboard events, since we're key. */
|
icculus@9628
|
538 |
/* This needs to be done before restoring the relative mouse mode. */
|
icculus@9628
|
539 |
SDL_SetKeyboardFocus(window);
|
icculus@9628
|
540 |
|
slouken@9086
|
541 |
if (mouse->relative_mode && !mouse->relative_mode_warp && ![self isMoving]) {
|
jorgen@8260
|
542 |
mouse->SetRelativeMouseMode(SDL_TRUE);
|
jorgen@8260
|
543 |
}
|
slouken@5367
|
544 |
|
slouken@5367
|
545 |
/* If we just gained focus we need the updated mouse position */
|
jorgen@7271
|
546 |
if (!mouse->relative_mode) {
|
slouken@5367
|
547 |
NSPoint point;
|
slouken@5396
|
548 |
int x, y;
|
slouken@5396
|
549 |
|
slouken@5396
|
550 |
point = [_data->nswindow mouseLocationOutsideOfEventStream];
|
slouken@5396
|
551 |
x = (int)point.x;
|
slouken@5396
|
552 |
y = (int)(window->h - point.y);
|
slouken@5396
|
553 |
|
slouken@5396
|
554 |
if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
|
slouken@6950
|
555 |
SDL_SendMouseMotion(window, 0, 0, x, y);
|
slouken@5396
|
556 |
}
|
slouken@5367
|
557 |
}
|
slouken@1962
|
558 |
|
slouken@4503
|
559 |
/* Check to see if someone updated the clipboard */
|
slouken@4503
|
560 |
Cocoa_CheckClipboardUpdate(_data->videodata);
|
icculus@8288
|
561 |
|
icculus@8293
|
562 |
if ((isFullscreenSpace) && ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)) {
|
icculus@8288
|
563 |
[NSMenu setMenuBarVisible:NO];
|
icculus@8288
|
564 |
}
|
slouken@1933
|
565 |
}
|
slouken@1933
|
566 |
|
slouken@1933
|
567 |
- (void)windowDidResignKey:(NSNotification *)aNotification
|
slouken@1933
|
568 |
{
|
jorgen@8260
|
569 |
SDL_Mouse *mouse = SDL_GetMouse();
|
slouken@9086
|
570 |
if (mouse->relative_mode && !mouse->relative_mode_warp) {
|
jorgen@8260
|
571 |
mouse->SetRelativeMouseMode(SDL_FALSE);
|
jorgen@8260
|
572 |
}
|
jorgen@8260
|
573 |
|
slouken@2059
|
574 |
/* Some other window will get mouse events, since we're not key. */
|
slouken@4465
|
575 |
if (SDL_GetMouseFocus() == _data->window) {
|
slouken@4465
|
576 |
SDL_SetMouseFocus(NULL);
|
slouken@2059
|
577 |
}
|
slouken@2059
|
578 |
|
slouken@2059
|
579 |
/* Some other window will get keyboard events, since we're not key. */
|
slouken@4465
|
580 |
if (SDL_GetKeyboardFocus() == _data->window) {
|
slouken@4465
|
581 |
SDL_SetKeyboardFocus(NULL);
|
slouken@4465
|
582 |
}
|
icculus@8288
|
583 |
|
icculus@8288
|
584 |
if (isFullscreenSpace) {
|
icculus@8288
|
585 |
[NSMenu setMenuBarVisible:YES];
|
icculus@8288
|
586 |
}
|
slouken@1933
|
587 |
}
|
slouken@1933
|
588 |
|
slime73@9643
|
589 |
- (void)windowDidChangeBackingProperties:(NSNotification *)aNotification
|
slime73@9643
|
590 |
{
|
slime73@9643
|
591 |
NSNumber *oldscale = [[aNotification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey];
|
slime73@9643
|
592 |
|
slime73@9643
|
593 |
if (inFullscreenTransition) {
|
slime73@9643
|
594 |
return;
|
slime73@9643
|
595 |
}
|
slime73@9643
|
596 |
|
slime73@9643
|
597 |
if ([oldscale doubleValue] != [_data->nswindow backingScaleFactor]) {
|
slime73@9643
|
598 |
/* Force a resize event when the backing scale factor changes. */
|
slime73@9643
|
599 |
_data->window->w = 0;
|
slime73@9643
|
600 |
_data->window->h = 0;
|
slime73@9643
|
601 |
[self windowDidResize:aNotification];
|
slime73@9643
|
602 |
}
|
slime73@9643
|
603 |
}
|
slime73@9643
|
604 |
|
slouken@7952
|
605 |
- (void)windowWillEnterFullScreen:(NSNotification *)aNotification
|
slouken@7952
|
606 |
{
|
slouken@7952
|
607 |
SDL_Window *window = _data->window;
|
slouken@7952
|
608 |
|
slouken@7990
|
609 |
SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
|
slouken@7965
|
610 |
|
slouken@7967
|
611 |
isFullscreenSpace = YES;
|
slouken@7952
|
612 |
inFullscreenTransition = YES;
|
slouken@7952
|
613 |
}
|
slouken@7952
|
614 |
|
slouken@7952
|
615 |
- (void)windowDidEnterFullScreen:(NSNotification *)aNotification
|
slouken@7952
|
616 |
{
|
slouken@7965
|
617 |
SDL_Window *window = _data->window;
|
slouken@7965
|
618 |
|
slouken@7952
|
619 |
inFullscreenTransition = NO;
|
slouken@7961
|
620 |
|
slouken@7963
|
621 |
if (pendingWindowOperation == PENDING_OPERATION_LEAVE_FULLSCREEN) {
|
slouken@7963
|
622 |
pendingWindowOperation = PENDING_OPERATION_NONE;
|
slouken@7967
|
623 |
[self setFullscreenSpace:NO];
|
slouken@7961
|
624 |
} else {
|
icculus@8284
|
625 |
if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
|
icculus@8284
|
626 |
[NSMenu setMenuBarVisible:NO];
|
icculus@8284
|
627 |
}
|
icculus@8284
|
628 |
|
slouken@7963
|
629 |
pendingWindowOperation = PENDING_OPERATION_NONE;
|
slouken@7965
|
630 |
/* Force the size change event in case it was delivered earlier
|
slouken@7965
|
631 |
while the window was still animating into place.
|
slouken@7965
|
632 |
*/
|
slouken@7965
|
633 |
window->w = 0;
|
slouken@7965
|
634 |
window->h = 0;
|
slouken@7961
|
635 |
[self windowDidResize:aNotification];
|
slouken@7961
|
636 |
}
|
slouken@7952
|
637 |
}
|
slouken@7952
|
638 |
|
slouken@7952
|
639 |
- (void)windowWillExitFullScreen:(NSNotification *)aNotification
|
slouken@7952
|
640 |
{
|
slouken@7964
|
641 |
SDL_Window *window = _data->window;
|
slouken@7964
|
642 |
|
slouken@7990
|
643 |
SetWindowStyle(window, GetWindowStyle(window));
|
slouken@7964
|
644 |
|
slouken@7967
|
645 |
isFullscreenSpace = NO;
|
slouken@7952
|
646 |
inFullscreenTransition = YES;
|
slouken@7952
|
647 |
}
|
slouken@7952
|
648 |
|
slouken@7952
|
649 |
- (void)windowDidExitFullScreen:(NSNotification *)aNotification
|
slouken@7952
|
650 |
{
|
slouken@7965
|
651 |
SDL_Window *window = _data->window;
|
slouken@7952
|
652 |
NSWindow *nswindow = _data->nswindow;
|
slouken@7952
|
653 |
|
slouken@7952
|
654 |
inFullscreenTransition = NO;
|
slouken@7961
|
655 |
|
slouken@8618
|
656 |
[nswindow setLevel:kCGNormalWindowLevel];
|
slouken@8618
|
657 |
|
slouken@7963
|
658 |
if (pendingWindowOperation == PENDING_OPERATION_ENTER_FULLSCREEN) {
|
slouken@7963
|
659 |
pendingWindowOperation = PENDING_OPERATION_NONE;
|
slouken@7967
|
660 |
[self setFullscreenSpace:YES];
|
slouken@7963
|
661 |
} else if (pendingWindowOperation == PENDING_OPERATION_MINIMIZE) {
|
slouken@7963
|
662 |
pendingWindowOperation = PENDING_OPERATION_NONE;
|
slouken@7963
|
663 |
[nswindow miniaturize:nil];
|
slouken@7961
|
664 |
} else {
|
icculus@8291
|
665 |
/* Adjust the fullscreen toggle button and readd menu now that we're here. */
|
icculus@8291
|
666 |
if (window->flags & SDL_WINDOW_RESIZABLE) {
|
icculus@8291
|
667 |
/* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
|
icculus@8291
|
668 |
[nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
icculus@8291
|
669 |
} else {
|
icculus@8284
|
670 |
[nswindow setCollectionBehavior:NSWindowCollectionBehaviorManaged];
|
icculus@8284
|
671 |
}
|
icculus@8291
|
672 |
[NSMenu setMenuBarVisible:YES];
|
icculus@8284
|
673 |
|
slouken@7963
|
674 |
pendingWindowOperation = PENDING_OPERATION_NONE;
|
slouken@7965
|
675 |
/* Force the size change event in case it was delivered earlier
|
slouken@7965
|
676 |
while the window was still animating into place.
|
slouken@7965
|
677 |
*/
|
slouken@7965
|
678 |
window->w = 0;
|
slouken@7965
|
679 |
window->h = 0;
|
slouken@7961
|
680 |
[self windowDidResize:aNotification];
|
icculus@8622
|
681 |
|
slouken@8623
|
682 |
/* FIXME: Why does the window get hidden? */
|
slouken@8623
|
683 |
if (window->flags & SDL_WINDOW_SHOWN) {
|
slouken@8623
|
684 |
Cocoa_ShowWindow(SDL_GetVideoDevice(), window);
|
slouken@8623
|
685 |
}
|
slouken@7961
|
686 |
}
|
slouken@7952
|
687 |
}
|
slouken@7952
|
688 |
|
icculus@8291
|
689 |
-(NSApplicationPresentationOptions)window:(NSWindow *)window willUseFullScreenPresentationOptions:(NSApplicationPresentationOptions)proposedOptions
|
icculus@8291
|
690 |
{
|
icculus@8291
|
691 |
if ((_data->window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) {
|
icculus@8291
|
692 |
return NSApplicationPresentationFullScreen | NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar;
|
icculus@8291
|
693 |
} else {
|
icculus@8291
|
694 |
return proposedOptions;
|
icculus@8291
|
695 |
}
|
icculus@8291
|
696 |
}
|
icculus@8291
|
697 |
|
icculus@8291
|
698 |
|
slouken@7191
|
699 |
/* We'll respond to key events by doing nothing so we don't beep.
|
slouken@7191
|
700 |
* We could handle key messages here, but we lose some in the NSApp dispatch,
|
slouken@7191
|
701 |
* where they get converted to action messages, etc.
|
slouken@7191
|
702 |
*/
|
slouken@6514
|
703 |
- (void)flagsChanged:(NSEvent *)theEvent
|
slouken@6514
|
704 |
{
|
slouken@7191
|
705 |
/*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
|
slouken@6514
|
706 |
}
|
slouken@6514
|
707 |
- (void)keyDown:(NSEvent *)theEvent
|
slouken@6514
|
708 |
{
|
slouken@7191
|
709 |
/*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
|
slouken@6514
|
710 |
}
|
slouken@6514
|
711 |
- (void)keyUp:(NSEvent *)theEvent
|
slouken@6514
|
712 |
{
|
slouken@7191
|
713 |
/*Cocoa_HandleKeyEvent(SDL_GetVideoDevice(), theEvent);*/
|
slouken@6514
|
714 |
}
|
slouken@6514
|
715 |
|
slouken@7191
|
716 |
/* We'll respond to selectors by doing nothing so we don't beep.
|
slouken@7191
|
717 |
* The escape key gets converted to a "cancel" selector, etc.
|
slouken@7191
|
718 |
*/
|
slouken@6514
|
719 |
- (void)doCommandBySelector:(SEL)aSelector
|
slouken@6514
|
720 |
{
|
slouken@7191
|
721 |
/*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
|
slouken@6514
|
722 |
}
|
slouken@6514
|
723 |
|
icculus@8935
|
724 |
- (BOOL)processHitTest:(NSEvent *)theEvent
|
icculus@8931
|
725 |
{
|
icculus@8931
|
726 |
SDL_assert(isDragAreaRunning == [_data->nswindow isMovableByWindowBackground]);
|
icculus@8931
|
727 |
|
icculus@8935
|
728 |
if (_data->window->hit_test) { /* if no hit-test, skip this. */
|
icculus@8931
|
729 |
const NSPoint location = [theEvent locationInWindow];
|
icculus@8931
|
730 |
const SDL_Point point = { (int) location.x, _data->window->h - (((int) location.y)-1) };
|
icculus@8935
|
731 |
const SDL_HitTestResult rc = _data->window->hit_test(_data->window, &point, _data->window->hit_test_data);
|
icculus@8935
|
732 |
if (rc == SDL_HITTEST_DRAGGABLE) {
|
icculus@8935
|
733 |
if (!isDragAreaRunning) {
|
icculus@8935
|
734 |
isDragAreaRunning = YES;
|
icculus@8935
|
735 |
[_data->nswindow setMovableByWindowBackground:YES];
|
icculus@8931
|
736 |
}
|
icculus@8935
|
737 |
return YES; /* dragging! */
|
icculus@8931
|
738 |
}
|
icculus@8931
|
739 |
}
|
icculus@8931
|
740 |
|
icculus@8931
|
741 |
if (isDragAreaRunning) {
|
icculus@8931
|
742 |
isDragAreaRunning = NO;
|
icculus@8931
|
743 |
[_data->nswindow setMovableByWindowBackground:NO];
|
icculus@8931
|
744 |
return YES; /* was dragging, drop event. */
|
icculus@8931
|
745 |
}
|
icculus@8931
|
746 |
|
icculus@8935
|
747 |
return NO; /* not a special area, carry on. */
|
icculus@8931
|
748 |
}
|
icculus@8931
|
749 |
|
slouken@1933
|
750 |
- (void)mouseDown:(NSEvent *)theEvent
|
slouken@1933
|
751 |
{
|
slouken@1959
|
752 |
int button;
|
slouken@1933
|
753 |
|
icculus@8935
|
754 |
if ([self processHitTest:theEvent]) {
|
icculus@8931
|
755 |
return; /* dragging, drop event. */
|
icculus@8931
|
756 |
}
|
icculus@8931
|
757 |
|
slouken@1959
|
758 |
switch ([theEvent buttonNumber]) {
|
slouken@1959
|
759 |
case 0:
|
slouken@7915
|
760 |
if (([theEvent modifierFlags] & NSControlKeyMask) &&
|
slouken@7915
|
761 |
GetHintCtrlClickEmulateRightClick()) {
|
slouken@7740
|
762 |
wasCtrlLeft = YES;
|
slouken@7740
|
763 |
button = SDL_BUTTON_RIGHT;
|
slouken@7740
|
764 |
} else {
|
slouken@7740
|
765 |
wasCtrlLeft = NO;
|
slouken@7740
|
766 |
button = SDL_BUTTON_LEFT;
|
slouken@7740
|
767 |
}
|
slouken@1959
|
768 |
break;
|
slouken@1959
|
769 |
case 1:
|
slouken@1959
|
770 |
button = SDL_BUTTON_RIGHT;
|
slouken@1959
|
771 |
break;
|
slouken@1959
|
772 |
case 2:
|
slouken@1959
|
773 |
button = SDL_BUTTON_MIDDLE;
|
slouken@1959
|
774 |
break;
|
slouken@1959
|
775 |
default:
|
slouken@5061
|
776 |
button = [theEvent buttonNumber] + 1;
|
slouken@1959
|
777 |
break;
|
slouken@1959
|
778 |
}
|
slouken@6950
|
779 |
SDL_SendMouseButton(_data->window, 0, SDL_PRESSED, button);
|
slouken@1933
|
780 |
}
|
slouken@1933
|
781 |
|
slouken@1933
|
782 |
- (void)rightMouseDown:(NSEvent *)theEvent
|
slouken@1933
|
783 |
{
|
slouken@1959
|
784 |
[self mouseDown:theEvent];
|
slouken@1933
|
785 |
}
|
slouken@1933
|
786 |
|
slouken@1933
|
787 |
- (void)otherMouseDown:(NSEvent *)theEvent
|
slouken@1933
|
788 |
{
|
slouken@1959
|
789 |
[self mouseDown:theEvent];
|
slouken@1933
|
790 |
}
|
slouken@1933
|
791 |
|
slouken@1933
|
792 |
- (void)mouseUp:(NSEvent *)theEvent
|
slouken@1933
|
793 |
{
|
slouken@1959
|
794 |
int button;
|
slouken@1933
|
795 |
|
icculus@8935
|
796 |
if ([self processHitTest:theEvent]) {
|
icculus@8931
|
797 |
return; /* stopped dragging, drop event. */
|
icculus@8931
|
798 |
}
|
icculus@8931
|
799 |
|
slouken@1959
|
800 |
switch ([theEvent buttonNumber]) {
|
slouken@1959
|
801 |
case 0:
|
slouken@7740
|
802 |
if (wasCtrlLeft) {
|
slouken@7740
|
803 |
button = SDL_BUTTON_RIGHT;
|
slouken@7740
|
804 |
wasCtrlLeft = NO;
|
slouken@7740
|
805 |
} else {
|
slouken@7740
|
806 |
button = SDL_BUTTON_LEFT;
|
slouken@7740
|
807 |
}
|
slouken@1959
|
808 |
break;
|
slouken@1959
|
809 |
case 1:
|
slouken@1959
|
810 |
button = SDL_BUTTON_RIGHT;
|
slouken@1959
|
811 |
break;
|
slouken@1959
|
812 |
case 2:
|
slouken@1959
|
813 |
button = SDL_BUTTON_MIDDLE;
|
slouken@1959
|
814 |
break;
|
slouken@1959
|
815 |
default:
|
slouken@5061
|
816 |
button = [theEvent buttonNumber] + 1;
|
slouken@1959
|
817 |
break;
|
slouken@1959
|
818 |
}
|
slouken@6950
|
819 |
SDL_SendMouseButton(_data->window, 0, SDL_RELEASED, button);
|
slouken@1933
|
820 |
}
|
slouken@1933
|
821 |
|
slouken@1933
|
822 |
- (void)rightMouseUp:(NSEvent *)theEvent
|
slouken@1933
|
823 |
{
|
slouken@1959
|
824 |
[self mouseUp:theEvent];
|
slouken@1933
|
825 |
}
|
slouken@1933
|
826 |
|
slouken@1933
|
827 |
- (void)otherMouseUp:(NSEvent *)theEvent
|
slouken@1933
|
828 |
{
|
slouken@1959
|
829 |
[self mouseUp:theEvent];
|
slouken@1933
|
830 |
}
|
slouken@1933
|
831 |
|
slouken@1933
|
832 |
- (void)mouseMoved:(NSEvent *)theEvent
|
slouken@1933
|
833 |
{
|
slouken@5406
|
834 |
SDL_Mouse *mouse = SDL_GetMouse();
|
slouken@3685
|
835 |
SDL_Window *window = _data->window;
|
slouken@5396
|
836 |
NSPoint point;
|
slouken@5396
|
837 |
int x, y;
|
slouken@1933
|
838 |
|
icculus@8935
|
839 |
if ([self processHitTest:theEvent]) {
|
icculus@8931
|
840 |
return; /* dragging, drop event. */
|
icculus@8931
|
841 |
}
|
icculus@8931
|
842 |
|
slouken@5406
|
843 |
if (mouse->relative_mode) {
|
gzjjgod@5059
|
844 |
return;
|
slouken@5371
|
845 |
}
|
gzjjgod@5059
|
846 |
|
slouken@5396
|
847 |
point = [theEvent locationInWindow];
|
slouken@5396
|
848 |
x = (int)point.x;
|
slouken@5396
|
849 |
y = (int)(window->h - point.y);
|
slouken@5371
|
850 |
|
icculus@8929
|
851 |
if (window->flags & SDL_WINDOW_INPUT_GRABBED) {
|
icculus@8929
|
852 |
if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
|
slouken@6666
|
853 |
if (x < 0) {
|
slouken@6666
|
854 |
x = 0;
|
slouken@6666
|
855 |
} else if (x >= window->w) {
|
slouken@6666
|
856 |
x = window->w - 1;
|
slouken@6666
|
857 |
}
|
slouken@6666
|
858 |
if (y < 0) {
|
slouken@6666
|
859 |
y = 0;
|
slouken@6666
|
860 |
} else if (y >= window->h) {
|
slouken@6666
|
861 |
y = window->h - 1;
|
slouken@6666
|
862 |
}
|
slouken@6666
|
863 |
|
jorgen@7593
|
864 |
#if !SDL_MAC_NO_SANDBOX
|
jorgen@8260
|
865 |
CGPoint cgpoint;
|
jorgen@8260
|
866 |
|
jorgen@7593
|
867 |
/* When SDL_MAC_NO_SANDBOX is set, this is handled by
|
jorgen@7593
|
868 |
* SDL_cocoamousetap.m.
|
jorgen@7593
|
869 |
*/
|
jorgen@7593
|
870 |
|
slouken@6666
|
871 |
cgpoint.x = window->x + x;
|
slouken@6666
|
872 |
cgpoint.y = window->y + y;
|
jorgen@7098
|
873 |
|
jorgen@7113
|
874 |
/* According to the docs, this was deprecated in 10.6, but it's still
|
jorgen@7113
|
875 |
* around. The substitute requires a CGEventSource, but I'm not entirely
|
jorgen@7113
|
876 |
* sure how we'd procure the right one for this event.
|
jorgen@7098
|
877 |
*/
|
jorgen@7113
|
878 |
CGSetLocalEventsSuppressionInterval(0.0);
|
slouken@6666
|
879 |
CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
|
jorgen@7113
|
880 |
CGSetLocalEventsSuppressionInterval(0.25);
|
jorgen@8261
|
881 |
|
jorgen@8261
|
882 |
Cocoa_HandleMouseWarp(cgpoint.x, cgpoint.y);
|
jorgen@7593
|
883 |
#endif
|
slouken@5396
|
884 |
}
|
slouken@2059
|
885 |
}
|
slouken@6950
|
886 |
SDL_SendMouseMotion(window, 0, 0, x, y);
|
slouken@1933
|
887 |
}
|
slouken@1933
|
888 |
|
slouken@1957
|
889 |
- (void)mouseDragged:(NSEvent *)theEvent
|
slouken@1957
|
890 |
{
|
slouken@1957
|
891 |
[self mouseMoved:theEvent];
|
slouken@1957
|
892 |
}
|
slouken@1957
|
893 |
|
slouken@1958
|
894 |
- (void)rightMouseDragged:(NSEvent *)theEvent
|
slouken@1958
|
895 |
{
|
slouken@1958
|
896 |
[self mouseMoved:theEvent];
|
slouken@1958
|
897 |
}
|
slouken@1958
|
898 |
|
slouken@1958
|
899 |
- (void)otherMouseDragged:(NSEvent *)theEvent
|
slouken@1958
|
900 |
{
|
slouken@1958
|
901 |
[self mouseMoved:theEvent];
|
slouken@1958
|
902 |
}
|
slouken@1958
|
903 |
|
slouken@1933
|
904 |
- (void)scrollWheel:(NSEvent *)theEvent
|
slouken@1933
|
905 |
{
|
gzjjgod@5057
|
906 |
Cocoa_HandleMouseWheel(_data->window, theEvent);
|
slouken@1933
|
907 |
}
|
slouken@1933
|
908 |
|
slouken@4673
|
909 |
- (void)touchesBeganWithEvent:(NSEvent *) theEvent
|
slouken@4673
|
910 |
{
|
urkle@9236
|
911 |
NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
|
urkle@9236
|
912 |
int existingTouchCount = 0;
|
urkle@9236
|
913 |
|
urkle@9236
|
914 |
for (NSTouch* touch in touches) {
|
urkle@9236
|
915 |
if ([touch phase] != NSTouchPhaseBegan) {
|
urkle@9236
|
916 |
existingTouchCount++;
|
urkle@9236
|
917 |
}
|
urkle@9236
|
918 |
}
|
urkle@9236
|
919 |
if (existingTouchCount == 0) {
|
urkle@9236
|
920 |
SDL_TouchID touchID = (SDL_TouchID)(intptr_t)[[touches anyObject] device];
|
urkle@9236
|
921 |
int numFingers = SDL_GetNumTouchFingers(touchID);
|
urkle@9236
|
922 |
DLog("Reset Lost Fingers: %d", numFingers);
|
urkle@9236
|
923 |
for (--numFingers; numFingers >= 0; --numFingers) {
|
urkle@9236
|
924 |
SDL_Finger* finger = SDL_GetTouchFinger(touchID, numFingers);
|
urkle@9236
|
925 |
SDL_SendTouch(touchID, finger->id, SDL_FALSE, 0, 0, 0);
|
urkle@9236
|
926 |
}
|
urkle@9236
|
927 |
}
|
urkle@9236
|
928 |
|
urkle@9236
|
929 |
DLog("Began Fingers: %lu .. existing: %d", (unsigned long)[touches count], existingTouchCount);
|
slouken@8986
|
930 |
[self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
|
slouken@4673
|
931 |
}
|
slouken@4673
|
932 |
|
slouken@4673
|
933 |
- (void)touchesMovedWithEvent:(NSEvent *) theEvent
|
slouken@4673
|
934 |
{
|
slouken@8986
|
935 |
[self handleTouches:NSTouchPhaseMoved withEvent:theEvent];
|
slouken@4673
|
936 |
}
|
slouken@4673
|
937 |
|
slouken@4673
|
938 |
- (void)touchesEndedWithEvent:(NSEvent *) theEvent
|
slouken@4673
|
939 |
{
|
slouken@8986
|
940 |
[self handleTouches:NSTouchPhaseEnded withEvent:theEvent];
|
slouken@4673
|
941 |
}
|
slouken@4673
|
942 |
|
slouken@4673
|
943 |
- (void)touchesCancelledWithEvent:(NSEvent *) theEvent
|
slouken@4673
|
944 |
{
|
slouken@8986
|
945 |
[self handleTouches:NSTouchPhaseCancelled withEvent:theEvent];
|
slouken@4673
|
946 |
}
|
slouken@4673
|
947 |
|
slouken@8986
|
948 |
- (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
|
slouken@4673
|
949 |
{
|
slouken@8986
|
950 |
NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
|
slouken@1957
|
951 |
|
slouken@8986
|
952 |
for (NSTouch *touch in touches) {
|
slouken@6953
|
953 |
const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
|
slouken@9679
|
954 |
if (SDL_AddTouch(touchId, "") < 0) {
|
slouken@9679
|
955 |
return;
|
slouken@7191
|
956 |
}
|
slouken@4687
|
957 |
|
slouken@6953
|
958 |
const SDL_FingerID fingerId = (SDL_FingerID)(intptr_t)[touch identity];
|
slouken@4673
|
959 |
float x = [touch normalizedPosition].x;
|
slouken@4673
|
960 |
float y = [touch normalizedPosition].y;
|
slouken@5261
|
961 |
/* Make the origin the upper left instead of the lower left */
|
slouken@5261
|
962 |
y = 1.0f - y;
|
slouken@4687
|
963 |
|
slouken@8986
|
964 |
switch (phase) {
|
slouken@8986
|
965 |
case NSTouchPhaseBegan:
|
slouken@6951
|
966 |
SDL_SendTouch(touchId, fingerId, SDL_TRUE, x, y, 1.0f);
|
slouken@4673
|
967 |
break;
|
slouken@8986
|
968 |
case NSTouchPhaseEnded:
|
slouken@8986
|
969 |
case NSTouchPhaseCancelled:
|
slouken@6951
|
970 |
SDL_SendTouch(touchId, fingerId, SDL_FALSE, x, y, 1.0f);
|
slouken@4673
|
971 |
break;
|
slouken@8986
|
972 |
case NSTouchPhaseMoved:
|
slouken@6951
|
973 |
SDL_SendTouchMotion(touchId, fingerId, x, y, 1.0f);
|
slouken@4673
|
974 |
break;
|
slouken@8986
|
975 |
default:
|
slouken@8986
|
976 |
break;
|
slouken@4673
|
977 |
}
|
slouken@4673
|
978 |
}
|
slouken@1933
|
979 |
}
|
slouken@1933
|
980 |
|
slouken@1933
|
981 |
@end
|
slouken@1933
|
982 |
|
icculus@9623
|
983 |
@interface SDLView : NSView {
|
icculus@9623
|
984 |
SDL_Window *_sdlWindow;
|
icculus@9623
|
985 |
}
|
icculus@9623
|
986 |
|
icculus@9623
|
987 |
- (void)setSDLWindow:(SDL_Window*)window;
|
jorgen@7158
|
988 |
|
slouken@5379
|
989 |
/* The default implementation doesn't pass rightMouseDown to responder chain */
|
slouken@5379
|
990 |
- (void)rightMouseDown:(NSEvent *)theEvent;
|
icculus@8931
|
991 |
- (BOOL)mouseDownCanMoveWindow;
|
icculus@9623
|
992 |
- (void)drawRect:(NSRect)dirtyRect;
|
gzjjgod@4915
|
993 |
@end
|
gzjjgod@4915
|
994 |
|
gzjjgod@4915
|
995 |
@implementation SDLView
|
icculus@9623
|
996 |
- (void)setSDLWindow:(SDL_Window*)window
|
icculus@9623
|
997 |
{
|
icculus@9623
|
998 |
_sdlWindow = window;
|
icculus@9623
|
999 |
}
|
icculus@9623
|
1000 |
|
icculus@9623
|
1001 |
- (void)drawRect:(NSRect)dirtyRect
|
icculus@9623
|
1002 |
{
|
icculus@9623
|
1003 |
SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
|
icculus@9623
|
1004 |
}
|
icculus@9623
|
1005 |
|
gzjjgod@4915
|
1006 |
- (void)rightMouseDown:(NSEvent *)theEvent
|
gzjjgod@4915
|
1007 |
{
|
slouken@5371
|
1008 |
[[self nextResponder] rightMouseDown:theEvent];
|
gzjjgod@4915
|
1009 |
}
|
jorgen@7158
|
1010 |
|
icculus@8931
|
1011 |
- (BOOL)mouseDownCanMoveWindow
|
icculus@8931
|
1012 |
{
|
icculus@8931
|
1013 |
/* Always say YES, but this doesn't do anything until we call
|
icculus@8931
|
1014 |
-[NSWindow setMovableByWindowBackground:YES], which we ninja-toggle
|
icculus@8931
|
1015 |
during mouse events when we're using a drag area. */
|
icculus@8931
|
1016 |
return YES;
|
icculus@8931
|
1017 |
}
|
icculus@8931
|
1018 |
|
jorgen@7158
|
1019 |
- (void)resetCursorRects
|
jorgen@7158
|
1020 |
{
|
jorgen@7158
|
1021 |
[super resetCursorRects];
|
jorgen@7158
|
1022 |
SDL_Mouse *mouse = SDL_GetMouse();
|
jorgen@7158
|
1023 |
|
jorgen@7270
|
1024 |
if (mouse->cursor_shown && mouse->cur_cursor && !mouse->relative_mode) {
|
jorgen@7158
|
1025 |
[self addCursorRect:[self bounds]
|
jorgen@7158
|
1026 |
cursor:mouse->cur_cursor->driverdata];
|
jorgen@7158
|
1027 |
} else {
|
jorgen@7158
|
1028 |
[self addCursorRect:[self bounds]
|
jorgen@7158
|
1029 |
cursor:[NSCursor invisibleCursor]];
|
jorgen@7158
|
1030 |
}
|
jorgen@7158
|
1031 |
}
|
gzjjgod@4915
|
1032 |
@end
|
gzjjgod@4915
|
1033 |
|
slouken@1933
|
1034 |
static int
|
slouken@1951
|
1035 |
SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created)
|
slime73@9587
|
1036 |
{ @autoreleasepool
|
slouken@1933
|
1037 |
{
|
slouken@1951
|
1038 |
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
|
slouken@1933
|
1039 |
SDL_WindowData *data;
|
slouken@1933
|
1040 |
|
slouken@1933
|
1041 |
/* Allocate the window data */
|
slouken@8926
|
1042 |
window->driverdata = data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
|
slouken@1933
|
1043 |
if (!data) {
|
icculus@7037
|
1044 |
return SDL_OutOfMemory();
|
slouken@1933
|
1045 |
}
|
slouken@3685
|
1046 |
data->window = window;
|
slouken@3688
|
1047 |
data->nswindow = nswindow;
|
slouken@1933
|
1048 |
data->created = created;
|
slouken@1951
|
1049 |
data->videodata = videodata;
|
jorgen@7595
|
1050 |
data->nscontexts = [[NSMutableArray alloc] init];
|
slouken@1933
|
1051 |
|
slouken@6848
|
1052 |
/* Create an event listener for the window */
|
slouken@6848
|
1053 |
data->listener = [[Cocoa_WindowListener alloc] init];
|
slouken@1933
|
1054 |
|
slouken@6848
|
1055 |
/* Fill in the SDL window with the window data */
|
slouken@6848
|
1056 |
{
|
slouken@6848
|
1057 |
NSRect rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
slouken@8801
|
1058 |
ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
|
slouken@6848
|
1059 |
window->x = (int)rect.origin.x;
|
slouken@6848
|
1060 |
window->y = (int)rect.origin.y;
|
slouken@6848
|
1061 |
window->w = (int)rect.size.width;
|
slouken@6848
|
1062 |
window->h = (int)rect.size.height;
|
slouken@6848
|
1063 |
}
|
slouken@5371
|
1064 |
|
slouken@6848
|
1065 |
/* Set up the listener after we create the view */
|
slouken@6848
|
1066 |
[data->listener listen:data];
|
slouken@5371
|
1067 |
|
slouken@6848
|
1068 |
if ([nswindow isVisible]) {
|
slouken@6848
|
1069 |
window->flags |= SDL_WINDOW_SHOWN;
|
slouken@6848
|
1070 |
} else {
|
slouken@6848
|
1071 |
window->flags &= ~SDL_WINDOW_SHOWN;
|
slouken@6848
|
1072 |
}
|
jorgen@7084
|
1073 |
|
slouken@6848
|
1074 |
{
|
slouken@6848
|
1075 |
unsigned int style = [nswindow styleMask];
|
alexey@6832
|
1076 |
|
slouken@6848
|
1077 |
if (style == NSBorderlessWindowMask) {
|
slouken@6848
|
1078 |
window->flags |= SDL_WINDOW_BORDERLESS;
|
slouken@6848
|
1079 |
} else {
|
slouken@6848
|
1080 |
window->flags &= ~SDL_WINDOW_BORDERLESS;
|
slouken@1933
|
1081 |
}
|
slouken@6848
|
1082 |
if (style & NSResizableWindowMask) {
|
slouken@6848
|
1083 |
window->flags |= SDL_WINDOW_RESIZABLE;
|
alexey@6832
|
1084 |
} else {
|
slouken@6848
|
1085 |
window->flags &= ~SDL_WINDOW_RESIZABLE;
|
alexey@6832
|
1086 |
}
|
slouken@6848
|
1087 |
}
|
jorgen@7084
|
1088 |
|
slouken@6848
|
1089 |
/* isZoomed always returns true if the window is not resizable */
|
slouken@6848
|
1090 |
if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
|
slouken@6848
|
1091 |
window->flags |= SDL_WINDOW_MAXIMIZED;
|
slouken@6848
|
1092 |
} else {
|
slouken@6848
|
1093 |
window->flags &= ~SDL_WINDOW_MAXIMIZED;
|
slouken@6848
|
1094 |
}
|
jorgen@7084
|
1095 |
|
slouken@6848
|
1096 |
if ([nswindow isMiniaturized]) {
|
slouken@6848
|
1097 |
window->flags |= SDL_WINDOW_MINIMIZED;
|
slouken@6848
|
1098 |
} else {
|
slouken@6848
|
1099 |
window->flags &= ~SDL_WINDOW_MINIMIZED;
|
slouken@6848
|
1100 |
}
|
jorgen@7084
|
1101 |
|
slouken@6848
|
1102 |
if ([nswindow isKeyWindow]) {
|
slouken@6848
|
1103 |
window->flags |= SDL_WINDOW_INPUT_FOCUS;
|
slouken@6848
|
1104 |
SDL_SetKeyboardFocus(data->window);
|
slouken@6848
|
1105 |
}
|
alexey@6832
|
1106 |
|
jorgen@7085
|
1107 |
/* Prevents the window's "window device" from being destroyed when it is
|
jorgen@7085
|
1108 |
* hidden. See http://www.mikeash.com/pyblog/nsopenglcontext-and-one-shot.html
|
jorgen@7085
|
1109 |
*/
|
jorgen@7085
|
1110 |
[nswindow setOneShot:NO];
|
jorgen@7085
|
1111 |
|
slouken@6848
|
1112 |
/* All done! */
|
slouken@6848
|
1113 |
window->driverdata = data;
|
slouken@6848
|
1114 |
return 0;
|
slime73@9587
|
1115 |
}}
|
slouken@1933
|
1116 |
|
slouken@1933
|
1117 |
int
|
slouken@1933
|
1118 |
Cocoa_CreateWindow(_THIS, SDL_Window * window)
|
slime73@9587
|
1119 |
{ @autoreleasepool
|
slouken@1933
|
1120 |
{
|
icculus@8295
|
1121 |
SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
|
slouken@6848
|
1122 |
NSWindow *nswindow;
|
slouken@6848
|
1123 |
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
slouken@6848
|
1124 |
NSRect rect;
|
slouken@6848
|
1125 |
SDL_Rect bounds;
|
slouken@6848
|
1126 |
unsigned int style;
|
slouken@8986
|
1127 |
NSArray *screens = [NSScreen screens];
|
slouken@1933
|
1128 |
|
slouken@6848
|
1129 |
Cocoa_GetDisplayBounds(_this, display, &bounds);
|
slouken@6848
|
1130 |
rect.origin.x = window->x;
|
slouken@6848
|
1131 |
rect.origin.y = window->y;
|
slouken@6848
|
1132 |
rect.size.width = window->w;
|
slouken@6848
|
1133 |
rect.size.height = window->h;
|
slouken@8986
|
1134 |
ConvertNSRect([screens objectAtIndex:0], (window->flags & FULLSCREEN_MASK), &rect);
|
slouken@1933
|
1135 |
|
slouken@6848
|
1136 |
style = GetWindowStyle(window);
|
slouken@1933
|
1137 |
|
slouken@6848
|
1138 |
/* Figure out which screen to place this window */
|
slouken@6848
|
1139 |
NSScreen *screen = nil;
|
slouken@8986
|
1140 |
for (NSScreen *candidate in screens) {
|
slouken@6848
|
1141 |
NSRect screenRect = [candidate frame];
|
slouken@6848
|
1142 |
if (rect.origin.x >= screenRect.origin.x &&
|
slouken@6848
|
1143 |
rect.origin.x < screenRect.origin.x + screenRect.size.width &&
|
slouken@6848
|
1144 |
rect.origin.y >= screenRect.origin.y &&
|
slouken@6848
|
1145 |
rect.origin.y < screenRect.origin.y + screenRect.size.height) {
|
slouken@6848
|
1146 |
screen = candidate;
|
slouken@6848
|
1147 |
rect.origin.x -= screenRect.origin.x;
|
slouken@6848
|
1148 |
rect.origin.y -= screenRect.origin.y;
|
slouken@3506
|
1149 |
}
|
slouken@6848
|
1150 |
}
|
slouken@7946
|
1151 |
|
slouken@7946
|
1152 |
@try {
|
slouken@7946
|
1153 |
nswindow = [[SDLWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:NO screen:screen];
|
slouken@7946
|
1154 |
}
|
slouken@7946
|
1155 |
@catch (NSException *e) {
|
slime73@9587
|
1156 |
return SDL_SetError("%s", [[e reason] UTF8String]);
|
slouken@7946
|
1157 |
}
|
icculus@7205
|
1158 |
[nswindow setBackgroundColor:[NSColor blackColor]];
|
icculus@8284
|
1159 |
|
icculus@8295
|
1160 |
if (videodata->allow_spaces) {
|
slouken@8986
|
1161 |
SDL_assert(floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6);
|
icculus@8295
|
1162 |
SDL_assert([nswindow respondsToSelector:@selector(toggleFullScreen:)]);
|
icculus@8284
|
1163 |
/* we put FULLSCREEN_DESKTOP windows in their own Space, without a toggle button or menubar, later */
|
icculus@8284
|
1164 |
if (window->flags & SDL_WINDOW_RESIZABLE) {
|
icculus@8284
|
1165 |
/* resizable windows are Spaces-friendly: they get the "go fullscreen" toggle button on their titlebar. */
|
slouken@7968
|
1166 |
[nswindow setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
slouken@7968
|
1167 |
}
|
slouken@7955
|
1168 |
}
|
slouken@1933
|
1169 |
|
slouken@7191
|
1170 |
/* Create a default view for this window */
|
slouken@6848
|
1171 |
rect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
icculus@9623
|
1172 |
SDLView *contentView = [[SDLView alloc] initWithFrame:rect];
|
icculus@9623
|
1173 |
[contentView setSDLWindow:window];
|
urkle@7746
|
1174 |
|
slouken@7955
|
1175 |
if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
|
urkle@7746
|
1176 |
if ([contentView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
|
urkle@7746
|
1177 |
[contentView setWantsBestResolutionOpenGLSurface:YES];
|
urkle@7746
|
1178 |
}
|
urkle@7746
|
1179 |
}
|
urkle@7746
|
1180 |
|
slouken@6848
|
1181 |
[nswindow setContentView: contentView];
|
slouken@6848
|
1182 |
[contentView release];
|
slouken@6489
|
1183 |
|
jorgen@9237
|
1184 |
/* Allow files and folders to be dragged onto the window by users */
|
jorgen@9237
|
1185 |
[nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
|
jorgen@9237
|
1186 |
|
slouken@6848
|
1187 |
if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
|
slouken@6848
|
1188 |
[nswindow release];
|
slouken@6848
|
1189 |
return -1;
|
slouken@1933
|
1190 |
}
|
slouken@6848
|
1191 |
return 0;
|
slime73@9587
|
1192 |
}}
|
slouken@1933
|
1193 |
|
slouken@1933
|
1194 |
int
|
slouken@1933
|
1195 |
Cocoa_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
|
slime73@9587
|
1196 |
{ @autoreleasepool
|
slouken@1933
|
1197 |
{
|
slouken@1933
|
1198 |
NSWindow *nswindow = (NSWindow *) data;
|
slouken@1933
|
1199 |
NSString *title;
|
slouken@1933
|
1200 |
|
slouken@6848
|
1201 |
/* Query the title from the existing window */
|
slouken@6848
|
1202 |
title = [nswindow title];
|
slouken@6848
|
1203 |
if (title) {
|
slouken@6848
|
1204 |
window->title = SDL_strdup([title UTF8String]);
|
slouken@1933
|
1205 |
}
|
slouken@1933
|
1206 |
|
slouken@1951
|
1207 |
return SetupWindowData(_this, window, nswindow, SDL_FALSE);
|
slime73@9587
|
1208 |
}}
|
slouken@1933
|
1209 |
|
slouken@1933
|
1210 |
void
|
slouken@1933
|
1211 |
Cocoa_SetWindowTitle(_THIS, SDL_Window * window)
|
slime73@9587
|
1212 |
{ @autoreleasepool
|
slouken@1933
|
1213 |
{
|
slouken@6848
|
1214 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
icculus@9474
|
1215 |
NSString *string = [[NSString alloc] initWithUTF8String:window->title];
|
slouken@6848
|
1216 |
[nswindow setTitle:string];
|
slouken@6848
|
1217 |
[string release];
|
slime73@9587
|
1218 |
}}
|
slouken@1933
|
1219 |
|
slouken@1933
|
1220 |
void
|
slouken@5375
|
1221 |
Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon)
|
slime73@9587
|
1222 |
{ @autoreleasepool
|
slouken@5375
|
1223 |
{
|
slouken@6848
|
1224 |
NSImage *nsimage = Cocoa_CreateImage(icon);
|
slouken@5375
|
1225 |
|
slouken@6848
|
1226 |
if (nsimage) {
|
slouken@6848
|
1227 |
[NSApp setApplicationIconImage:nsimage];
|
slouken@5375
|
1228 |
}
|
slime73@9587
|
1229 |
}}
|
slouken@5375
|
1230 |
|
slouken@5375
|
1231 |
void
|
slouken@1933
|
1232 |
Cocoa_SetWindowPosition(_THIS, SDL_Window * window)
|
slime73@9587
|
1233 |
{ @autoreleasepool
|
slouken@1933
|
1234 |
{
|
jorgen@7594
|
1235 |
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
jorgen@7594
|
1236 |
NSWindow *nswindow = windata->nswindow;
|
slouken@6848
|
1237 |
NSRect rect;
|
slouken@6848
|
1238 |
Uint32 moveHack;
|
slouken@6848
|
1239 |
|
slouken@6848
|
1240 |
rect.origin.x = window->x;
|
slouken@6848
|
1241 |
rect.origin.y = window->y;
|
slouken@6848
|
1242 |
rect.size.width = window->w;
|
slouken@6848
|
1243 |
rect.size.height = window->h;
|
slouken@8801
|
1244 |
ConvertNSRect([nswindow screen], (window->flags & FULLSCREEN_MASK), &rect);
|
slouken@5478
|
1245 |
|
slouken@6848
|
1246 |
moveHack = s_moveHack;
|
slouken@6848
|
1247 |
s_moveHack = 0;
|
slouken@6848
|
1248 |
[nswindow setFrameOrigin:rect.origin];
|
slouken@6848
|
1249 |
s_moveHack = moveHack;
|
slouken@5478
|
1250 |
|
jorgen@7595
|
1251 |
ScheduleContextUpdates(windata);
|
slime73@9587
|
1252 |
}}
|
slouken@1933
|
1253 |
|
slouken@1933
|
1254 |
void
|
slouken@1933
|
1255 |
Cocoa_SetWindowSize(_THIS, SDL_Window * window)
|
slime73@9587
|
1256 |
{ @autoreleasepool
|
slouken@1933
|
1257 |
{
|
slouken@6848
|
1258 |
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
slouken@6848
|
1259 |
NSWindow *nswindow = windata->nswindow;
|
slouken@6848
|
1260 |
NSSize size;
|
slouken@1933
|
1261 |
|
slouken@6848
|
1262 |
size.width = window->w;
|
slouken@6848
|
1263 |
size.height = window->h;
|
slouken@6848
|
1264 |
[nswindow setContentSize:size];
|
icculus@5564
|
1265 |
|
jorgen@7595
|
1266 |
ScheduleContextUpdates(windata);
|
slime73@9587
|
1267 |
}}
|
slouken@1933
|
1268 |
|
slouken@1933
|
1269 |
void
|
stopiccot@6681
|
1270 |
Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window)
|
slime73@9587
|
1271 |
{ @autoreleasepool
|
stopiccot@6681
|
1272 |
{
|
slouken@6848
|
1273 |
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
slouken@7191
|
1274 |
|
slouken@6848
|
1275 |
NSSize minSize;
|
slouken@6848
|
1276 |
minSize.width = window->min_w;
|
slouken@6848
|
1277 |
minSize.height = window->min_h;
|
slouken@7191
|
1278 |
|
slouken@6848
|
1279 |
[windata->nswindow setContentMinSize:minSize];
|
slime73@9587
|
1280 |
}}
|
slouken@6788
|
1281 |
|
slouken@6788
|
1282 |
void
|
slouken@6788
|
1283 |
Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window)
|
slime73@9587
|
1284 |
{ @autoreleasepool
|
slouken@6788
|
1285 |
{
|
slouken@6848
|
1286 |
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
slouken@7191
|
1287 |
|
slouken@6848
|
1288 |
NSSize maxSize;
|
slouken@6848
|
1289 |
maxSize.width = window->max_w;
|
slouken@6848
|
1290 |
maxSize.height = window->max_h;
|
slouken@7191
|
1291 |
|
slouken@6848
|
1292 |
[windata->nswindow setContentMaxSize:maxSize];
|
slime73@9587
|
1293 |
}}
|
stopiccot@6681
|
1294 |
|
stopiccot@6681
|
1295 |
void
|
slouken@1933
|
1296 |
Cocoa_ShowWindow(_THIS, SDL_Window * window)
|
slime73@9587
|
1297 |
{ @autoreleasepool
|
slouken@1933
|
1298 |
{
|
jorgen@7087
|
1299 |
SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
|
jorgen@7087
|
1300 |
NSWindow *nswindow = windowData->nswindow;
|
slouken@1933
|
1301 |
|
slouken@6848
|
1302 |
if (![nswindow isMiniaturized]) {
|
jorgen@7087
|
1303 |
[windowData->listener pauseVisibleObservation];
|
slouken@6848
|
1304 |
[nswindow makeKeyAndOrderFront:nil];
|
jorgen@7087
|
1305 |
[windowData->listener resumeVisibleObservation];
|
slouken@1956
|
1306 |
}
|
slime73@9587
|
1307 |
}}
|
slouken@1933
|
1308 |
|
slouken@1933
|
1309 |
void
|
slouken@1933
|
1310 |
Cocoa_HideWindow(_THIS, SDL_Window * window)
|
slime73@9587
|
1311 |
{ @autoreleasepool
|
slouken@1933
|
1312 |
{
|
slouken@6848
|
1313 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
slouken@6848
|
1314 |
|
slouken@6848
|
1315 |
[nswindow orderOut:nil];
|
slime73@9587
|
1316 |
}}
|
slouken@1933
|
1317 |
|
slouken@1933
|
1318 |
void
|
slouken@1933
|
1319 |
Cocoa_RaiseWindow(_THIS, SDL_Window * window)
|
slime73@9587
|
1320 |
{ @autoreleasepool
|
slouken@1933
|
1321 |
{
|
jorgen@7087
|
1322 |
SDL_WindowData *windowData = ((SDL_WindowData *) window->driverdata);
|
jorgen@7087
|
1323 |
NSWindow *nswindow = windowData->nswindow;
|
slouken@6848
|
1324 |
|
slouken@7771
|
1325 |
/* makeKeyAndOrderFront: has the side-effect of deminiaturizing and showing
|
slouken@7771
|
1326 |
a minimized or hidden window, so check for that before showing it.
|
slouken@7771
|
1327 |
*/
|
jorgen@7087
|
1328 |
[windowData->listener pauseVisibleObservation];
|
jorgen@7469
|
1329 |
if (![nswindow isMiniaturized] && [nswindow isVisible]) {
|
alfred@9041
|
1330 |
[NSApp activateIgnoringOtherApps:YES];
|
jorgen@7469
|
1331 |
[nswindow makeKeyAndOrderFront:nil];
|
jorgen@7469
|
1332 |
}
|
jorgen@7087
|
1333 |
[windowData->listener resumeVisibleObservation];
|
slime73@9587
|
1334 |
}}
|
slouken@1933
|
1335 |
|
slouken@1933
|
1336 |
void
|
slouken@1933
|
1337 |
Cocoa_MaximizeWindow(_THIS, SDL_Window * window)
|
slime73@9587
|
1338 |
{ @autoreleasepool
|
slouken@1933
|
1339 |
{
|
jorgen@7594
|
1340 |
SDL_WindowData *windata = (SDL_WindowData *) window->driverdata;
|
jorgen@7594
|
1341 |
NSWindow *nswindow = windata->nswindow;
|
slouken@6848
|
1342 |
|
slouken@6848
|
1343 |
[nswindow zoom:nil];
|
icculus@5564
|
1344 |
|
jorgen@7595
|
1345 |
ScheduleContextUpdates(windata);
|
slime73@9587
|
1346 |
}}
|
slouken@1933
|
1347 |
|
slouken@1933
|
1348 |
void
|
slouken@1933
|
1349 |
Cocoa_MinimizeWindow(_THIS, SDL_Window * window)
|
slime73@9587
|
1350 |
{ @autoreleasepool
|
slouken@1933
|
1351 |
{
|
slouken@7963
|
1352 |
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
slouken@7963
|
1353 |
NSWindow *nswindow = data->nswindow;
|
slouken@6848
|
1354 |
|
slouken@7968
|
1355 |
if ([data->listener isInFullscreenSpaceTransition]) {
|
slouken@7963
|
1356 |
[data->listener addPendingWindowOperation:PENDING_OPERATION_MINIMIZE];
|
slouken@7963
|
1357 |
} else {
|
slouken@7963
|
1358 |
[nswindow miniaturize:nil];
|
slouken@7963
|
1359 |
}
|
slime73@9587
|
1360 |
}}
|
slouken@1933
|
1361 |
|
slouken@1933
|
1362 |
void
|
slouken@1933
|
1363 |
Cocoa_RestoreWindow(_THIS, SDL_Window * window)
|
slime73@9587
|
1364 |
{ @autoreleasepool
|
slouken@1933
|
1365 |
{
|
slouken@6848
|
1366 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
slouken@1933
|
1367 |
|
slouken@6848
|
1368 |
if ([nswindow isMiniaturized]) {
|
slouken@6848
|
1369 |
[nswindow deminiaturize:nil];
|
slouken@6848
|
1370 |
} else if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
|
slouken@6848
|
1371 |
[nswindow zoom:nil];
|
slouken@1956
|
1372 |
}
|
slime73@9587
|
1373 |
}}
|
slouken@1933
|
1374 |
|
slouken@5400
|
1375 |
static NSWindow *
|
slouken@5400
|
1376 |
Cocoa_RebuildWindow(SDL_WindowData * data, NSWindow * nswindow, unsigned style)
|
slouken@5400
|
1377 |
{
|
slouken@5400
|
1378 |
if (!data->created) {
|
slouken@5400
|
1379 |
/* Don't mess with other people's windows... */
|
slouken@5400
|
1380 |
return nswindow;
|
slouken@5400
|
1381 |
}
|
slouken@5400
|
1382 |
|
slouken@5400
|
1383 |
[data->listener close];
|
jorgen@7085
|
1384 |
data->nswindow = [[SDLWindow alloc] initWithContentRect:[[nswindow contentView] frame] styleMask:style backing:NSBackingStoreBuffered defer:NO screen:[nswindow screen]];
|
slouken@5400
|
1385 |
[data->nswindow setContentView:[nswindow contentView]];
|
jorgen@9237
|
1386 |
[data->nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
|
jorgen@7085
|
1387 |
/* See comment in SetupWindowData. */
|
jorgen@7085
|
1388 |
[data->nswindow setOneShot:NO];
|
slouken@5400
|
1389 |
[data->listener listen:data];
|
slouken@5400
|
1390 |
|
slouken@5400
|
1391 |
[nswindow close];
|
slouken@5400
|
1392 |
|
slouken@5400
|
1393 |
return data->nswindow;
|
slouken@5400
|
1394 |
}
|
slouken@5400
|
1395 |
|
slouken@1933
|
1396 |
void
|
icculus@6422
|
1397 |
Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
|
slime73@9587
|
1398 |
{ @autoreleasepool
|
icculus@6422
|
1399 |
{
|
slouken@7990
|
1400 |
if (SetWindowStyle(window, GetWindowStyle(window))) {
|
slouken@6848
|
1401 |
if (bordered) {
|
slouken@7191
|
1402 |
Cocoa_SetWindowTitle(_this, window); /* this got blanked out. */
|
icculus@6426
|
1403 |
}
|
icculus@6422
|
1404 |
}
|
slime73@9587
|
1405 |
}}
|
icculus@6422
|
1406 |
|
slouken@7952
|
1407 |
|
slouken@7968
|
1408 |
void
|
slouken@7968
|
1409 |
Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
|
slime73@9587
|
1410 |
{ @autoreleasepool
|
slouken@7952
|
1411 |
{
|
slouken@6848
|
1412 |
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
slouken@6848
|
1413 |
NSWindow *nswindow = data->nswindow;
|
slouken@6848
|
1414 |
NSRect rect;
|
slouken@6848
|
1415 |
|
slouken@6848
|
1416 |
/* The view responder chain gets messed with during setStyleMask */
|
slouken@6848
|
1417 |
if ([[nswindow contentView] nextResponder] == data->listener) {
|
slouken@6848
|
1418 |
[[nswindow contentView] setNextResponder:nil];
|
slouken@6848
|
1419 |
}
|
slouken@5502
|
1420 |
|
slouken@6848
|
1421 |
if (fullscreen) {
|
slouken@6848
|
1422 |
SDL_Rect bounds;
|
slouken@6848
|
1423 |
|
slouken@6848
|
1424 |
Cocoa_GetDisplayBounds(_this, display, &bounds);
|
slouken@6848
|
1425 |
rect.origin.x = bounds.x;
|
slouken@6848
|
1426 |
rect.origin.y = bounds.y;
|
slouken@6848
|
1427 |
rect.size.width = bounds.w;
|
slouken@6848
|
1428 |
rect.size.height = bounds.h;
|
slouken@8801
|
1429 |
ConvertNSRect([nswindow screen], fullscreen, &rect);
|
slouken@6848
|
1430 |
|
slouken@6848
|
1431 |
/* Hack to fix origin on Mac OS X 10.4 */
|
slouken@6848
|
1432 |
NSRect screenRect = [[nswindow screen] frame];
|
slouken@6848
|
1433 |
if (screenRect.size.height >= 1.0f) {
|
slouken@6848
|
1434 |
rect.origin.y += (screenRect.size.height - rect.size.height);
|
slouken@5401
|
1435 |
}
|
slouken@5401
|
1436 |
|
slouken@6848
|
1437 |
if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
|
slouken@6848
|
1438 |
[nswindow performSelector: @selector(setStyleMask:) withObject: (id)NSBorderlessWindowMask];
|
slouken@5400
|
1439 |
} else {
|
slouken@6848
|
1440 |
nswindow = Cocoa_RebuildWindow(data, nswindow, NSBorderlessWindowMask);
|
slouken@6848
|
1441 |
}
|
slouken@6848
|
1442 |
} else {
|
slouken@6848
|
1443 |
rect.origin.x = window->windowed.x;
|
slouken@6848
|
1444 |
rect.origin.y = window->windowed.y;
|
slouken@6848
|
1445 |
rect.size.width = window->windowed.w;
|
slouken@6848
|
1446 |
rect.size.height = window->windowed.h;
|
slouken@8801
|
1447 |
ConvertNSRect([nswindow screen], fullscreen, &rect);
|
alexey@6832
|
1448 |
|
slouken@6848
|
1449 |
if ([nswindow respondsToSelector: @selector(setStyleMask:)]) {
|
slouken@6848
|
1450 |
[nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)GetWindowStyle(window)];
|
slouken@5400
|
1451 |
} else {
|
slouken@6848
|
1452 |
nswindow = Cocoa_RebuildWindow(data, nswindow, GetWindowStyle(window));
|
slouken@5361
|
1453 |
}
|
slouken@5398
|
1454 |
}
|
slouken@6848
|
1455 |
|
slouken@6848
|
1456 |
/* The view responder chain gets messed with during setStyleMask */
|
slouken@6848
|
1457 |
if ([[nswindow contentView] nextResponder] != data->listener) {
|
slouken@6848
|
1458 |
[[nswindow contentView] setNextResponder:data->listener];
|
slouken@6848
|
1459 |
}
|
slouken@6848
|
1460 |
|
slouken@6848
|
1461 |
s_moveHack = 0;
|
slouken@7873
|
1462 |
[nswindow setContentSize:rect.size];
|
slouken@6848
|
1463 |
[nswindow setFrameOrigin:rect.origin];
|
slouken@6848
|
1464 |
s_moveHack = SDL_GetTicks();
|
slouken@6848
|
1465 |
|
slouken@6848
|
1466 |
/* When the window style changes the title is cleared */
|
slouken@6848
|
1467 |
if (!fullscreen) {
|
slouken@6848
|
1468 |
Cocoa_SetWindowTitle(_this, window);
|
slouken@6848
|
1469 |
}
|
slouken@6848
|
1470 |
|
slouken@6848
|
1471 |
if (SDL_ShouldAllowTopmost() && fullscreen) {
|
slouken@6848
|
1472 |
/* OpenGL is rendering to the window, so make it visible! */
|
slouken@6848
|
1473 |
[nswindow setLevel:CGShieldingWindowLevel()];
|
slouken@6848
|
1474 |
} else {
|
slouken@6848
|
1475 |
[nswindow setLevel:kCGNormalWindowLevel];
|
slouken@6848
|
1476 |
}
|
jorgen@7087
|
1477 |
|
jorgen@7636
|
1478 |
if ([nswindow isVisible] || fullscreen) {
|
jorgen@7636
|
1479 |
[data->listener pauseVisibleObservation];
|
jorgen@7636
|
1480 |
[nswindow makeKeyAndOrderFront:nil];
|
jorgen@7636
|
1481 |
[data->listener resumeVisibleObservation];
|
jorgen@7636
|
1482 |
}
|
slouken@6848
|
1483 |
|
jorgen@7595
|
1484 |
ScheduleContextUpdates(data);
|
slime73@9587
|
1485 |
}}
|
slouken@5249
|
1486 |
|
slouken@5466
|
1487 |
int
|
slouken@5466
|
1488 |
Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp)
|
slouken@5466
|
1489 |
{
|
slouken@5466
|
1490 |
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
slouken@5466
|
1491 |
CGDirectDisplayID display_id = ((SDL_DisplayData *)display->driverdata)->display;
|
slouken@5466
|
1492 |
const uint32_t tableSize = 256;
|
slouken@5466
|
1493 |
CGGammaValue redTable[tableSize];
|
slouken@5466
|
1494 |
CGGammaValue greenTable[tableSize];
|
slouken@5466
|
1495 |
CGGammaValue blueTable[tableSize];
|
slouken@5466
|
1496 |
uint32_t i;
|
slouken@5466
|
1497 |
float inv65535 = 1.0f / 65535.0f;
|
slouken@5466
|
1498 |
|
slouken@5466
|
1499 |
/* Extract gamma values into separate tables, convert to floats between 0.0 and 1.0 */
|
slouken@5466
|
1500 |
for (i = 0; i < 256; i++) {
|
slouken@5466
|
1501 |
redTable[i] = ramp[0*256+i] * inv65535;
|
slouken@5466
|
1502 |
greenTable[i] = ramp[1*256+i] * inv65535;
|
slouken@5466
|
1503 |
blueTable[i] = ramp[2*256+i] * inv65535;
|
slouken@5466
|
1504 |
}
|
slouken@5466
|
1505 |
|
slouken@5466
|
1506 |
if (CGSetDisplayTransferByTable(display_id, tableSize,
|
slouken@5466
|
1507 |
redTable, greenTable, blueTable) != CGDisplayNoErr) {
|
icculus@7037
|
1508 |
return SDL_SetError("CGSetDisplayTransferByTable()");
|
slouken@5466
|
1509 |
}
|
slouken@5466
|
1510 |
return 0;
|
slouken@5466
|
1511 |
}
|
slouken@5466
|
1512 |
|
slouken@5466
|
1513 |
int
|
slouken@5466
|
1514 |
Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp)
|
slouken@5466
|
1515 |
{
|
slouken@5466
|
1516 |
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
|
slouken@5466
|
1517 |
CGDirectDisplayID display_id = ((SDL_DisplayData *)display->driverdata)->display;
|
slouken@5466
|
1518 |
const uint32_t tableSize = 256;
|
slouken@5466
|
1519 |
CGGammaValue redTable[tableSize];
|
slouken@5466
|
1520 |
CGGammaValue greenTable[tableSize];
|
slouken@5466
|
1521 |
CGGammaValue blueTable[tableSize];
|
slouken@5466
|
1522 |
uint32_t i, tableCopied;
|
slouken@5466
|
1523 |
|
slouken@5466
|
1524 |
if (CGGetDisplayTransferByTable(display_id, tableSize,
|
slouken@5466
|
1525 |
redTable, greenTable, blueTable, &tableCopied) != CGDisplayNoErr) {
|
icculus@7037
|
1526 |
return SDL_SetError("CGGetDisplayTransferByTable()");
|
slouken@5466
|
1527 |
}
|
slouken@5466
|
1528 |
|
slouken@5466
|
1529 |
for (i = 0; i < tableCopied; i++) {
|
slouken@5466
|
1530 |
ramp[0*256+i] = (Uint16)(redTable[i] * 65535.0f);
|
slouken@5466
|
1531 |
ramp[1*256+i] = (Uint16)(greenTable[i] * 65535.0f);
|
slouken@5466
|
1532 |
ramp[2*256+i] = (Uint16)(blueTable[i] * 65535.0f);
|
slouken@5466
|
1533 |
}
|
slouken@5466
|
1534 |
return 0;
|
slouken@5466
|
1535 |
}
|
slouken@5466
|
1536 |
|
slouken@5249
|
1537 |
void
|
slouken@6662
|
1538 |
Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
|
slouken@1933
|
1539 |
{
|
slouken@5371
|
1540 |
/* Move the cursor to the nearest point in the window */
|
jorgen@8260
|
1541 |
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
jorgen@8260
|
1542 |
if (grabbed && data && ![data->listener isMoving]) {
|
slouken@5371
|
1543 |
int x, y;
|
slouken@5371
|
1544 |
CGPoint cgpoint;
|
slouken@5371
|
1545 |
|
slouken@5371
|
1546 |
SDL_GetMouseState(&x, &y);
|
slouken@5371
|
1547 |
cgpoint.x = window->x + x;
|
slouken@5371
|
1548 |
cgpoint.y = window->y + y;
|
jorgen@8261
|
1549 |
|
jorgen@8261
|
1550 |
Cocoa_HandleMouseWarp(cgpoint.x, cgpoint.y);
|
jorgen@8261
|
1551 |
|
jorgen@8261
|
1552 |
DLog("Returning cursor to (%g, %g)", cgpoint.x, cgpoint.y);
|
slouken@5371
|
1553 |
CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
|
slouken@5371
|
1554 |
}
|
slouken@7191
|
1555 |
|
icculus@8652
|
1556 |
if ( data && (window->flags & SDL_WINDOW_FULLSCREEN) ) {
|
slouken@7191
|
1557 |
if (SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
|
slouken@7191
|
1558 |
/* OpenGL is rendering to the window, so make it visible! */
|
slouken@7191
|
1559 |
[data->nswindow setLevel:CGShieldingWindowLevel()];
|
slouken@7191
|
1560 |
} else {
|
slouken@7191
|
1561 |
[data->nswindow setLevel:kCGNormalWindowLevel];
|
slouken@7191
|
1562 |
}
|
slouken@7191
|
1563 |
}
|
slouken@1933
|
1564 |
}
|
slouken@1933
|
1565 |
|
slouken@1933
|
1566 |
void
|
slouken@1933
|
1567 |
Cocoa_DestroyWindow(_THIS, SDL_Window * window)
|
slime73@9587
|
1568 |
{ @autoreleasepool
|
slouken@1933
|
1569 |
{
|
slouken@6848
|
1570 |
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
slouken@1933
|
1571 |
|
slouken@6848
|
1572 |
if (data) {
|
slouken@6848
|
1573 |
[data->listener close];
|
slouken@6848
|
1574 |
[data->listener release];
|
slouken@6848
|
1575 |
if (data->created) {
|
slouken@6848
|
1576 |
[data->nswindow close];
|
slouken@1933
|
1577 |
}
|
jorgen@7595
|
1578 |
|
jorgen@7595
|
1579 |
NSArray *contexts = [[data->nscontexts copy] autorelease];
|
jorgen@7595
|
1580 |
for (SDLOpenGLContext *context in contexts) {
|
jorgen@7595
|
1581 |
/* Calling setWindow:NULL causes the context to remove itself from the context list. */
|
jorgen@7595
|
1582 |
[context setWindow:NULL];
|
jorgen@7595
|
1583 |
}
|
jorgen@7595
|
1584 |
[data->nscontexts release];
|
jorgen@7595
|
1585 |
|
slouken@6848
|
1586 |
SDL_free(data);
|
slouken@1933
|
1587 |
}
|
slouken@8978
|
1588 |
window->driverdata = NULL;
|
slime73@9587
|
1589 |
}}
|
slouken@1933
|
1590 |
|
slouken@1933
|
1591 |
SDL_bool
|
slouken@1933
|
1592 |
Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
|
slouken@1933
|
1593 |
{
|
slouken@4900
|
1594 |
NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
|
slouken@1933
|
1595 |
|
slouken@1933
|
1596 |
if (info->version.major <= SDL_MAJOR_VERSION) {
|
slouken@4900
|
1597 |
info->subsystem = SDL_SYSWM_COCOA;
|
slouken@5056
|
1598 |
info->info.cocoa.window = nswindow;
|
slouken@1933
|
1599 |
return SDL_TRUE;
|
slouken@1933
|
1600 |
} else {
|
slouken@1933
|
1601 |
SDL_SetError("Application not compiled with SDL %d.%d\n",
|
slouken@1933
|
1602 |
SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
|
slouken@1933
|
1603 |
return SDL_FALSE;
|
slouken@1933
|
1604 |
}
|
slouken@1933
|
1605 |
}
|
slouken@1933
|
1606 |
|
slouken@7968
|
1607 |
SDL_bool
|
slouken@7969
|
1608 |
Cocoa_IsWindowInFullscreenSpace(SDL_Window * window)
|
slouken@7969
|
1609 |
{
|
slouken@7969
|
1610 |
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
slouken@7969
|
1611 |
|
slouken@7969
|
1612 |
if ([data->listener isInFullscreenSpace]) {
|
slouken@7969
|
1613 |
return SDL_TRUE;
|
slouken@7969
|
1614 |
} else {
|
slouken@7969
|
1615 |
return SDL_FALSE;
|
slouken@7969
|
1616 |
}
|
slouken@7969
|
1617 |
}
|
slouken@7969
|
1618 |
|
slouken@7969
|
1619 |
SDL_bool
|
slouken@7968
|
1620 |
Cocoa_SetWindowFullscreenSpace(SDL_Window * window, SDL_bool state)
|
slime73@9587
|
1621 |
{ @autoreleasepool
|
slouken@7968
|
1622 |
{
|
slouken@7968
|
1623 |
SDL_bool succeeded = SDL_FALSE;
|
slouken@7968
|
1624 |
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
slouken@7968
|
1625 |
|
slouken@7968
|
1626 |
if ([data->listener setFullscreenSpace:(state ? YES : NO)]) {
|
slouken@7968
|
1627 |
succeeded = SDL_TRUE;
|
slouken@8810
|
1628 |
|
slouken@8810
|
1629 |
/* Wait for the transition to complete, so application changes
|
slouken@8810
|
1630 |
take effect properly (e.g. setting the window size, etc.)
|
slouken@8810
|
1631 |
*/
|
slouken@8810
|
1632 |
const int limit = 10000;
|
slouken@8810
|
1633 |
int count = 0;
|
slouken@8810
|
1634 |
while ([data->listener isInFullscreenSpaceTransition]) {
|
slouken@8810
|
1635 |
if ( ++count == limit ) {
|
slouken@8810
|
1636 |
/* Uh oh, transition isn't completing. Should we assert? */
|
slouken@8810
|
1637 |
break;
|
slouken@8810
|
1638 |
}
|
slouken@8810
|
1639 |
SDL_Delay(1);
|
slouken@8810
|
1640 |
SDL_PumpEvents();
|
slouken@8810
|
1641 |
}
|
slouken@7968
|
1642 |
}
|
slouken@7968
|
1643 |
|
slouken@7968
|
1644 |
return succeeded;
|
slime73@9587
|
1645 |
}}
|
slouken@7968
|
1646 |
|
icculus@8931
|
1647 |
int
|
icculus@8935
|
1648 |
Cocoa_SetWindowHitTest(SDL_Window * window, SDL_bool enabled)
|
icculus@8931
|
1649 |
{
|
icculus@8931
|
1650 |
return 0; /* just succeed, the real work is done elsewhere. */
|
icculus@8931
|
1651 |
}
|
icculus@8931
|
1652 |
|
slouken@6044
|
1653 |
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
slouken@6044
|
1654 |
|
slouken@1933
|
1655 |
/* vi: set ts=4 sw=4 expandtab: */
|