annotate src/sys/osx/dark_theme.mm @ 3:190ded9438c0

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