annotate src/sys/osx/dark_theme.mm @ 1:1ae666fdf9e2

*: initial commit
author Paper <mrpapersonic@gmail.com>
date Tue, 08 Aug 2023 19:49:15 -0400
parents
children 23d0d9319a00
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include "sys/osx/dark_theme.h"
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 #import <Cocoa/Cocoa.h>
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4 bool osx::DarkThemeAvailable()
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 return (__builtin_available(macOS 10.14, *)) ? true : false;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 bool osx::IsInDarkTheme()
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 if (__builtin_available(macOS 10.14, *))
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 auto appearance = [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 @[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 return [appearance isEqualToString:NSAppearanceNameDarkAqua];
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 return false;
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 void osx::SetToDarkTheme()
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 if (__builtin_available(macOS 10.14, *))
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]];
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 void osx::SetToLightTheme()
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30 {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32 if (__builtin_available(macOS 10.14, *))
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33 {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
34 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
37
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
38 void osx::SetToAutoTheme()
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39 {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40 if (__builtin_available(macOS 10.14, *))
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
41 {
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42 [NSApp setAppearance:nil];
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43 }
1ae666fdf9e2 *: initial commit
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44 }