diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/sys/osx/dark_theme.mm	Tue Aug 08 19:49:15 2023 -0400
@@ -0,0 +1,44 @@
+#include "sys/osx/dark_theme.h"
+#import <Cocoa/Cocoa.h>
+
+bool osx::DarkThemeAvailable()
+{
+	return (__builtin_available(macOS 10.14, *)) ? true : false;
+}
+
+bool osx::IsInDarkTheme()
+{
+    if (__builtin_available(macOS 10.14, *))
+    {
+        auto appearance = [NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:
+                @[ NSAppearanceNameAqua, NSAppearanceNameDarkAqua ]];
+        return [appearance isEqualToString:NSAppearanceNameDarkAqua];
+    }
+    return false;
+}
+
+void osx::SetToDarkTheme()
+{
+   // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
+   if (__builtin_available(macOS 10.14, *))
+   {
+        [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]];
+   }
+}
+
+void osx::SetToLightTheme()
+{
+    // https://stackoverflow.com/questions/55925862/how-can-i-set-my-os-x-application-theme-in-code
+    if (__builtin_available(macOS 10.14, *))
+    {
+        [NSApp setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
+    }
+}
+
+void osx::SetToAutoTheme()
+{
+    if (__builtin_available(macOS 10.14, *))
+    {
+        [NSApp setAppearance:nil];
+    }
+}