Mac: Better handling when someone else is the app delegate.

--HG--
extra : rebase_source : a2d99f3c2d93c0a6adeaf04fccec23799cc52de9
This commit is contained in:
Jørgen P. Tjernø 2013-10-07 16:01:40 -07:00
parent 0631b5a7a8
commit daf4ca1ac2
2 changed files with 61 additions and 5 deletions

View file

@ -42,12 +42,11 @@
@end
@interface SDLAppDelegate : NSObject {
@public
BOOL seenFirstActivate;
}
- (id)init;
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
- (void)applicationDidBecomeActive:(NSNotification *)aNotification;
@end
@implementation SDLAppDelegate : NSObject
@ -57,18 +56,28 @@
if (self) {
seenFirstActivate = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(focusSomeWindow:)
name:NSApplicationDidBecomeActiveNotification
object:nil];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
SDL_SendQuit();
return NSTerminateCancel;
}
- (void)applicationDidBecomeActive:(NSNotification *)aNotification
- (void)focusSomeWindow:(NSNotification *)aNotification
{
/* HACK: Ignore the first call. The application gets a
* applicationDidBecomeActive: a little bit after the first window is
@ -111,6 +120,8 @@
}
@end
static SDLAppDelegate *appDelegate = nil;
static NSString *
GetApplicationName(void)
{
@ -235,8 +246,17 @@ Cocoa_RegisterApp(void)
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
}
if (NSApp && ![NSApp delegate]) {
[NSApp setDelegate:[[SDLAppDelegate alloc] init]];
if (NSApp && !appDelegate) {
appDelegate = [[SDLAppDelegate alloc] init];
/* If someone else has an app delegate, it means we can't turn a
* termination into SDL_Quit, and we can't handle application:openFile:
*/
if (![NSApp delegate]) {
[NSApp setDelegate:appDelegate];
} else {
appDelegate->seenFirstActivate = YES;
}
}
[pool release];
}