Mercurial > minori
annotate src/sys/osx/dark_theme.mm @ 187:9613d72b097e
*: multiple performance improvements
like marking `static const` when it makes sense...
date: change old stupid heap-based method to a structure which should
make copying the thing actually make a copy.
also many performance-based changes, like removing the std::tie
dependency and forward-declaring nlohmann json
*: replace every instance of QString::fromUtf8 to Strings::ToQString.
the main difference is that our function will always convert exactly
what is in the string, while some other times it would only convert
up to the nearest NUL byte
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 06 Dec 2023 13:43:54 -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 |