slouken@1931
|
1 |
/*
|
slouken@5535
|
2 |
Simple DirectMedia Layer
|
slouken@9619
|
3 |
Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
|
slouken@1931
|
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@1931
|
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@1931
|
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@1931
|
20 |
*/
|
icculus@8093
|
21 |
#include "../../SDL_internal.h"
|
slouken@6044
|
22 |
|
slouken@6044
|
23 |
#if SDL_VIDEO_DRIVER_COCOA
|
slouken@3120
|
24 |
#include "SDL_timer.h"
|
slouken@1931
|
25 |
|
slouken@1931
|
26 |
#include "SDL_cocoavideo.h"
|
slouken@2738
|
27 |
#include "../../events/SDL_events_c.h"
|
icculus@8648
|
28 |
#include "SDL_assert.h"
|
alfred@9820
|
29 |
#include "SDL_hints.h"
|
slouken@1931
|
30 |
|
icculus@9364
|
31 |
/* This define was added in the 10.9 SDK. */
|
icculus@9364
|
32 |
#ifndef kIOPMAssertPreventUserIdleDisplaySleep
|
icculus@9364
|
33 |
#define kIOPMAssertPreventUserIdleDisplaySleep kIOPMAssertionTypePreventUserIdleDisplaySleep
|
icculus@9364
|
34 |
#endif
|
icculus@9364
|
35 |
|
slouken@8239
|
36 |
@interface SDLApplication : NSApplication
|
slouken@8239
|
37 |
|
slouken@8239
|
38 |
- (void)terminate:(id)sender;
|
slouken@8239
|
39 |
|
slouken@8239
|
40 |
@end
|
slouken@8239
|
41 |
|
slouken@8239
|
42 |
@implementation SDLApplication
|
slouken@8239
|
43 |
|
slouken@8239
|
44 |
// Override terminate to handle Quit and System Shutdown smoothly.
|
slouken@8239
|
45 |
- (void)terminate:(id)sender
|
slouken@8239
|
46 |
{
|
slouken@8239
|
47 |
SDL_SendQuit();
|
slouken@8239
|
48 |
}
|
slouken@8239
|
49 |
|
slouken@8239
|
50 |
@end // SDLApplication
|
slouken@8239
|
51 |
|
slouken@1931
|
52 |
/* setAppleMenu disappeared from the headers in 10.4 */
|
slouken@1931
|
53 |
@interface NSApplication(NSAppleMenu)
|
slouken@1931
|
54 |
- (void)setAppleMenu:(NSMenu *)menu;
|
slouken@1931
|
55 |
@end
|
slouken@1931
|
56 |
|
slouken@8986
|
57 |
@interface SDLAppDelegate : NSObject <NSApplicationDelegate> {
|
jorgen@7801
|
58 |
@public
|
jorgen@7469
|
59 |
BOOL seenFirstActivate;
|
jorgen@7469
|
60 |
}
|
jorgen@7469
|
61 |
|
jorgen@7469
|
62 |
- (id)init;
|
slouken@1937
|
63 |
@end
|
slouken@1937
|
64 |
|
slouken@1937
|
65 |
@implementation SDLAppDelegate : NSObject
|
jorgen@7469
|
66 |
- (id)init
|
jorgen@7469
|
67 |
{
|
jorgen@7469
|
68 |
self = [super init];
|
jorgen@7469
|
69 |
if (self) {
|
icculus@9419
|
70 |
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
icculus@9419
|
71 |
|
jorgen@7469
|
72 |
seenFirstActivate = NO;
|
icculus@9419
|
73 |
|
icculus@9419
|
74 |
[center addObserver:self
|
icculus@9419
|
75 |
selector:@selector(windowWillClose:)
|
icculus@9419
|
76 |
name:NSWindowWillCloseNotification
|
icculus@9419
|
77 |
object:nil];
|
icculus@9419
|
78 |
|
icculus@9419
|
79 |
[center addObserver:self
|
icculus@9419
|
80 |
selector:@selector(focusSomeWindow:)
|
icculus@9419
|
81 |
name:NSApplicationDidBecomeActiveNotification
|
icculus@9419
|
82 |
object:nil];
|
jorgen@7469
|
83 |
}
|
jorgen@7469
|
84 |
|
jorgen@7469
|
85 |
return self;
|
jorgen@7469
|
86 |
}
|
jorgen@7469
|
87 |
|
jorgen@7801
|
88 |
- (void)dealloc
|
jorgen@7801
|
89 |
{
|
icculus@9419
|
90 |
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
icculus@9419
|
91 |
|
icculus@9419
|
92 |
[center removeObserver:self name:NSWindowWillCloseNotification object:nil];
|
icculus@9419
|
93 |
[center removeObserver:self name:NSApplicationDidBecomeActiveNotification object:nil];
|
icculus@9419
|
94 |
|
jorgen@7801
|
95 |
[super dealloc];
|
jorgen@7801
|
96 |
}
|
jorgen@7801
|
97 |
|
icculus@9419
|
98 |
- (void)windowWillClose:(NSNotification *)notification;
|
icculus@9419
|
99 |
{
|
icculus@9419
|
100 |
NSWindow *win = (NSWindow*)[notification object];
|
icculus@9419
|
101 |
|
icculus@9419
|
102 |
if (![win isKeyWindow]) {
|
icculus@9419
|
103 |
return;
|
icculus@9419
|
104 |
}
|
icculus@9419
|
105 |
|
icculus@9419
|
106 |
/* HACK: Make the next window in the z-order key when the key window is
|
icculus@9419
|
107 |
* closed. The custom event loop and/or windowing code we have seems to
|
icculus@9419
|
108 |
* prevent the normal behavior: https://bugzilla.libsdl.org/show_bug.cgi?id=1825
|
icculus@9419
|
109 |
*/
|
icculus@9419
|
110 |
|
icculus@9419
|
111 |
/* +[NSApp orderedWindows] never includes the 'About' window, but we still
|
icculus@9419
|
112 |
* want to try its list first since the behavior in other apps is to only
|
icculus@9419
|
113 |
* make the 'About' window key if no other windows are on-screen.
|
icculus@9419
|
114 |
*/
|
icculus@9419
|
115 |
for (NSWindow *window in [NSApp orderedWindows]) {
|
icculus@9419
|
116 |
if (window != win && [window canBecomeKeyWindow]) {
|
icculus@9419
|
117 |
if ([window respondsToSelector:@selector(isOnActiveSpace)]) {
|
icculus@9419
|
118 |
if (![window isOnActiveSpace]) {
|
icculus@9419
|
119 |
continue;
|
icculus@9419
|
120 |
}
|
icculus@9419
|
121 |
}
|
icculus@9419
|
122 |
[window makeKeyAndOrderFront:self];
|
icculus@9419
|
123 |
return;
|
icculus@9419
|
124 |
}
|
icculus@9419
|
125 |
}
|
icculus@9419
|
126 |
|
icculus@9419
|
127 |
/* If a window wasn't found above, iterate through all visible windows
|
icculus@9419
|
128 |
* (including the 'About' window, if it's shown) and make the first one key.
|
icculus@9419
|
129 |
* Note that +[NSWindow windowNumbersWithOptions:] was added in 10.6.
|
icculus@9419
|
130 |
*/
|
icculus@9419
|
131 |
if ([NSWindow respondsToSelector:@selector(windowNumbersWithOptions:)]) {
|
icculus@9419
|
132 |
/* Get all visible windows in the active Space, in z-order. */
|
icculus@9419
|
133 |
for (NSNumber *num in [NSWindow windowNumbersWithOptions:0]) {
|
icculus@9419
|
134 |
NSWindow *window = [NSApp windowWithWindowNumber:[num integerValue]];
|
icculus@9419
|
135 |
if (window && window != win && [window canBecomeKeyWindow]) {
|
icculus@9419
|
136 |
[window makeKeyAndOrderFront:self];
|
icculus@9419
|
137 |
return;
|
icculus@9419
|
138 |
}
|
icculus@9419
|
139 |
}
|
icculus@9419
|
140 |
}
|
icculus@9419
|
141 |
}
|
icculus@9419
|
142 |
|
jorgen@7801
|
143 |
- (void)focusSomeWindow:(NSNotification *)aNotification
|
jorgen@7466
|
144 |
{
|
jorgen@7469
|
145 |
/* HACK: Ignore the first call. The application gets a
|
jorgen@7469
|
146 |
* applicationDidBecomeActive: a little bit after the first window is
|
jorgen@7469
|
147 |
* created, and if we don't ignore it, a window that has been created with
|
icculus@9419
|
148 |
* SDL_WINDOW_MINIMIZED will ~immediately be restored.
|
jorgen@7469
|
149 |
*/
|
jorgen@7469
|
150 |
if (!seenFirstActivate) {
|
jorgen@7469
|
151 |
seenFirstActivate = YES;
|
jorgen@7469
|
152 |
return;
|
jorgen@7469
|
153 |
}
|
jorgen@7469
|
154 |
|
jorgen@7466
|
155 |
SDL_VideoDevice *device = SDL_GetVideoDevice();
|
slouken@8986
|
156 |
if (device && device->windows) {
|
jorgen@7466
|
157 |
SDL_Window *window = device->windows;
|
jorgen@7466
|
158 |
int i;
|
slouken@8986
|
159 |
for (i = 0; i < device->num_displays; ++i) {
|
jorgen@7466
|
160 |
SDL_Window *fullscreen_window = device->displays[i].fullscreen_window;
|
slouken@8986
|
161 |
if (fullscreen_window) {
|
jorgen@7466
|
162 |
if (fullscreen_window->flags & SDL_WINDOW_MINIMIZED) {
|
jorgen@7466
|
163 |
SDL_RestoreWindow(fullscreen_window);
|
jorgen@7466
|
164 |
}
|
jorgen@7466
|
165 |
return;
|
jorgen@7466
|
166 |
}
|
jorgen@7466
|
167 |
}
|
jorgen@7466
|
168 |
|
jorgen@7466
|
169 |
if (window->flags & SDL_WINDOW_MINIMIZED) {
|
jorgen@7466
|
170 |
SDL_RestoreWindow(window);
|
jorgen@7466
|
171 |
} else {
|
jorgen@7466
|
172 |
SDL_RaiseWindow(window);
|
jorgen@7466
|
173 |
}
|
jorgen@7466
|
174 |
}
|
jorgen@7466
|
175 |
}
|
jorgen@7466
|
176 |
|
slouken@6091
|
177 |
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
|
slouken@6091
|
178 |
{
|
slouken@6091
|
179 |
return (BOOL)SDL_SendDropFile([filename UTF8String]);
|
slouken@6091
|
180 |
}
|
slouken@1937
|
181 |
@end
|
slouken@1937
|
182 |
|
jorgen@7801
|
183 |
static SDLAppDelegate *appDelegate = nil;
|
jorgen@7801
|
184 |
|
slouken@1931
|
185 |
static NSString *
|
slouken@1931
|
186 |
GetApplicationName(void)
|
slouken@1931
|
187 |
{
|
slouken@8237
|
188 |
NSString *appName;
|
slouken@1931
|
189 |
|
slouken@1931
|
190 |
/* Determine the application name */
|
slouken@8237
|
191 |
appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
slouken@8986
|
192 |
if (!appName) {
|
slouken@8237
|
193 |
appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
|
slouken@8986
|
194 |
}
|
slouken@7191
|
195 |
|
slouken@8986
|
196 |
if (![appName length]) {
|
slouken@1931
|
197 |
appName = [[NSProcessInfo processInfo] processName];
|
slouken@8986
|
198 |
}
|
slouken@1931
|
199 |
|
slouken@1931
|
200 |
return appName;
|
slouken@1931
|
201 |
}
|
slouken@1931
|
202 |
|
slouken@1931
|
203 |
static void
|
slouken@1931
|
204 |
CreateApplicationMenus(void)
|
slouken@1931
|
205 |
{
|
slouken@1931
|
206 |
NSString *appName;
|
slouken@1931
|
207 |
NSString *title;
|
slouken@1931
|
208 |
NSMenu *appleMenu;
|
slouken@6515
|
209 |
NSMenu *serviceMenu;
|
slouken@1931
|
210 |
NSMenu *windowMenu;
|
slouken@7952
|
211 |
NSMenu *viewMenu;
|
slouken@1931
|
212 |
NSMenuItem *menuItem;
|
icculus@8653
|
213 |
NSMenu *mainMenu;
|
slouken@7191
|
214 |
|
slouken@7511
|
215 |
if (NSApp == nil) {
|
jorgen@7508
|
216 |
return;
|
jorgen@7508
|
217 |
}
|
icculus@8653
|
218 |
|
icculus@8653
|
219 |
mainMenu = [[NSMenu alloc] init];
|
icculus@8653
|
220 |
|
slouken@1931
|
221 |
/* Create the main menu bar */
|
icculus@8653
|
222 |
[NSApp setMainMenu:mainMenu];
|
icculus@8653
|
223 |
|
icculus@8653
|
224 |
[mainMenu release]; /* we're done with it, let NSApp own it. */
|
icculus@8653
|
225 |
mainMenu = nil;
|
slouken@1931
|
226 |
|
slouken@1931
|
227 |
/* Create the application menu */
|
slouken@1931
|
228 |
appName = GetApplicationName();
|
slouken@1931
|
229 |
appleMenu = [[NSMenu alloc] initWithTitle:@""];
|
slouken@7191
|
230 |
|
slouken@1931
|
231 |
/* Add menu items */
|
slouken@1931
|
232 |
title = [@"About " stringByAppendingString:appName];
|
slouken@1931
|
233 |
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
|
slouken@1931
|
234 |
|
slouken@1931
|
235 |
[appleMenu addItem:[NSMenuItem separatorItem]];
|
slouken@1931
|
236 |
|
slouken@6515
|
237 |
[appleMenu addItemWithTitle:@"Preferences…" action:nil keyEquivalent:@","];
|
slouken@6515
|
238 |
|
slouken@6515
|
239 |
[appleMenu addItem:[NSMenuItem separatorItem]];
|
slouken@6515
|
240 |
|
slouken@6515
|
241 |
serviceMenu = [[NSMenu alloc] initWithTitle:@""];
|
slouken@6515
|
242 |
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""];
|
slouken@6515
|
243 |
[menuItem setSubmenu:serviceMenu];
|
slouken@6515
|
244 |
|
slouken@6515
|
245 |
[NSApp setServicesMenu:serviceMenu];
|
slouken@6836
|
246 |
[serviceMenu release];
|
slouken@5377
|
247 |
|
slouken@5377
|
248 |
[appleMenu addItem:[NSMenuItem separatorItem]];
|
slouken@5377
|
249 |
|
slouken@1931
|
250 |
title = [@"Hide " stringByAppendingString:appName];
|
slouken@6515
|
251 |
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
|
slouken@1931
|
252 |
|
slouken@6515
|
253 |
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
|
slouken@1931
|
254 |
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
|
slouken@1931
|
255 |
|
slouken@1931
|
256 |
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
|
slouken@1931
|
257 |
|
slouken@1931
|
258 |
[appleMenu addItem:[NSMenuItem separatorItem]];
|
slouken@1931
|
259 |
|
slouken@1931
|
260 |
title = [@"Quit " stringByAppendingString:appName];
|
slouken@6515
|
261 |
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
|
slouken@7191
|
262 |
|
slouken@1931
|
263 |
/* Put menu into the menubar */
|
slouken@1931
|
264 |
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
|
slouken@1931
|
265 |
[menuItem setSubmenu:appleMenu];
|
slouken@1931
|
266 |
[[NSApp mainMenu] addItem:menuItem];
|
slouken@1931
|
267 |
[menuItem release];
|
slouken@1931
|
268 |
|
slouken@1931
|
269 |
/* Tell the application object that this is now the application menu */
|
slouken@1931
|
270 |
[NSApp setAppleMenu:appleMenu];
|
slouken@1931
|
271 |
[appleMenu release];
|
slouken@1931
|
272 |
|
slouken@1931
|
273 |
|
slouken@1931
|
274 |
/* Create the window menu */
|
slouken@1931
|
275 |
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
|
slouken@7191
|
276 |
|
slouken@6515
|
277 |
/* Add menu items */
|
slouken@6515
|
278 |
[windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
|
slouken@7191
|
279 |
|
slouken@6515
|
280 |
[windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
|
slouken@6515
|
281 |
|
slouken@1931
|
282 |
/* Put menu into the menubar */
|
slouken@1931
|
283 |
menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
|
slouken@1931
|
284 |
[menuItem setSubmenu:windowMenu];
|
slouken@1931
|
285 |
[[NSApp mainMenu] addItem:menuItem];
|
slouken@1931
|
286 |
[menuItem release];
|
slouken@7191
|
287 |
|
slouken@1931
|
288 |
/* Tell the application object that this is now the window menu */
|
slouken@1931
|
289 |
[NSApp setWindowsMenu:windowMenu];
|
slouken@1931
|
290 |
[windowMenu release];
|
slouken@7952
|
291 |
|
slouken@7952
|
292 |
|
slouken@7952
|
293 |
/* Add the fullscreen view toggle menu option, if supported */
|
slouken@7952
|
294 |
if ([NSApp respondsToSelector:@selector(setPresentationOptions:)]) {
|
slouken@7952
|
295 |
/* Create the view menu */
|
slouken@7952
|
296 |
viewMenu = [[NSMenu alloc] initWithTitle:@"View"];
|
slouken@7952
|
297 |
|
slouken@7952
|
298 |
/* Add menu items */
|
slouken@7952
|
299 |
menuItem = [viewMenu addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
|
slouken@7952
|
300 |
[menuItem setKeyEquivalentModifierMask:NSControlKeyMask | NSCommandKeyMask];
|
slouken@7952
|
301 |
|
slouken@7952
|
302 |
/* Put menu into the menubar */
|
slouken@7952
|
303 |
menuItem = [[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""];
|
slouken@7952
|
304 |
[menuItem setSubmenu:viewMenu];
|
slouken@7952
|
305 |
[[NSApp mainMenu] addItem:menuItem];
|
slouken@7952
|
306 |
[menuItem release];
|
slouken@7952
|
307 |
|
slouken@7952
|
308 |
[viewMenu release];
|
slouken@7952
|
309 |
}
|
slouken@1931
|
310 |
}
|
slouken@1931
|
311 |
|
slouken@1931
|
312 |
void
|
slouken@1931
|
313 |
Cocoa_RegisterApp(void)
|
slouken@9087
|
314 |
{ @autoreleasepool
|
slouken@1931
|
315 |
{
|
icculus@6639
|
316 |
/* This can get called more than once! Be careful what you initialize! */
|
slouken@1931
|
317 |
|
slouken@6848
|
318 |
if (NSApp == nil) {
|
slouken@8239
|
319 |
[SDLApplication sharedApplication];
|
icculus@8648
|
320 |
SDL_assert(NSApp != nil);
|
slouken@1931
|
321 |
|
alfred@9820
|
322 |
const char *hint = SDL_GetHint(SDL_HINT_MAC_BACKGROUND_APP);
|
alfred@9820
|
323 |
if (!hint && *hint != '0') {
|
icculus@9364
|
324 |
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
|
alfred@9820
|
325 |
if ([NSApp respondsToSelector:@selector(setActivationPolicy:)]) {
|
icculus@9364
|
326 |
#endif
|
alfred@9820
|
327 |
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
icculus@9364
|
328 |
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
|
alfred@9820
|
329 |
} else {
|
alfred@9820
|
330 |
ProcessSerialNumber psn = {0, kCurrentProcess};
|
alfred@9820
|
331 |
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
alfred@9820
|
332 |
}
|
icculus@9364
|
333 |
#endif
|
alfred@9820
|
334 |
[NSApp activateIgnoringOtherApps:YES];
|
alfred@9820
|
335 |
}
|
alfred@9820
|
336 |
|
slouken@6848
|
337 |
if ([NSApp mainMenu] == nil) {
|
slouken@6848
|
338 |
CreateApplicationMenus();
|
slouken@1931
|
339 |
}
|
slouken@6848
|
340 |
[NSApp finishLaunching];
|
slouken@8289
|
341 |
NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
|
slouken@8290
|
342 |
[NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
|
slouken@8290
|
343 |
[NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
|
jorgen@8718
|
344 |
[NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
|
slouken@8290
|
345 |
nil];
|
slouken@7739
|
346 |
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
|
icculus@8648
|
347 |
[appDefaults release];
|
slouken@1931
|
348 |
}
|
jorgen@7801
|
349 |
if (NSApp && !appDelegate) {
|
jorgen@7801
|
350 |
appDelegate = [[SDLAppDelegate alloc] init];
|
jorgen@7801
|
351 |
|
jorgen@7801
|
352 |
/* If someone else has an app delegate, it means we can't turn a
|
jorgen@7801
|
353 |
* termination into SDL_Quit, and we can't handle application:openFile:
|
jorgen@7801
|
354 |
*/
|
jorgen@7801
|
355 |
if (![NSApp delegate]) {
|
slouken@8986
|
356 |
[(NSApplication *)NSApp setDelegate:appDelegate];
|
jorgen@7801
|
357 |
} else {
|
jorgen@7801
|
358 |
appDelegate->seenFirstActivate = YES;
|
jorgen@7801
|
359 |
}
|
slouken@6848
|
360 |
}
|
slouken@9087
|
361 |
}}
|
slouken@1931
|
362 |
|
slouken@1931
|
363 |
void
|
slouken@1931
|
364 |
Cocoa_PumpEvents(_THIS)
|
slouken@9087
|
365 |
{ @autoreleasepool
|
slouken@1931
|
366 |
{
|
slouken@3025
|
367 |
/* Update activity every 30 seconds to prevent screensaver */
|
icculus@9364
|
368 |
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
|
icculus@9364
|
369 |
if (_this->suspend_screensaver && !data->screensaver_use_iopm) {
|
slouken@3025
|
370 |
Uint32 now = SDL_GetTicks();
|
slouken@3025
|
371 |
if (!data->screensaver_activity ||
|
slouken@7857
|
372 |
SDL_TICKS_PASSED(now, data->screensaver_activity + 30000)) {
|
slouken@3025
|
373 |
UpdateSystemActivity(UsrActivity);
|
slouken@3025
|
374 |
data->screensaver_activity = now;
|
slouken@3025
|
375 |
}
|
slouken@3025
|
376 |
}
|
slouken@3025
|
377 |
|
slouken@6848
|
378 |
for ( ; ; ) {
|
slouken@6848
|
379 |
NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
|
slouken@6848
|
380 |
if ( event == nil ) {
|
slouken@6848
|
381 |
break;
|
slouken@1931
|
382 |
}
|
slouken@7191
|
383 |
|
slouken@6848
|
384 |
switch ([event type]) {
|
slouken@6848
|
385 |
case NSLeftMouseDown:
|
slouken@6848
|
386 |
case NSOtherMouseDown:
|
slouken@6848
|
387 |
case NSRightMouseDown:
|
slouken@6848
|
388 |
case NSLeftMouseUp:
|
slouken@6848
|
389 |
case NSOtherMouseUp:
|
slouken@6848
|
390 |
case NSRightMouseUp:
|
slouken@6848
|
391 |
case NSLeftMouseDragged:
|
slouken@6848
|
392 |
case NSRightMouseDragged:
|
slouken@6848
|
393 |
case NSOtherMouseDragged: /* usually middle mouse dragged */
|
slouken@6848
|
394 |
case NSMouseMoved:
|
slouken@6848
|
395 |
case NSScrollWheel:
|
slouken@6848
|
396 |
Cocoa_HandleMouseEvent(_this, event);
|
slouken@6848
|
397 |
break;
|
slouken@6848
|
398 |
case NSKeyDown:
|
slouken@6848
|
399 |
case NSKeyUp:
|
slouken@6848
|
400 |
case NSFlagsChanged:
|
slouken@6848
|
401 |
Cocoa_HandleKeyEvent(_this, event);
|
slouken@6848
|
402 |
break;
|
slouken@6848
|
403 |
default:
|
slouken@6848
|
404 |
break;
|
slouken@6848
|
405 |
}
|
slouken@6848
|
406 |
/* Pass through to NSApp to make sure everything stays in sync */
|
slouken@6848
|
407 |
[NSApp sendEvent:event];
|
slouken@1931
|
408 |
}
|
slouken@9087
|
409 |
}}
|
slouken@1931
|
410 |
|
icculus@9364
|
411 |
void
|
icculus@9364
|
412 |
Cocoa_SuspendScreenSaver(_THIS)
|
icculus@9364
|
413 |
{ @autoreleasepool
|
icculus@9364
|
414 |
{
|
icculus@9364
|
415 |
SDL_VideoData *data = (SDL_VideoData *)_this->driverdata;
|
icculus@9364
|
416 |
|
icculus@9364
|
417 |
if (!data->screensaver_use_iopm) {
|
icculus@9364
|
418 |
return;
|
icculus@9364
|
419 |
}
|
icculus@9364
|
420 |
|
icculus@9364
|
421 |
if (data->screensaver_assertion) {
|
icculus@9364
|
422 |
IOPMAssertionRelease(data->screensaver_assertion);
|
icculus@9364
|
423 |
data->screensaver_assertion = 0;
|
icculus@9364
|
424 |
}
|
icculus@9364
|
425 |
|
icculus@9364
|
426 |
if (_this->suspend_screensaver) {
|
icculus@9364
|
427 |
/* FIXME: this should ideally describe the real reason why the game
|
icculus@9364
|
428 |
* called SDL_DisableScreenSaver. Note that the name is only meant to be
|
icculus@9364
|
429 |
* seen by OS X power users. there's an additional optional human-readable
|
icculus@9364
|
430 |
* (localized) reason parameter which we don't set.
|
icculus@9364
|
431 |
*/
|
icculus@9364
|
432 |
NSString *name = [GetApplicationName() stringByAppendingString:@" using SDL_DisableScreenSaver"];
|
icculus@9364
|
433 |
IOPMAssertionCreateWithDescription(kIOPMAssertPreventUserIdleDisplaySleep,
|
icculus@9364
|
434 |
(CFStringRef) name,
|
icculus@9364
|
435 |
NULL, NULL, NULL, 0, NULL,
|
icculus@9364
|
436 |
&data->screensaver_assertion);
|
icculus@9364
|
437 |
}
|
icculus@9364
|
438 |
}}
|
icculus@9364
|
439 |
|
slouken@6044
|
440 |
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
slouken@6044
|
441 |
|
slouken@1931
|
442 |
/* vi: set ts=4 sw=4 expandtab: */
|