Mercurial > minori
annotate src/sys/osx/dark_theme.mm @ 137:69db40272acd
dep/animia: [WIP] huge refactor
this WILL NOT compile, because lots of code has been changed
and every API in the original codebase has been removed.
note that this api setup is not exactly permanent...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 10 Nov 2023 13:52:47 -0500 |
parents | 6d8da6e64d61 |
children | 9c4645100fec |
rev | line source |
---|---|
2 | 1 #include "sys/osx/dark_theme.h" |
2 #import <Cocoa/Cocoa.h> | |
3 | |
9 | 4 namespace osx { |
5 | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
6 /* I remember clang giving a hissy fit when I tried simplifying this to just |
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
7 a return; does it still do that? */ |
9 | 8 bool DarkThemeAvailable() { |
5 | 9 if (@available(macOS 10.14, *)) |
10 return true; | |
11 else | |
12 return false; | |
2 | 13 } |
14 | |
9 | 15 bool IsInDarkTheme() { |
16 if (@available(macOS 10.14, *)) { | |
15 | 17 auto appearance = [NSApp.effectiveAppearance |
18 bestMatchFromAppearancesWithNames:@[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]]; | |
9 | 19 return [appearance isEqualToString:NSAppearanceNameDarkAqua]; |
20 } | |
21 return false; | |
2 | 22 } |
23 | |
9 | 24 void SetToDarkTheme() { |
25 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code | |
26 if (@available(macOS 10.14, *)) { | |
15 | 27 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]]; |
9 | 28 } |
2 | 29 } |
30 | |
9 | 31 void SetToLightTheme() { |
32 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
33 if (@available(macOS 10.14, *)) { |
15 | 34 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]]; |
9 | 35 } |
2 | 36 } |
37 | |
9 | 38 void SetToAutoTheme() { |
39 if (@available(macOS 10.14, *)) { | |
40 [NSApp setAppearance:nil]; | |
41 } | |
2 | 42 } |
9 | 43 |
44 } // namespace osx |