21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_COCOA 27 #include "../../events/SDL_events_c.h" 32 #ifndef kIOPMAssertPreventUserIdleDisplaySleep 33 #define kIOPMAssertPreventUserIdleDisplaySleep kIOPMAssertionTypePreventUserIdleDisplaySleep 36 @interface SDLApplication : NSApplication
42 @implementation SDLApplication
53 @interface NSApplication(NSAppleMenu)
54 - (
void)setAppleMenu:(NSMenu *)menu;
57 @interface SDLAppDelegate : NSObject <NSApplicationDelegate> {
59 BOOL seenFirstActivate;
65 @implementation SDLAppDelegate : NSObject
70 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
72 seenFirstActivate = NO;
74 [center addObserver:self
75 selector:@selector(windowWillClose:)
76 name:NSWindowWillCloseNotification
79 [center addObserver:self
80 selector:@selector(focusSomeWindow:)
81 name:NSApplicationDidBecomeActiveNotification
90 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
92 [center removeObserver:self name:NSWindowWillCloseNotification object:nil];
93 [center removeObserver:self name:NSApplicationDidBecomeActiveNotification object:nil];
98 - (
void)windowWillClose:(NSNotification *)notification;
100 NSWindow *win = (NSWindow*)[notification
object];
102 if (![win isKeyWindow]) {
115 for (NSWindow *
window in [NSApp orderedWindows]) {
117 if ([
window respondsToSelector:
@selector(isOnActiveSpace)]) {
118 if (![
window isOnActiveSpace]) {
122 [window makeKeyAndOrderFront:self];
131 if ([NSWindow respondsToSelector:
@selector(windowNumbersWithOptions:)]) {
133 for (NSNumber *
num in [NSWindow windowNumbersWithOptions:0]) {
135 if (window && window != win && [window canBecomeKeyWindow]) {
136 [window makeKeyAndOrderFront:self];
143 - (
void)focusSomeWindow:(NSNotification *)aNotification
150 if (!seenFirstActivate) {
151 seenFirstActivate = YES;
156 if (device && device->
windows) {
161 if (fullscreen_window) {
163 SDL_RestoreWindow(fullscreen_window);
170 SDL_RestoreWindow(window);
172 SDL_RaiseWindow(window);
177 - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
183 static SDLAppDelegate *appDelegate = nil;
186 GetApplicationName(
void)
191 appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
193 appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
197 appName = [[NSProcessInfo processInfo] processName];
204 CreateApplicationMenus(
void)
212 NSMenuItem *menuItem;
219 mainMenu = [[NSMenu alloc] init];
222 [NSApp setMainMenu:mainMenu];
228 appName = GetApplicationName();
229 appleMenu = [[NSMenu alloc] initWithTitle:@""];
232 title = [@"About " stringByAppendingString:appName];
233 [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
235 [appleMenu addItem:[NSMenuItem separatorItem]];
237 [appleMenu addItemWithTitle:@"Preferencesâ •2‘U€¦" action:nil keyEquivalent:@","];
239 [appleMenu addItem:[NSMenuItem separatorItem]];
241 serviceMenu = [[NSMenu alloc] initWithTitle:@""];
242 menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:
@"Services" action:nil keyEquivalent:
@""];
243 [menuItem setSubmenu:serviceMenu];
245 [NSApp setServicesMenu:serviceMenu];
246 [serviceMenu release];
248 [appleMenu addItem:[NSMenuItem separatorItem]];
250 title = [@"Hide " stringByAppendingString:appName];
251 [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
253 menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:
@"Hide Others" action:
@selector(hideOtherApplications:) keyEquivalent:
@"h"];
254 [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
256 [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
258 [appleMenu addItem:[NSMenuItem separatorItem]];
260 title = [@"Quit " stringByAppendingString:appName];
261 [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
264 menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
265 [menuItem setSubmenu:appleMenu];
266 [[NSApp mainMenu] addItem:menuItem];
270 [NSApp setAppleMenu:appleMenu];
275 windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
278 [windowMenu addItemWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
280 [windowMenu addItemWithTitle:@"Zoom" action:@selector(performZoom:) keyEquivalent:@""];
283 menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
284 [menuItem setSubmenu:windowMenu];
285 [[NSApp mainMenu] addItem:menuItem];
289 [NSApp setWindowsMenu:windowMenu];
290 [windowMenu release];
294 if ([NSApp respondsToSelector:
@selector(setPresentationOptions:)]) {
296 viewMenu = [[NSMenu alloc] initWithTitle:@"View"];
299 menuItem = [viewMenu addItemWithTitle:@"Toggle Full Screen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"];
300 [menuItem setKeyEquivalentModifierMask:NSControlKeyMask | NSCommandKeyMask];
303 menuItem = [[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""];
304 [menuItem setSubmenu:viewMenu];
305 [[NSApp mainMenu] addItem:menuItem];
319 [SDLApplication sharedApplication];
323 if (!hint || *hint ==
'0') {
324 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6 325 if ([NSApp respondsToSelector:
@selector(setActivationPolicy:)]) {
327 [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
328 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6 330 ProcessSerialNumber psn = {0, kCurrentProcess};
331 TransformProcessType(&psn, kProcessTransformToForegroundApplication);
334 [NSApp activateIgnoringOtherApps:YES];
337 if ([NSApp mainMenu] == nil) {
338 CreateApplicationMenus();
340 [NSApp finishLaunching];
341 NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
342 [NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
343 [NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
344 [NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
346 [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
347 [appDefaults release];
349 if (NSApp && !appDelegate) {
350 appDelegate = [[SDLAppDelegate alloc] init];
355 if (![NSApp delegate]) {
356 [(NSApplication *)NSApp setDelegate:appDelegate];
358 appDelegate->seenFirstActivate = YES;
373 UpdateSystemActivity(UsrActivity);
379 NSEvent *
event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ];
380 if (
event == nil ) {
385 case NSLeftMouseDown:
386 case NSOtherMouseDown:
387 case NSRightMouseDown:
391 case NSLeftMouseDragged:
392 case NSRightMouseDragged:
393 case NSOtherMouseDragged:
407 [NSApp sendEvent:event];
432 NSString *
name = [GetApplicationName() stringByAppendingString:@" using SDL_DisableScreenSaver"];
433 IOPMAssertionCreateWithDescription(kIOPMAssertPreventUserIdleDisplaySleep,
void Cocoa_RegisterApp(void)
void Cocoa_HandleKeyEvent(_THIS, NSEvent *event)
uint32_t Uint32
An unsigned 32-bit integer type.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
void Cocoa_SuspendScreenSaver(_THIS)
GLuint const GLchar * name
IOPMAssertionID screensaver_assertion
static SDL_VideoDevice * _this
#define SDL_HINT_MAC_BACKGROUND_APP
When set don't force the SDL app to become a foreground process.
GLuint GLuint GLsizei GLenum type
Uint32 screensaver_activity
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
void Cocoa_PumpEvents(_THIS)
BOOL screensaver_use_iopm
SDL_VideoDisplay * displays
void Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
SDL_Window * fullscreen_window
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
#define SDL_assert(condition)
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
int SDL_SendDropFile(const char *file)
The type used to identify a window.
SDL_VideoDevice * SDL_GetVideoDevice(void)
SDL_bool suspend_screensaver
GLuint GLsizei GLsizei * length
#define SDL_TICKS_PASSED(A, B)
Compare SDL ticks values, and return true if A has passed B.