From 1fbc6945d2006bfc07a9a66eb64a134c855d8d61 Mon Sep 17 00:00:00 2001 From: Richard Gráčik Date: Sat, 2 Mar 2024 10:02:35 +0100 Subject: macOS theme switching (#276) * abaddon.cpp: add support for macOS theme changing Based on AppleInterfaceThemeChangedNotification for now. * CMakeLists: last changes for macOS specific libs --------- Co-authored-by: ouwou <26526779+ouwou@users.noreply.github.com> --- src/abaddon.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src') diff --git a/src/abaddon.cpp b/src/abaddon.cpp index 443fa4e..456749a 100644 --- a/src/abaddon.cpp +++ b/src/abaddon.cpp @@ -25,6 +25,23 @@ #include "remoteauth/remoteauthdialog.hpp" #include "util.hpp" +#if defined(__APPLE__) +#include + +void macOSThemeChanged() { + CFPropertyListRef appearanceName = CFPreferencesCopyAppValue(CFSTR("AppleInterfaceStyle"), kCFPreferencesAnyApplication); + if (appearanceName != NULL && CFGetTypeID(appearanceName) == CFStringGetTypeID() && CFStringCompare((CFStringRef)appearanceName, CFSTR("Dark"), 0) == kCFCompareEqualTo) { + Gtk::Settings::get_default()->set_property("gtk-application-prefer-dark-theme", true); + } else { + Gtk::Settings::get_default()->set_property("gtk-application-prefer-dark-theme", false); + } +} + +void macOSThemeChangedCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { + macOSThemeChanged(); +} +#endif + #ifdef WITH_LIBHANDY #include #endif @@ -331,6 +348,17 @@ int Abaddon::StartGTK() { m_gtk_app->hold(); m_main_window->show(); +#if defined(__APPLE__) + CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(), + NULL, + macOSThemeChangedCallback, + CFSTR("AppleInterfaceThemeChangedNotification"), + NULL, + CFNotificationSuspensionBehaviorCoalesce); + + macOSThemeChanged(); +#endif + RunFirstTimeDiscordStartup(); return m_gtk_app->run(*m_main_window); -- cgit v1.2.3