From b7b40368a206259925e9bd5dc77c92ff09353d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20L=C3=B6tscher?= Date: Sun, 7 Apr 2024 23:54:15 +0200 Subject: [PATCH] Derive dark mode property on MacOS --- src/core/gui/MainWindow.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/core/gui/MainWindow.cpp b/src/core/gui/MainWindow.cpp index 7d425e41b3db..8d1af106c743 100644 --- a/src/core/gui/MainWindow.cpp +++ b/src/core/gui/MainWindow.cpp @@ -44,6 +44,13 @@ #include "config-dev.h" // for TOOLBAR_CONFIG #include "filesystem.h" // for path, exists +#ifdef __APPLE__ +// the following header file contains a definition of struct Point that conflicts with model/Point.h +#define Point Point_CF +#include +#undef Point +#endif + using std::string; @@ -237,7 +244,22 @@ static ThemeProperties getThemeProperties(GtkWidget* w) { props.darkSuffix = sm[2].length() > 0; } gboolean dark = false; + +#ifdef __APPLE__ + CFStringRef interfaceStyle = + (CFStringRef)CFPreferencesCopyAppValue(CFSTR("AppleInterfaceStyle"), kCFPreferencesCurrentApplication); + if (interfaceStyle) { + char buffer[128]; + if (CFStringGetCString(interfaceStyle, buffer, sizeof(buffer), kCFStringEncodingUTF8)) { + std::string style = buffer; + if (auto pos = style.find("Dark"); pos != std::string::npos) { + dark = true; + } + } + } +#else g_object_get(gtk_widget_get_settings(w), "gtk-application-prefer-dark-theme", &dark, nullptr); +#endif g_message("Extracted theme info: Name = %s, rootname = %s, dark = %s", name.get(), props.rootname.c_str(), dark ? "true" : "false");