annotate 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
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"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
2 #import <Cocoa/Cocoa.h>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
3
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
4 namespace osx {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
5
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
6 bool DarkThemeAvailable() {
5
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
7 if (@available(macOS 10.14, *))
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
8 return true;
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
9 else
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
10 return false;
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
11 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
12
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
13 bool IsInDarkTheme() {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
14 if (@available(macOS 10.14, *)) {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
15 auto appearance =
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
16 [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:@[
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
17 NSAppearanceNameAqua, NSAppearanceNameDarkAqua
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
18 ]];
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
19 return [appearance isEqualToString:NSAppearanceNameDarkAqua];
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
20 }
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
21 return false;
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
22 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
23
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
24 void SetToDarkTheme() {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
25 // 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
26 if (@available(macOS 10.14, *)) {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
27 [NSApp setAppearance:[NSAppearance
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
28 appearanceNamed:NSAppearanceNameDarkAqua]];
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
29 }
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
30 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
31
9
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
32 void SetToLightTheme() {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
33 // 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
34 if (__builtin_available(macOS 10.14, *)) {
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
35 [NSApp
5c0397762b53 INCOMPLETE: megacommit :)
Paper <mrpapersonic@gmail.com>
parents: 5
diff changeset
36 setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
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