diff --git a/Telegram/SourceFiles/platform/linux/integration_linux.cpp b/Telegram/SourceFiles/platform/linux/integration_linux.cpp index 54176c3e0b..fd8553f6f4 100644 --- a/Telegram/SourceFiles/platform/linux/integration_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/integration_linux.cpp @@ -8,11 +8,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/linux/integration_linux.h" #include "platform/platform_integration.h" +#include "base/platform/linux/base_linux_glibmm_helper.h" #include "base/platform/linux/base_linux_xdp_utilities.h" #include "core/application.h" +#include "core/core_settings.h" #include "base/random.h" #include +#include using namespace gi::repository; @@ -31,6 +34,7 @@ private: } gi::result _inhibitProxy; + base::Platform::XDP::SettingWatcher _darkModeWatcher; }; LinuxIntegration::LinuxIntegration() @@ -39,7 +43,23 @@ LinuxIntegration::LinuxIntegration() Gio::BusType::SESSION_, Gio::DBusProxyFlags::DO_NOT_AUTO_START_AT_CONSTRUCTION_, std::string(base::Platform::XDP::kService), - std::string(base::Platform::XDP::kObjectPath))) { + std::string(base::Platform::XDP::kObjectPath))) +, _darkModeWatcher([]( + const Glib::ustring &group, + const Glib::ustring &key, + const Glib::VariantBase &value) { + if (group == "org.freedesktop.appearance" + && key == "color-scheme") { + try { + const auto ivalue = base::Platform::GlibVariantCast(value); + + crl::on_main([=] { + Core::App().settings().setSystemDarkMode(ivalue == 1); + }); + } catch (...) { + } + } +}) { } void LinuxIntegration::init() { diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index d176b9b45d..1ea753fd36 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -575,30 +575,8 @@ QString SingleInstanceLocalServerName(const QString &hash) { #endif // !Q_OS_LINUX || Qt < 6.2.0 } +#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) std::optional IsDarkMode() { - [[maybe_unused]] static const auto Inited = [] { - using XDPSettingWatcher = base::Platform::XDP::SettingWatcher; - static const XDPSettingWatcher Watcher( - [=]( - const Glib::ustring &group, - const Glib::ustring &key, - const Glib::VariantBase &value) { - if (group == "org.freedesktop.appearance" - && key == "color-scheme") { - try { - const auto ivalue = base::Platform::GlibVariantCast(value); - - crl::on_main([=] { - Core::App().settings().setSystemDarkMode(ivalue == 1); - }); - } catch (...) { - } - } - }); - - return true; - }(); - try { const auto result = base::Platform::XDP::ReadSetting( "org.freedesktop.appearance", @@ -613,6 +591,7 @@ std::optional IsDarkMode() { return std::nullopt; } +#endif // Qt < 6.5.0 bool AutostartSupported() { return true; diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 950fadaa88..71096fac06 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -38,6 +38,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include +#include #include #include @@ -112,7 +113,11 @@ private: - (void) darkModeChanged:(NSNotification *)aNotification { Core::Sandbox::Instance().customEnterFromEventLoop([&] { +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + QWindowSystemInterface::handleThemeChange(); +#else // Qt >= 6.5.0 Core::App().settings().setSystemDarkMode(Platform::IsDarkMode()); +#endif // Qt < 6.5.0 }); } @@ -149,6 +154,21 @@ void ForceDisabled(QAction *action, bool disabled) { } } +QString strNotificationAboutThemeChange() { + const uint32 letters[] = { 0x75E86256, 0xD03E11B1, 0x4D92201D, 0xA2144987, 0x99D5B34F, 0x037589C3, 0x38ED2A7C, 0xD2371ABC, 0xDC98BB02, 0x27964E1B, 0x01748AED, 0xE06679F8, 0x761C9580, 0x4F2595BF, 0x6B5FCBF4, 0xE4D9C24E, 0xBA2F6AB5, 0xE6E3FA71, 0xF2CFC255, 0x56A50C19, 0x43AE1239, 0x77CA4254, 0x7D189A89, 0xEA7663EE, 0x84CEB554, 0xA0ADF236, 0x886512D4, 0x7D3FBDAF, 0x85C4BE4F, 0x12C8255E, 0x9AD8BD41, 0xAC154683, 0xB117598B, 0xDFD9F947, 0x63F06C7B, 0x6340DCD6, 0x3AAE6B3E, 0x26CB125A }; + return Platform::MakeFromLetters(letters); +} + +QString strNotificationAboutScreenLocked() { + const uint32 letters[] = { 0x34B47F28, 0x47E95179, 0x73D05C42, 0xB4E2A933, 0x924F22D1, 0x4265D8EA, 0x9E4D2CC2, 0x02E8157B, 0x35BF7525, 0x75901A41, 0xB0400FCC, 0xE801169D, 0x4E04B589, 0xC1CEF054, 0xAB2A7EB0, 0x5C67C4F6, 0xA4E2B954, 0xB35E12D2, 0xD598B22B, 0x4E3B8AAB, 0xBEA5E439, 0xFDA8AA3C, 0x1632DBA8, 0x88FE8965 }; + return Platform::MakeFromLetters(letters); +} + +QString strNotificationAboutScreenUnlocked() { + const uint32 letters[] = { 0xF897900B, 0x19A04630, 0x144DA6DF, 0x643CA7ED, 0x81DDA343, 0x88C6B149, 0x5F9A3A15, 0x31804E13, 0xDF2202B8, 0x9BD1B500, 0x61B92735, 0x7DDF5D43, 0xB74E06C3, 0x16FF1665, 0x9098F702, 0x4461DAF0, 0xA3134FA5, 0x52B01D3C, 0x6BC35769, 0xA7CC945D, 0x8B5327C0, 0x7630B9A0, 0x4E52E3CE, 0xED7765E3, 0xCEB7862D, 0xA06B34F0 }; + return Platform::MakeFromLetters(letters); +} + } // namespace MainWindow::Private::Private(not_null window) diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.h b/Telegram/SourceFiles/platform/mac/specific_mac.h index 142f4fa57f..fb63752c15 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.h +++ b/Telegram/SourceFiles/platform/mac/specific_mac.h @@ -16,8 +16,6 @@ class LocationPoint; namespace Platform { -[[nodiscard]] bool IsDarkMenuBar(); - inline bool AutostartSupported() { return false; } @@ -70,11 +68,4 @@ void psDownloadPathEnableAccess(); QByteArray psDownloadPathBookmark(const QString &path); QByteArray psPathBookmark(const QString &path); -QString strNotificationAboutThemeChange(); -QString strNotificationAboutScreenLocked(); -QString strNotificationAboutScreenUnlocked(); -QString strStyleOfInterface(); -QString strTitleWrapClass(); -QString strTitleClass(); - bool psLaunchMaps(const Data::LocationPoint &point); diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.mm b/Telegram/SourceFiles/platform/mac/specific_mac.mm index 3d633d4d12..d795a1c247 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac.mm @@ -124,6 +124,14 @@ QString SingleInstanceLocalServerName(const QString &hash) { #endif // OS_MAC_STORE } +#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) +namespace { + +QString strStyleOfInterface() { + const uint32 letters[] = { 0x3BBB7F05, 0xED4C5EC3, 0xC62C15A3, 0x5D10B283, 0x1BB35729, 0x63FB674D, 0xDBE5C174, 0x401EA195, 0x87B0C82A, 0x311BD596, 0x7063ECFA, 0x4AB90C27, 0xDA587DC4, 0x0B6296F8, 0xAA5603FA, 0xE1140A9F, 0x3D12D094, 0x339B5708, 0x712BA5B1 }; + return Platform::MakeFromLetters(letters); +} + bool IsDarkMenuBar() { bool result = false; @autoreleasepool { @@ -137,11 +145,14 @@ bool IsDarkMenuBar() { return result; } +} // namespace + std::optional IsDarkMode() { return IsMac10_14OrGreater() ? std::make_optional(IsDarkMenuBar()) : std::nullopt; } +#endif // Qt < 6.5.0 void WriteCrashDumpDetails() { #ifndef DESKTOP_APP_DISABLE_CRASH_REPORTS @@ -272,33 +283,3 @@ QByteArray psDownloadPathBookmark(const QString &path) { bool psLaunchMaps(const Data::LocationPoint &point) { return QDesktopServices::openUrl(u"https://maps.apple.com/?q=Point&z=16&ll=%1,%2"_q.arg(point.latAsString()).arg(point.lonAsString())); } - -QString strNotificationAboutThemeChange() { - const uint32 letters[] = { 0x75E86256, 0xD03E11B1, 0x4D92201D, 0xA2144987, 0x99D5B34F, 0x037589C3, 0x38ED2A7C, 0xD2371ABC, 0xDC98BB02, 0x27964E1B, 0x01748AED, 0xE06679F8, 0x761C9580, 0x4F2595BF, 0x6B5FCBF4, 0xE4D9C24E, 0xBA2F6AB5, 0xE6E3FA71, 0xF2CFC255, 0x56A50C19, 0x43AE1239, 0x77CA4254, 0x7D189A89, 0xEA7663EE, 0x84CEB554, 0xA0ADF236, 0x886512D4, 0x7D3FBDAF, 0x85C4BE4F, 0x12C8255E, 0x9AD8BD41, 0xAC154683, 0xB117598B, 0xDFD9F947, 0x63F06C7B, 0x6340DCD6, 0x3AAE6B3E, 0x26CB125A }; - return Platform::MakeFromLetters(letters); -} - -QString strNotificationAboutScreenLocked() { - const uint32 letters[] = { 0x34B47F28, 0x47E95179, 0x73D05C42, 0xB4E2A933, 0x924F22D1, 0x4265D8EA, 0x9E4D2CC2, 0x02E8157B, 0x35BF7525, 0x75901A41, 0xB0400FCC, 0xE801169D, 0x4E04B589, 0xC1CEF054, 0xAB2A7EB0, 0x5C67C4F6, 0xA4E2B954, 0xB35E12D2, 0xD598B22B, 0x4E3B8AAB, 0xBEA5E439, 0xFDA8AA3C, 0x1632DBA8, 0x88FE8965 }; - return Platform::MakeFromLetters(letters); -} - -QString strNotificationAboutScreenUnlocked() { - const uint32 letters[] = { 0xF897900B, 0x19A04630, 0x144DA6DF, 0x643CA7ED, 0x81DDA343, 0x88C6B149, 0x5F9A3A15, 0x31804E13, 0xDF2202B8, 0x9BD1B500, 0x61B92735, 0x7DDF5D43, 0xB74E06C3, 0x16FF1665, 0x9098F702, 0x4461DAF0, 0xA3134FA5, 0x52B01D3C, 0x6BC35769, 0xA7CC945D, 0x8B5327C0, 0x7630B9A0, 0x4E52E3CE, 0xED7765E3, 0xCEB7862D, 0xA06B34F0 }; - return Platform::MakeFromLetters(letters); -} - -QString strStyleOfInterface() { - const uint32 letters[] = { 0x3BBB7F05, 0xED4C5EC3, 0xC62C15A3, 0x5D10B283, 0x1BB35729, 0x63FB674D, 0xDBE5C174, 0x401EA195, 0x87B0C82A, 0x311BD596, 0x7063ECFA, 0x4AB90C27, 0xDA587DC4, 0x0B6296F8, 0xAA5603FA, 0xE1140A9F, 0x3D12D094, 0x339B5708, 0x712BA5B1 }; - return Platform::MakeFromLetters(letters); -} - -QString strTitleWrapClass() { - const uint32 letters[] = { 0x066C95DD, 0xA289D425, 0x000EF1A5, 0xB53C76AA, 0x5096391D, 0x212BF5B8, 0xE6BCA526, 0x2A5B8EC6, 0xC1457BDB, 0xA1BEE033, 0xA8ADFA11, 0xFF151585, 0x36EC257D, 0x4D96241D, 0xD0341BAA, 0xDE2908BF, 0xFE7978E8, 0x26875E1D, 0x70DA5557, 0x14C02B69, 0x7EFF7E69, 0x008D7217, 0x5EB01138 }; - return Platform::MakeFromLetters(letters); -} - -QString strTitleClass() { - const uint32 letters[] = { 0x1054BBE5, 0xA39FC333, 0x54B51E1E, 0x24895213, 0x50B71830, 0xBF07478C, 0x10BA5503, 0x5C70D3E6, 0x65079D9D, 0xACAAF939, 0x6A56C3CD }; - return Platform::MakeFromLetters(letters); -} diff --git a/Telegram/SourceFiles/platform/mac/specific_mac_p.mm b/Telegram/SourceFiles/platform/mac/specific_mac_p.mm index a3231e3e7f..e02930c1a7 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac_p.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac_p.mm @@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #if __has_include() #include #endif // __has_include() +#include #include #include #include @@ -195,7 +196,11 @@ ApplicationDelegate *_sharedDelegate = nil; "-receiveWakeNote: received, scheduling detach from audio device")); Media::Audio::ScheduleDetachFromDeviceSafe(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + QWindowSystemInterface::handleThemeChange(); +#else // Qt >= 6.5.0 Core::App().settings().setSystemDarkMode(Platform::IsDarkMode()); +#endif // Qt < 6.5.0 }); } diff --git a/Telegram/SourceFiles/platform/platform_specific.h b/Telegram/SourceFiles/platform/platform_specific.h index 794f4428b6..2056b8c877 100644 --- a/Telegram/SourceFiles/platform/platform_specific.h +++ b/Telegram/SourceFiles/platform/platform_specific.h @@ -51,10 +51,9 @@ void NewVersionLaunched(int oldVersion); [[nodiscard]] bool PreventsQuit(Core::QuitReason reason); +#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) [[nodiscard]] std::optional IsDarkMode(); -[[nodiscard]] inline bool IsDarkModeSupported() { - return IsDarkMode().has_value(); -} +#endif // Qt < 6.5.0 namespace ThirdParty { diff --git a/Telegram/SourceFiles/platform/win/integration_win.cpp b/Telegram/SourceFiles/platform/win/integration_win.cpp index c0ec35cc4f..72c1783b34 100644 --- a/Telegram/SourceFiles/platform/win/integration_win.cpp +++ b/Telegram/SourceFiles/platform/win/integration_win.cpp @@ -78,9 +78,11 @@ bool WindowsIntegration::processEvent( } break; +#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) case WM_SETTINGCHANGE: Core::App().settings().setSystemDarkMode(Platform::IsDarkMode()); break; +#endif // Qt < 6.5.0 } return false; } diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index 4cdb5021c2..39a3c8f9ae 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -587,7 +587,7 @@ void MainWindow::validateWindowTheme(bool native, bool night) { SetWindowTheme(_hWnd, empty, empty); QApplication::setStyle(QStyleFactory::create(u"Windows"_q)); #if 0 - } else if (!Platform::IsDarkModeSupported()/* + } else if (!Core::App().settings().systemDarkMode().has_value()/* || (!Dlls::AllowDarkModeForApp && !Dlls::SetPreferredAppMode) || !Dlls::AllowDarkModeForWindow || !Dlls::RefreshImmersiveColorPolicyState diff --git a/Telegram/SourceFiles/platform/win/specific_win.cpp b/Telegram/SourceFiles/platform/win/specific_win.cpp index 6dc19d35be..f8c3e80744 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.cpp +++ b/Telegram/SourceFiles/platform/win/specific_win.cpp @@ -383,6 +383,7 @@ QString SingleInstanceLocalServerName(const QString &hash) { return u"Global\\"_q + hash + '-' + cGUIDStr(); } +#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) std::optional IsDarkMode() { static const auto kSystemVersion = QOperatingSystemVersion::current(); static const auto kDarkModeAddedVersion = QOperatingSystemVersion( @@ -413,6 +414,7 @@ std::optional IsDarkMode() { return (value == 0); } +#endif // Qt < 6.5.0 bool AutostartSupported() { return true; diff --git a/Telegram/SourceFiles/settings/settings_chat.cpp b/Telegram/SourceFiles/settings/settings_chat.cpp index 545d7da526..1156bdb509 100644 --- a/Telegram/SourceFiles/settings/settings_chat.cpp +++ b/Telegram/SourceFiles/settings/settings_chat.cpp @@ -1533,7 +1533,7 @@ void SetupCloudThemes( void SetupAutoNightMode( not_null controller, not_null container) { - if (!Platform::IsDarkModeSupported()) { + if (!Core::App().settings().systemDarkMode().has_value()) { return; } diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 1aae8805b6..64850eaefd 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unixtime.h" #include "base/crc32hash.h" #include "base/never_freed_pointer.h" +#include "base/qt_signal_producer.h" #include "data/data_session.h" #include "data/data_document_resolver.h" #include "main/main_account.h" // Account::local. @@ -43,6 +44,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include #include +#include +#include namespace Window { namespace Theme { @@ -522,7 +525,24 @@ void ChatBackground::start() { checkUploadWallPaper(); }, _lifetime); +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + rpl::single( + QGuiApplication::styleHints()->colorScheme() + ) | rpl::then( + base::qt_signal_producer( + QGuiApplication::styleHints(), + &QStyleHints::colorSchemeChanged + ) + ) | rpl::map([](Qt::ColorScheme colorScheme) { + return colorScheme == Qt::ColorScheme::Unknown + ? std::nullopt + : std::make_optional(colorScheme == Qt::ColorScheme::Dark); + }) | rpl::start_with_next([](std::optional dark) { + Core::App().settings().setSystemDarkMode(dark); + }, _lifetime); +#else // Qt >= 6.5.0 Core::App().settings().setSystemDarkMode(Platform::IsDarkMode()); +#endif // Qt < 6.5.0 } void ChatBackground::refreshThemeWatcher() {