diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 166ea6d7bf574c..9590e6934b5db7 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -32,11 +32,9 @@ For license and copyright information please follow this link: #ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION #include "base/platform/linux/base_linux_xcb_utilities.h" -#include "base/platform/linux/base_linux_xsettings.h" #endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION #include -#include #include #include #include @@ -68,7 +66,6 @@ namespace { constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs; constexpr auto kIconName = "telegram"_cs; -constexpr auto kDarkColorLimit = 192; constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs; constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs; @@ -400,6 +397,7 @@ QString GetIconName() { } std::optional IsDarkMode() { +#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION [[maybe_unused]] static const auto Inited = [] { static const auto Setter = [] { crl::on_main([] { @@ -407,140 +405,38 @@ std::optional IsDarkMode() { }); }; - QObject::connect( - qGuiApp, - &QGuiApplication::paletteChanged, - Setter); - -#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION - using base::Platform::XCB::XSettings; - if (const auto xSettings = XSettings::Instance()) { - xSettings->registerCallbackForProperty("Net/ThemeName", []( - xcb_connection_t *, - const QByteArray &, - const QVariant &, - void *) { - Setter(); - }, nullptr); - } -#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION - -#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION using XDPSettingWatcher = base::Platform::XDP::SettingWatcher; - static const XDPSettingWatcher GtkThemeWatcher( + static const XDPSettingWatcher Watcher( [=]( const Glib::ustring &group, const Glib::ustring &key, const Glib::VariantBase &value) { - if (group == "org.gnome.desktop.interface" - && key == "gtk-theme") { + if (group == "org.freedesktop.appearance" + && key == "color-scheme") { Setter(); } }); - static const XDPSettingWatcher KdeColorSchemeWatcher( - [=]( - const Glib::ustring &group, - const Glib::ustring &key, - const Glib::VariantBase &value) { - if (group == "org.kde.kdeglobals.General" - && key == "ColorScheme") { - Setter(); - } - }); -#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION - return true; }(); - std::optional result; - - const auto styleName = QApplication::style()->metaObject()->className(); - if (styleName != qstr("QFusionStyle") - && styleName != qstr("QWindowsStyle")) { - result = false; - - const auto paletteBackgroundGray = qGray( - QPalette().color(QPalette::Window).rgb()); - - if (paletteBackgroundGray < kDarkColorLimit) { - result = true; - return result; - } - } - -#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION - using base::Platform::XCB::XSettings; - if (const auto xSettings = XSettings::Instance()) { - const auto gtkThemeX = xSettings->setting("Net/ThemeName"); - if (gtkThemeX.isValid()) { - result = false; - if (gtkThemeX.toString().contains( - qsl("-dark"), - Qt::CaseInsensitive)) { - result = true; - return result; - } - } - } -#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION - -#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION try { - using namespace base::Platform::XDP; - - const auto gtkThemePortal = ReadSetting( - "org.gnome.desktop.interface", - "gtk-theme"); - - if (gtkThemePortal.has_value()) { - const auto gtkThemePortalString = QString::fromStdString( - base::Platform::GlibVariantCast( - *gtkThemePortal)); - - result = false; - - if (gtkThemePortalString.contains( - qsl("-dark"), - Qt::CaseInsensitive)) { - result = true; - return result; - } - } - } catch (...) { - } - - try { - using namespace base::Platform::XDP; - - const auto kdeBackgroundColorOptional = ReadSetting( - "org.kde.kdeglobals.Colors:Window", - "BackgroundNormal"); - - if (kdeBackgroundColorOptional.has_value()) { - const auto kdeBackgroundColorList = QString::fromStdString( - base::Platform::GlibVariantCast( - *kdeBackgroundColorOptional)).split(','); - - if (kdeBackgroundColorList.size() >= 3) { - result = false; - - const auto kdeBackgroundGray = qGray( - kdeBackgroundColorList[0].toInt(), - kdeBackgroundColorList[1].toInt(), - kdeBackgroundColorList[2].toInt()); - - if (kdeBackgroundGray < kDarkColorLimit) { - result = true; - return result; - } + const auto result = base::Platform::XDP::ReadSetting( + "org.freedesktop.appearance", + "color-scheme"); + + if (result.has_value()) { + const auto value = base::Platform::GlibVariantCast(*result); + if (value == 1) { + return true; } + return false; } } catch (...) { } #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION - return result; + return std::nullopt; } bool AutostartSupported() {