Mac and Linux SDL2 binary snapshots
Edward Rudd
2021-06-15 dec7875a6e23212021e4d9080330a42832dfe02a
source/src/video/cocoa/SDL_cocoaevents.m
@@ -26,12 +26,14 @@
#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
@@ -117,6 +119,7 @@
}
- (id)init;
- (void)localeDidChange:(NSNotification *)notification;
@end
@implementation SDLAppDelegate : NSObject
@@ -137,6 +140,11 @@
                   selector:@selector(focusSomeWindow:)
                       name:NSApplicationDidBecomeActiveNotification
                     object:nil];
        [center addObserver:self
                   selector:@selector(localeDidChange:)
                       name:NSCurrentLocaleDidChangeNotification
                     object:nil];
    }
    return self;
@@ -148,6 +156,7 @@
    [center removeObserver:self name:NSWindowWillCloseNotification object:nil];
    [center removeObserver:self name:NSApplicationDidBecomeActiveNotification object:nil];
    [center removeObserver:self name:NSCurrentLocaleDidChangeNotification object:nil];
    [super dealloc];
}
@@ -226,6 +235,11 @@
    }
}
- (void)localeDidChange:(NSNotification *)notification;
{
    SDL_SendLocaleChangedEvent();
}
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
    return (BOOL)SDL_SendDropFile(NULL, [filename UTF8String]) && SDL_SendDropComplete(NULL);
@@ -248,10 +262,24 @@
        [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;
@@ -281,6 +309,9 @@
    NSString *mainNibFileName;
    bool success = false;
    
    if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_8) {
        return false;
    }
    infoDict = [[NSBundle mainBundle] infoDictionary];
    if (infoDict) {
        mainNibFileName = [infoDict valueForKey:@"NSMainNibFile"];