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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
4
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
5 namespace osx {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
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
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
10 bool DarkThemeAvailable() {
5
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
11 if (@available(macOS 10.14, *))
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
12 return true;
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
13 else
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
14 return false;
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
15 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
16
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
17 bool IsInDarkTheme() {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
18 if (@available(macOS 10.14, *)) {
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
19 auto appearance = [NSApp.effectiveAppearance
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
20 bestMatchFromAppearancesWithNames:@[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
21 return [appearance isEqualToString:NSAppearanceNameDarkAqua];
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
22 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
23 return false;
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
24 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
25
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
26 void SetToDarkTheme() {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
27 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
28 if (@available(macOS 10.14, *)) {
15
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
29 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]];
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
30 }
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
31 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
32
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
33 void SetToLightTheme() {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
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
cde8f67a7c7d *: update, megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
36 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
37 }
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
38 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
39
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
40 void SetToAutoTheme() {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
41 if (@available(macOS 10.14, *)) {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
42 [NSApp setAppearance:nil];
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
43 }
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
44 }
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
45
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
46 } // namespace osx