diff --git a/Telegram/SourceFiles/platform/linux/integration_linux.cpp b/Telegram/SourceFiles/platform/linux/integration_linux.cpp index 147a9f03c66228..8a7db94ed4064c 100644 --- a/Telegram/SourceFiles/platform/linux/integration_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/integration_linux.cpp @@ -17,6 +17,7 @@ For license and copyright information please follow this link: #include "base/random.h" #include +#include #include #include @@ -189,24 +190,30 @@ class LinuxIntegration final : public Integration, public base::has_weak_ptr { const gi::ref_ptr _application; XdpInhibit::InhibitProxy _inhibitProxy; -#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) + rpl::variable> _darkMode; base::Platform::XDP::SettingWatcher _darkModeWatcher; -#endif // Qt < 6.5.0 + rpl::lifetime _lifetime; }; LinuxIntegration::LinuxIntegration() : _application(MakeApplication()) -#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) +, _darkMode([]() -> std::optional { + if (auto value = base::Platform::XDP::ReadSetting( + "org.freedesktop.appearance", + "color-scheme")) { + return value->get_uint32() == 1; + } + return std::nullopt; +}) , _darkModeWatcher( "org.freedesktop.appearance", "color-scheme", - [](GLib::Variant value) { + [=](GLib::Variant value) { Core::Sandbox::Instance().customEnterFromEventLoop([&] { - Core::App().settings().setSystemDarkMode(value.get_uint32() == 1); + _darkMode = value.get_uint32() == 1; }); -}) -#endif // Qt < 6.5.0 -{ + } +) { LOG(("Icon theme: %1").arg(QIcon::themeName())); LOG(("Fallback icon theme: %1").arg(QIcon::fallbackThemeName())); @@ -230,6 +237,30 @@ 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 b49cef3bbe6104..d4b438a4d4a255 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -536,13 +536,7 @@ QString SingleInstanceLocalServerName(const QString &hash) { #if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) std::optional IsDarkMode() { - auto result = base::Platform::XDP::ReadSetting( - "org.freedesktop.appearance", - "color-scheme"); - - return result.has_value() - ? std::make_optional(result->get_uint32() == 1) - : std::nullopt; + return 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 640a9b19cc9c22..899534d9e78a17 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -529,6 +529,8 @@ 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(), @@ -542,7 +544,9 @@ void ChatBackground::start() { Core::App().settings().setSystemDarkMode(dark); }, _lifetime); #else // Qt >= 6.5.0 - Core::App().settings().setSystemDarkMode(Platform::IsDarkMode()); + if (const auto dark = Platform::IsDarkMode()) { + Core::App().settings().setSystemDarkMode(dark); + } #endif // Qt < 6.5.0 }