mirror of
https://github.com/encounter/SDL.git
synced 2025-12-10 05:57:44 +00:00
Mac: Better handling when someone else is the app delegate.
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user