summaryrefslogtreecommitdiff
path: root/platform/macos
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2022-08-29 11:24:48 +0300
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2022-08-31 11:37:01 +0300
commit629ae58a8064e30860dcf83f71a1abe9560cc59c (patch)
tree2c39f5b94c2d66d563335668dbfce67e8de20668 /platform/macos
parentf6714581cc29e14d2b0799a36d5ce91e172489c5 (diff)
Add support for system dark mode and accent color detection (macOS and Windows). Add support for dark mode title bar on Windows.
Diffstat (limited to 'platform/macos')
-rw-r--r--platform/macos/display_server_macos.h4
-rw-r--r--platform/macos/display_server_macos.mm35
2 files changed, 39 insertions, 0 deletions
diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h
index a08667a259..19e157d60d 100644
--- a/platform/macos/display_server_macos.h
+++ b/platform/macos/display_server_macos.h
@@ -284,6 +284,10 @@ public:
virtual void tts_resume() override;
virtual void tts_stop() override;
+ virtual bool is_dark_mode_supported() const override;
+ virtual bool is_dark_mode() const override;
+ virtual Color get_accent_color() const override;
+
virtual Error dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback) override;
virtual Error dialog_input_text(String p_title, String p_description, String p_partial, const Callable &p_callback) override;
diff --git a/platform/macos/display_server_macos.mm b/platform/macos/display_server_macos.mm
index b06ae9f27c..8a6477abd0 100644
--- a/platform/macos/display_server_macos.mm
+++ b/platform/macos/display_server_macos.mm
@@ -1682,6 +1682,41 @@ void DisplayServerMacOS::tts_stop() {
[tts stopSpeaking];
}
+bool DisplayServerMacOS::is_dark_mode_supported() const {
+ if (@available(macOS 10.14, *)) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool DisplayServerMacOS::is_dark_mode() const {
+ if (@available(macOS 10.14, *)) {
+ if (![[NSUserDefaults standardUserDefaults] objectForKey:@"AppleInterfaceStyle"]) {
+ return false;
+ } else {
+ return ([[[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"] isEqual:@"Dark"]);
+ }
+ } else {
+ return false;
+ }
+}
+
+Color DisplayServerMacOS::get_accent_color() const {
+ if (@available(macOS 10.14, *)) {
+ NSColor *color = [[NSColor controlAccentColor] colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
+ if (color) {
+ CGFloat components[4];
+ [color getRed:&components[0] green:&components[1] blue:&components[2] alpha:&components[3]];
+ return Color(components[0], components[1], components[2], components[3]);
+ } else {
+ return Color(0, 0, 0, 0);
+ }
+ } else {
+ return Color(0, 0, 0, 0);
+ }
+}
+
Error DisplayServerMacOS::dialog_show(String p_title, String p_description, Vector<String> p_buttons, const Callable &p_callback) {
_THREAD_SAFE_METHOD_