macOS: Fix an OS-generated warning printed to stdout on launch in bundled apps.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m
index 98bdf87..9da1704 100644
--- a/src/video/cocoa/SDL_cocoaevents.m
+++ b/src/video/cocoa/SDL_cocoaevents.m
@@ -38,6 +38,8 @@
- (void)terminate:(id)sender;
- (void)sendEvent:(NSEvent *)theEvent;
++ (void)registerUserDefaults;
+
@end
@implementation SDLApplication
@@ -90,6 +92,17 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
[super sendEvent:theEvent];
}
++ (void)registerUserDefaults
+{
+ NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
+ [NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
+ [NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
+ [NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
+ nil];
+ [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
+ [appDefaults release];
+}
+
@end // SDLApplication
/* setAppleMenu disappeared from the headers in 10.4 */
@@ -227,6 +240,10 @@ static void Cocoa_DispatchEvent(NSEvent *theEvent)
if (!SDL_GetHintBoolean(SDL_HINT_MAC_BACKGROUND_APP, SDL_FALSE)) {
[NSApp activateIgnoringOtherApps:YES];
}
+
+ /* If we call this before NSApp activation, macOS might print a complaint
+ * about ApplePersistenceIgnoreState. */
+ [SDLApplication registerUserDefaults];
}
@end
@@ -379,13 +396,12 @@ Cocoa_RegisterApp(void)
CreateApplicationMenus();
}
[NSApp finishLaunching];
- NSDictionary *appDefaults = [[NSDictionary alloc] initWithObjectsAndKeys:
- [NSNumber numberWithBool:NO], @"AppleMomentumScrollSupported",
- [NSNumber numberWithBool:NO], @"ApplePressAndHoldEnabled",
- [NSNumber numberWithBool:YES], @"ApplePersistenceIgnoreState",
- nil];
- [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
- [appDefaults release];
+ if ([NSApp delegate]) {
+ /* The SDL app delegate calls this in didFinishLaunching if it's
+ * attached to the NSApp, otherwise we need to call it manually.
+ */
+ [SDLApplication registerUserDefaults];
+ }
}
if (NSApp && !appDelegate) {
appDelegate = [[SDLAppDelegate alloc] init];