comparison 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
comparison
equal deleted inserted replaced
0:5a76e1b94163 1:1ae666fdf9e2
1 #include "sys/osx/dark_theme.h"
2 #import <Cocoa/Cocoa.h>
3
4 bool osx::DarkThemeAvailable()
5 {
6 return (__builtin_available(macOS 10.14, *)) ? true : false;
7 }
8
9 bool osx::IsInDarkTheme()
10 {
11 if (__builtin_available(macOS 10.14, *))
12 {
13 auto appearance = [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:
14 @[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
15 return [appearance isEqualToString:NSAppearanceNameDarkAqua];
16 }
17 return false;
18 }
19
20 void osx::SetToDarkTheme()
21 {
22 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
23 if (__builtin_available(macOS 10.14, *))
24 {
25 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]];
26 }
27 }
28
29 void osx::SetToLightTheme()
30 {
31 // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
32 if (__builtin_available(macOS 10.14, *))
33 {
34 [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
35 }
36 }
37
38 void osx::SetToAutoTheme()
39 {
40 if (__builtin_available(macOS 10.14, *))
41 {
42 [NSApp setAppearance:nil];
43 }
44 }