| | |
| | | |
| | | #include "SDL_cocoavideo.h" |
| | | #include "../../events/SDL_events_c.h" |
| | | #include "SDL_assert.h" |
| | | #include "SDL_hints.h" |
| | | |
| | | /* This define was added in the 10.9 SDK. */ |
| | | #ifndef kIOPMAssertPreventUserIdleDisplaySleep |
| | | #define kIOPMAssertPreventUserIdleDisplaySleep kIOPMAssertionTypePreventUserIdleDisplaySleep |
| | | #endif |
| | | #ifndef NSAppKitVersionNumber10_8 |
| | | #define NSAppKitVersionNumber10_8 1187 |
| | | #endif |
| | | |
| | | @interface SDLApplication : NSApplication |
| | |
| | | } |
| | | |
| | | - (id)init; |
| | | - (void)localeDidChange:(NSNotification *)notification; |
| | | @end |
| | | |
| | | @implementation SDLAppDelegate : NSObject |
| | |
| | | selector:@selector(focusSomeWindow:) |
| | | name:NSApplicationDidBecomeActiveNotification |
| | | object:nil]; |
| | | |
| | | [center addObserver:self |
| | | selector:@selector(localeDidChange:) |
| | | name:NSCurrentLocaleDidChangeNotification |
| | | object:nil]; |
| | | } |
| | | |
| | | return self; |
| | |
| | | |
| | | [center removeObserver:self name:NSWindowWillCloseNotification object:nil]; |
| | | [center removeObserver:self name:NSApplicationDidBecomeActiveNotification object:nil]; |
| | | [center removeObserver:self name:NSCurrentLocaleDidChangeNotification object:nil]; |
| | | |
| | | [super dealloc]; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | - (void)localeDidChange:(NSNotification *)notification; |
| | | { |
| | | SDL_SendLocaleChangedEvent(); |
| | | } |
| | | |
| | | - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename |
| | | { |
| | | return (BOOL)SDL_SendDropFile(NULL, [filename UTF8String]) && SDL_SendDropComplete(NULL); |
| | |
| | | [NSApp activateIgnoringOtherApps:YES]; |
| | | } |
| | | |
| | | [[NSAppleEventManager sharedAppleEventManager] |
| | | setEventHandler:self |
| | | andSelector:@selector(handleURLEvent:withReplyEvent:) |
| | | forEventClass:kInternetEventClass |
| | | andEventID:kAEGetURL]; |
| | | |
| | | /* If we call this before NSApp activation, macOS might print a complaint |
| | | * about ApplePersistenceIgnoreState. */ |
| | | [SDLApplication registerUserDefaults]; |
| | | } |
| | | |
| | | - (void)handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent |
| | | { |
| | | NSString* path = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; |
| | | SDL_SendDropFile(NULL, [path UTF8String]); |
| | | SDL_SendDropComplete(NULL); |
| | | } |
| | | |
| | | @end |
| | | |
| | | static SDLAppDelegate *appDelegate = nil; |
| | |
| | | NSString *mainNibFileName; |
| | | bool success = false; |
| | | |
| | | if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_8) { |
| | | return false; |
| | | } |
| | | infoDict = [[NSBundle mainBundle] infoDictionary]; |
| | | if (infoDict) { |
| | | mainNibFileName = [infoDict valueForKey:@"NSMainNibFile"]; |