summaryrefslogtreecommitdiff
path: root/src/macos.m
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-27 13:33:54 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-27 13:33:54 +0300
commit73d9c1d6f0dee5b391ec0484d62638c087f2adf7 (patch)
tree4e034036aed405e13988304ef690c9f66a4bd3f0 /src/macos.m
parentb25d33db257b59badac355f30b9be2caab64f785 (diff)
macOS: Robust system appearance check
This API does not exist on 10.13, so prepare for an exception.
Diffstat (limited to 'src/macos.m')
-rw-r--r--src/macos.m22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/macos.m b/src/macos.m
index b000fed9..975ba928 100644
--- a/src/macos.m
+++ b/src/macos.m
@@ -38,6 +38,16 @@ enum iTouchBarVariant {
38 default_TouchBarVariant, 38 default_TouchBarVariant,
39}; 39};
40 40
41static NSString *currentSystemAppearance_(void) {
42 /* This API does not exist on 10.13. */
43 @try {
44 return [[NSApp effectiveAppearance] name];
45 }
46 @catch (NSException *) {
47 return @"NSAppearanceNameAqua";
48 }
49}
50
41/*----------------------------------------------------------------------------------------------*/ 51/*----------------------------------------------------------------------------------------------*/
42 52
43@interface CommandButton : NSCustomTouchBarItem { 53@interface CommandButton : NSCustomTouchBarItem {
@@ -447,7 +457,11 @@ void setupApplication_MacOS(void) {
447 NSApplication *app = [NSApplication sharedApplication]; 457 NSApplication *app = [NSApplication sharedApplication];
448 /* Our delegate will override SDL's delegate. */ 458 /* Our delegate will override SDL's delegate. */
449 MyDelegate *myDel = [[MyDelegate alloc] initWithSDLDelegate:app.delegate]; 459 MyDelegate *myDel = [[MyDelegate alloc] initWithSDLDelegate:app.delegate];
450 [myDel setAppearance:[[app effectiveAppearance] name]]; 460 [myDel setAppearance:currentSystemAppearance_()];
461 [app addObserver:myDel
462 forKeyPath:@"effectiveAppearance"
463 options:0
464 context:myDel];
451 app.delegate = myDel; 465 app.delegate = myDel;
452 NSMenu *appMenu = [[[NSApp mainMenu] itemAtIndex:0] submenu]; 466 NSMenu *appMenu = [[[NSApp mainMenu] itemAtIndex:0] submenu];
453 NSMenuItem *prefsItem = [appMenu itemWithTitle:@"Preferences…"]; 467 NSMenuItem *prefsItem = [appMenu itemWithTitle:@"Preferences…"];
@@ -463,10 +477,6 @@ void setupApplication_MacOS(void) {
463void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) { 477void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *items, size_t count) {
464 NSApplication *app = [NSApplication sharedApplication]; 478 NSApplication *app = [NSApplication sharedApplication];
465 MyDelegate *myDel = (MyDelegate *) app.delegate; 479 MyDelegate *myDel = (MyDelegate *) app.delegate;
466 [app addObserver:myDel
467 forKeyPath:@"effectiveAppearance"
468 options:0
469 context:myDel];
470 NSMenu *appMenu = [app mainMenu]; 480 NSMenu *appMenu = [app mainMenu];
471 NSMenuItem *mainItem = [appMenu insertItemWithTitle:[NSString stringWithUTF8String:menuLabel] 481 NSMenuItem *mainItem = [appMenu insertItemWithTitle:[NSString stringWithUTF8String:menuLabel]
472 action:nil 482 action:nil
@@ -525,7 +535,7 @@ void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *
525void handleCommand_MacOS(const char *cmd) { 535void handleCommand_MacOS(const char *cmd) {
526 if (equal_Command(cmd, "prefs.ostheme.changed")) { 536 if (equal_Command(cmd, "prefs.ostheme.changed")) {
527 if (arg_Command(cmd)) { 537 if (arg_Command(cmd)) {
528 appearanceChanged_MacOS_([[NSApp effectiveAppearance] name]); 538 appearanceChanged_MacOS_(currentSystemAppearance_());
529 } 539 }
530 } 540 }
531#if 0 541#if 0