diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-02 13:54:46 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-02 13:54:46 +0200 |
commit | f81a4b2478fb3afa24a4ff38afd62cec86e5b9cd (patch) | |
tree | dfe59a5df67ab0df11948e593664a30a22fbd14b /platform/macos | |
parent | 4fa3675ffa96b1a3c1c9e4aa46fe6f2bebcbb4f7 (diff) | |
parent | 629ae58a8064e30860dcf83f71a1abe9560cc59c (diff) |
Merge pull request #65026 from bruvzg/dark_mode
Diffstat (limited to 'platform/macos')
-rw-r--r-- | platform/macos/display_server_macos.h | 4 | ||||
-rw-r--r-- | platform/macos/display_server_macos.mm | 35 |
2 files changed, 39 insertions, 0 deletions
diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h index cd457836de..769cba2de5 100644 --- a/platform/macos/display_server_macos.h +++ b/platform/macos/display_server_macos.h @@ -287,6 +287,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 c117713c2b..b009007d73 100644 --- a/platform/macos/display_server_macos.mm +++ b/platform/macos/display_server_macos.mm @@ -1715,6 +1715,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_ |