Mercurial > minori
annotate src/sys/osx/dark_theme.mm @ 193:0ad2507c3e60
dep/animia: cmake: check for the objc runtime library
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 07 Dec 2023 01:56:39 -0500 |
parents | 9c4645100fec |
children |
rev | line source |
---|---|
2 | 1 #include "sys/osx/dark_theme.h" |
179
9c4645100fec
osx: clean up includes, we do not need cocoa
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
2 |
9c4645100fec
osx: clean up includes, we do not need cocoa
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
3 #import <AppKit/AppKit.h> |
2 | 4 |
9 | 5 namespace osx { |
6 | |
105
6d8da6e64d61
theme: add dark stylesheet, make it actually usable
Paper <mrpapersonic@gmail.com>
parents:
15
diff
changeset
|
7 /* I remember clang giving a hissy fit when I tried simplifying this to just |
179
9c4645100fec
osx: clean up includes, we do not need cocoa
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
8 * a return; does it still do that? |
9c4645100fec
osx: clean up includes, we do not need cocoa
Paper <mrpapersonic@gmail.com>
parents:
105
diff
changeset
|
9 */ |
9 | 10 bool DarkThemeAvailable() { |
5 | 11 if (@available(macOS 10.14, *)) |
12 return true; | |
13 else | |
14 return false; | |
2 | 15 } |
16 | |
9 | 17 bool IsInDarkTheme() { |
18 if (@available(macOS 10.14, *)) { | |
15 | 19 auto appearance = [NSApp.effectiveAppearance |
20 bestMatchFromAppearancesWithNames:@[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]]; | |
9 | 21 return [appearance isEqualToString:NSAppearanceNameDarkAqua]; |
22 } | |
23 return false; | |
2 | 24 } |
25 | |
9 | 26 void SetToDarkTheme() { |
27 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code | |
28 if (@available(macOS 10.14, *)) { | |
15 | 29 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]]; |
9 | 30 } |
2 | 31 } |
32 | |
9 | 33 void SetToLightTheme() { |
34 // 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
|
35 if (@available(macOS 10.14, *)) { |
15 | 36 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]]; |
9 | 37 } |
2 | 38 } |
39 | |
9 | 40 void SetToAutoTheme() { |
41 if (@available(macOS 10.14, *)) { | |
42 [NSApp setAppearance:nil]; | |
43 } | |
2 | 44 } |
9 | 45 |
46 } // namespace osx |