From 39b90092ff320d6ef2fee038de55b90db980f768 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 25 Jan 2025 16:17:34 +0400 Subject: [PATCH] Revert "Fallback to portal on Linux if QStyleHints::colorScheme is unknown" This reverts commit a88f48cd935dee313bd727c2cdc9600b6f99769d. --- .../platform/linux/integration_linux.cpp | 47 ++++--------------- .../platform/linux/specific_linux.cpp | 8 +++- .../window/themes/window_theme.cpp | 6 +-- 3 files changed, 16 insertions(+), 45 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/integration_linux.cpp b/Telegram/SourceFiles/platform/linux/integration_linux.cpp index e048a2d05..147a9f03c 100644 --- a/Telegram/SourceFiles/platform/linux/integration_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/integration_linux.cpp @@ -17,7 +17,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/random.h" #include -#include #include #include @@ -190,30 +189,24 @@ private: const gi::ref_ptr _application; XdpInhibit::InhibitProxy _inhibitProxy; - rpl::variable> _darkMode; +#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) base::Platform::XDP::SettingWatcher _darkModeWatcher; - rpl::lifetime _lifetime; +#endif // Qt < 6.5.0 }; LinuxIntegration::LinuxIntegration() : _application(MakeApplication()) -, _darkMode([]() -> std::optional { - if (auto value = base::Platform::XDP::ReadSetting( - "org.freedesktop.appearance", - "color-scheme")) { - return value->get_uint32() == 1; - } - return std::nullopt; -}()) +#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) , _darkModeWatcher( "org.freedesktop.appearance", "color-scheme", - [=](GLib::Variant value) { + [](GLib::Variant value) { Core::Sandbox::Instance().customEnterFromEventLoop([&] { - _darkMode = value.get_uint32() == 1; + Core::App().settings().setSystemDarkMode(value.get_uint32() == 1); }); - } -) { +}) +#endif // Qt < 6.5.0 +{ LOG(("Icon theme: %1").arg(QIcon::themeName())); LOG(("Fallback icon theme: %1").arg(QIcon::fallbackThemeName())); @@ -237,30 +230,6 @@ void LinuxIntegration::init() { initInhibit(); })); - - _darkMode.value() -#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) - | rpl::filter([] { - return QGuiApplication::styleHints()->colorScheme() - == Qt::ColorScheme::Unknown; - }) -#endif // Qt >= 6.5.0 - | rpl::start_with_next([](std::optional value) { - Core::App().settings().setSystemDarkMode(value); - }, _lifetime); - -#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) - Core::App().settings().systemDarkModeValue( - ) | rpl::filter([=](std::optional value) { - return !value && _darkMode.current(); - }) | rpl::start_with_next([=] { - crl::on_main(this, [=] { - if (!Core::App().settings().systemDarkMode()) { - Core::App().settings().setSystemDarkMode(_darkMode.current()); - } - }); - }, _lifetime); -#endif // Qt >= 6.5.0 } void LinuxIntegration::initInhibit() { diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 19b0c68d9..c460d1e1c 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -535,7 +535,13 @@ QString SingleInstanceLocalServerName(const QString &hash) { #if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) std::optional IsDarkMode() { - return std::nullopt; + auto result = base::Platform::XDP::ReadSetting( + "org.freedesktop.appearance", + "color-scheme"); + + return result.has_value() + ? std::make_optional(result->get_uint32() == 1) + : std::nullopt; } #endif // Qt < 6.5.0 diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index dcdbfcccd..ff7c9650f 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -529,8 +529,6 @@ void ChatBackground::start() { #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) rpl::single( QGuiApplication::styleHints()->colorScheme() - ) | rpl::filter( - rpl::mappers::_1 != Qt::ColorScheme::Unknown ) | rpl::then( base::qt_signal_producer( QGuiApplication::styleHints(), @@ -544,9 +542,7 @@ void ChatBackground::start() { Core::App().settings().setSystemDarkMode(dark); }, _lifetime); #else // Qt >= 6.5.0 - if (const auto dark = Platform::IsDarkMode()) { - Core::App().settings().setSystemDarkMode(dark); - } + Core::App().settings().setSystemDarkMode(Platform::IsDarkMode()); #endif // Qt < 6.5.0 }