annotate src/sys/osx/dark_theme.mm @ 5:51ae25154b70

Fix OS X support code
author Paper <mrpapersonic@gmail.com>
date Sat, 12 Aug 2023 13:10:34 -0400
parents 23d0d9319a00
children 5c0397762b53
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
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
4 bool osx::DarkThemeAvailable()
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
5 {
5
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
6 if (@available(macOS 10.14, *))
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
7 return true;
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
8 else
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
9 return false;
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
10 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
11
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
12 bool osx::IsInDarkTheme()
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
13 {
5
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
14 if (@available(macOS 10.14, *))
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
15 {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
16 auto appearance = [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
17 @[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
18 return [appearance isEqualToString:NSAppearanceNameDarkAqua];
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
19 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
20 return false;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
21 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
22
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
23 void osx::SetToDarkTheme()
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
24 {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
25 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
5
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
26 if (@available(macOS 10.14, *))
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
27 {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
28 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]];
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
29 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
30 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
31
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
32 void osx::SetToLightTheme()
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
33 {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
34 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
35 if (__builtin_available(macOS 10.14, *))
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
36 {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
37 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
38 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
39 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
40
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
41 void osx::SetToAutoTheme()
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
42 {
5
51ae25154b70 Fix OS X support code
Paper <mrpapersonic@gmail.com>
parents: 2
diff changeset
43 if (@available(macOS 10.14, *))
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
44 {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
45 [NSApp setAppearance:nil];
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
46 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
47 }