Mercurial > minori
comparison src/sys/osx/dark_theme.mm @ 9:5c0397762b53
INCOMPLETE: megacommit :)
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Sun, 10 Sep 2023 03:59:16 -0400 |
| parents | 51ae25154b70 |
| children | cde8f67a7c7d |
comparison
equal
deleted
inserted
replaced
| 8:b1f73678ef61 | 9:5c0397762b53 |
|---|---|
| 1 #include "sys/osx/dark_theme.h" | 1 #include "sys/osx/dark_theme.h" |
| 2 #import <Cocoa/Cocoa.h> | 2 #import <Cocoa/Cocoa.h> |
| 3 | 3 |
| 4 bool osx::DarkThemeAvailable() | 4 namespace osx { |
| 5 { | 5 |
| 6 bool DarkThemeAvailable() { | |
| 6 if (@available(macOS 10.14, *)) | 7 if (@available(macOS 10.14, *)) |
| 7 return true; | 8 return true; |
| 8 else | 9 else |
| 9 return false; | 10 return false; |
| 10 } | 11 } |
| 11 | 12 |
| 12 bool osx::IsInDarkTheme() | 13 bool IsInDarkTheme() { |
| 13 { | 14 if (@available(macOS 10.14, *)) { |
| 14 if (@available(macOS 10.14, *)) | 15 auto appearance = |
| 15 { | 16 [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:@[ |
| 16 auto appearance = [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames: | 17 NSAppearanceNameAqua, NSAppearanceNameDarkAqua |
| 17 @[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]]; | 18 ]]; |
| 18 return [appearance isEqualToString:NSAppearanceNameDarkAqua]; | 19 return [appearance isEqualToString:NSAppearanceNameDarkAqua]; |
| 19 } | 20 } |
| 20 return false; | 21 return false; |
| 21 } | 22 } |
| 22 | 23 |
| 23 void osx::SetToDarkTheme() | 24 void SetToDarkTheme() { |
| 24 { | 25 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code |
| 25 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code | 26 if (@available(macOS 10.14, *)) { |
| 26 if (@available(macOS 10.14, *)) | 27 [NSApp setAppearance:[NSAppearance |
| 27 { | 28 appearanceNamed:NSAppearanceNameDarkAqua]]; |
| 28 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]]; | 29 } |
| 29 } | |
| 30 } | 30 } |
| 31 | 31 |
| 32 void osx::SetToLightTheme() | 32 void SetToLightTheme() { |
| 33 { | 33 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code |
| 34 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code | 34 if (__builtin_available(macOS 10.14, *)) { |
| 35 if (__builtin_available(macOS 10.14, *)) | 35 [NSApp |
| 36 { | 36 setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]]; |
| 37 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]]; | 37 } |
| 38 } | |
| 39 } | 38 } |
| 40 | 39 |
| 41 void osx::SetToAutoTheme() | 40 void SetToAutoTheme() { |
| 42 { | 41 if (@available(macOS 10.14, *)) { |
| 43 if (@available(macOS 10.14, *)) | 42 [NSApp setAppearance:nil]; |
| 44 { | 43 } |
| 45 [NSApp setAppearance:nil]; | |
| 46 } | |
| 47 } | 44 } |
| 45 | |
| 46 } // namespace osx |
