diff options
author | Ilya Fedin <fedin-ilja2010@ya.ru> | 2021-09-03 19:49:48 +0400 |
---|---|---|
committer | John Preston <johnprestonmail@gmail.com> | 2021-09-06 15:43:28 +0300 |
commit | 05d4d58f8bd1b550d23598760a91c39fbde8f8dd (patch) | |
tree | d9846536bf8864b79afff5c95c14849829de03af | |
parent | 434a7c5293d7bf0c1e957d4a17b340239df95f93 (diff) |
Replace GTK integration with xsettings + XDP
-rw-r--r-- | .github/workflows/linux.yml | 3 | ||||
-rw-r--r-- | Telegram/CMakeLists.txt | 13 | ||||
-rw-r--r-- | Telegram/SourceFiles/platform/linux/launcher_linux.cpp | 13 | ||||
-rw-r--r-- | Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp | 100 | ||||
-rw-r--r-- | Telegram/SourceFiles/platform/linux/linux_gtk_integration.h | 27 | ||||
-rw-r--r-- | Telegram/SourceFiles/platform/linux/linux_gtk_integration_dummy.cpp | 24 | ||||
-rw-r--r-- | Telegram/SourceFiles/platform/linux/specific_linux.cpp | 264 | ||||
m--------- | Telegram/lib_base | 0 | ||||
m--------- | Telegram/lib_ui | 0 | ||||
m--------- | cmake | 0 |
10 files changed, 140 insertions, 304 deletions
diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index d7d1f7355f..20de577a16 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -62,7 +62,6 @@ jobs: - "DESKTOP_APP_DISABLE_DBUS_INTEGRATION" - "DESKTOP_APP_DISABLE_X11_INTEGRATION" - "DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION" - - "DESKTOP_APP_DISABLE_GTK_INTEGRATION" env: UPLOAD_ARTIFACT: "false" @@ -90,7 +89,7 @@ jobs: if [ -n "${{ matrix.defines }}" ]; then DEFINE="-D ${{ matrix.defines }}=ON" if [ "${{ matrix.defines }}" == "DESKTOP_APP_DISABLE_DBUS_INTEGRATION" ]; then - DEFINE="$DEFINE -D DESKTOP_APP_DISABLE_GTK_INTEGRATION=ON -D DESKTOP_APP_DISABLE_WEBKITGTK=ON" + DEFINE="$DEFINE -D DESKTOP_APP_DISABLE_WEBKITGTK=ON" fi echo Define from matrix: $DEFINE echo "ARTIFACT_NAME=Telegram_${{ matrix.defines }}" >> $GITHUB_ENV diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index a9b7424666..ee65bcb8dc 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -860,9 +860,6 @@ PRIVATE payments/payments_form.h platform/linux/linux_desktop_environment.cpp platform/linux/linux_desktop_environment.h - platform/linux/linux_gtk_integration_dummy.cpp - platform/linux/linux_gtk_integration.cpp - platform/linux/linux_gtk_integration.h platform/linux/linux_wayland_integration_dummy.cpp platform/linux/linux_wayland_integration.cpp platform/linux/linux_wayland_integration.h @@ -1165,16 +1162,6 @@ else() ) endif() -if (DESKTOP_APP_DISABLE_GTK_INTEGRATION) - remove_target_sources(Telegram ${src_loc} - platform/linux/linux_gtk_integration.cpp - ) -else() - remove_target_sources(Telegram ${src_loc} - platform/linux/linux_gtk_integration_dummy.cpp - ) -endif() - if (DESKTOP_APP_USE_PACKAGED) remove_target_sources(Telegram ${src_loc} platform/mac/mac_iconv_helper.c diff --git a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp index 9c3caa54a1..a6109d86fe 100644 --- a/Telegram/SourceFiles/platform/linux/launcher_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/launcher_linux.cpp @@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/crash_reports.h" #include "core/update_checker.h" -#include "base/platform/linux/base_linux_gtk_integration.h" #ifndef DESKTOP_APP_DISABLE_WEBKITGTK #include "webview/platform/linux/webview_linux_webkit2gtk.h" @@ -63,20 +62,14 @@ int Launcher::exec() { Glib::init(); Gio::init(); - for (auto i = begin(_arguments), e = end(_arguments); i != e; ++i) { - if (*i == "-basegtkintegration" && std::distance(i, e) > 2) { - BaseGtkIntegration::SetServiceName(QString::fromStdString(*(i + 2))); - if (const auto integration = BaseGtkIntegration::Instance()) { - return integration->exec(QString::fromStdString(*(i + 1))); - } - return 1; #ifndef DESKTOP_APP_DISABLE_WEBKITGTK - } else if (*i == "-webviewhelper" && std::distance(i, e) > 2) { + for (auto i = begin(_arguments), e = end(_arguments); i != e; ++i) { + if (*i == "-webviewhelper" && std::distance(i, e) > 2) { Webview::WebKit2Gtk::SetServiceName(*(i + 2)); return Webview::WebKit2Gtk::Exec(*(i + 1)); -#endif // !DESKTOP_APP_DISABLE_WEBKITGTK } } +#endif // !DESKTOP_APP_DISABLE_WEBKITGTK return Core::Launcher::exec(); } diff --git a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp b/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp deleted file mode 100644 index 976970d6bd..0000000000 --- a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#include "platform/linux/linux_gtk_integration.h" - -#ifdef DESKTOP_APP_DISABLE_DBUS_INTEGRATION -#error "GTK integration depends on D-Bus integration." -#endif // DESKTOP_APP_DISABLE_DBUS_INTEGRATION - -#include "base/platform/linux/base_linux_gtk_integration.h" -#include "base/platform/linux/base_linux_dbus_utilities.h" -#include "base/platform/base_platform_info.h" - -#include <QtCore/QProcess> - -#include <glibmm.h> - -namespace Platform { -namespace internal { -namespace { - -constexpr auto kBaseService = "org.telegram.desktop.BaseGtkIntegration-%1"_cs; - -using BaseGtkIntegration = base::Platform::GtkIntegration; - -} // namespace - -QString GtkIntegration::AllowedBackends() { - return Platform::IsWayland() - ? qsl("wayland,x11") - : Platform::IsX11() - ? qsl("x11,wayland") - : QString(); -} - -void GtkIntegration::Start(Type type) { - if (type != Type::Base) { - return; - } - - const auto d = QFile::encodeName(QDir(cWorkingDir()).absolutePath()); - char h[33] = { 0 }; - hashMd5Hex(d.constData(), d.size(), h); - - BaseGtkIntegration::SetServiceName(kBaseService.utf16().arg(h)); - - const auto dbusName = [] { - try { - static const auto connection = Gio::DBus::Connection::get_sync( - Gio::DBus::BusType::BUS_TYPE_SESSION); - - return QString::fromStdString(connection->get_unique_name()); - } catch (...) { - return QString(); - } - }(); - - if (dbusName.isEmpty()) { - return; - } - - QProcess::startDetached(cExeDir() + cExeName(), { - qsl("-basegtkintegration"), - dbusName, - kBaseService.utf16().arg(h), - }); -} - -void GtkIntegration::Autorestart(Type type) { - if (type != Type::Base) { - return; - } - - try { - static const auto connection = Gio::DBus::Connection::get_sync( - Gio::DBus::BusType::BUS_TYPE_SESSION); - - base::Platform::DBus::RegisterServiceWatcher( - connection, - Glib::ustring(BaseGtkIntegration::ServiceName().toStdString()), - [=]( - const Glib::ustring &service, - const Glib::ustring &oldOwner, - const Glib::ustring &newOwner) { - if (newOwner.empty()) { - Start(type); - } else if (const auto integration = BaseGtkIntegration::Instance()) { - integration->load(AllowedBackends()); - } - }); - } catch (...) { - } -} - -} // namespace internal -} // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.h b/Telegram/SourceFiles/platform/linux/linux_gtk_integration.h deleted file mode 100644 index f0229ac13b..0000000000 --- a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#pragma once - -namespace Platform { -namespace internal { - -class GtkIntegration { -public: - enum class Type { - Base, - }; - - static QString AllowedBackends(); - - static void Start(Type type); - - static void Autorestart(Type type); -}; - -} // namespace internal -} // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/linux_gtk_integration_dummy.cpp b/Telegram/SourceFiles/platform/linux/linux_gtk_integration_dummy.cpp deleted file mode 100644 index 66a4fb5422..0000000000 --- a/Telegram/SourceFiles/platform/linux/linux_gtk_integration_dummy.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#include "platform/linux/linux_gtk_integration.h" - -namespace Platform { -namespace internal { - -QString GtkIntegration::AllowedBackends() { - return {}; -} - -void GtkIntegration::Start(Type type) { -} - -void GtkIntegration::Autorestart(Type type) { -} - -} // namespace internal -} // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 581077e2b4..954ce295b3 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -10,10 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/openssl_help.h" #include "base/platform/base_platform_info.h" #include "base/platform/linux/base_linux_glibmm_helper.h" -#include "base/platform/linux/base_linux_gtk_integration.h" #include "ui/platform/linux/ui_linux_wayland_integration.h" #include "platform/linux/linux_desktop_environment.h" -#include "platform/linux/linux_gtk_integration.h" #include "platform/linux/linux_wayland_integration.h" #include "base/qt_adapters.h" #include "lang/lang_keys.h" @@ -33,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #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 #ifndef DESKTOP_APP_DISABLE_WEBKITGTK @@ -64,10 +63,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include <iostream> using namespace Platform; -using BaseGtkIntegration = base::Platform::GtkIntegration; using UiWaylandIntegration = Ui::Platform::WaylandIntegration; using Platform::internal::WaylandIntegration; -using Platform::internal::GtkIntegration; namespace Platform { namespace { @@ -340,15 +337,104 @@ bool GenerateDesktopFile( } } -void SetDarkMode() { +} // namespace + +void SetApplicationIcon(const QIcon &icon) { + QApplication::setWindowIcon(icon); +} + +bool InFlatpak() { + static const auto Result = QFileInfo::exists(qsl("/.flatpak-info")); + return Result; +} + +bool InSnap() { + static const auto Result = qEnvironmentVariableIsSet("SNAP"); + return Result; +} + +QString AppRuntimeDirectory() { + static const auto Result = [&] { + auto runtimeDir = QStandardPaths::writableLocation( + QStandardPaths::RuntimeLocation); + + if (InFlatpak()) { + runtimeDir += qsl("/app/") + FlatpakID(); + } + + if (!QFileInfo::exists(runtimeDir)) { // non-systemd distros + runtimeDir = QDir::tempPath(); + } + + if (!runtimeDir.endsWith('/')) { + runtimeDir += '/'; + } + + return runtimeDir; + }(); + + return Result; +} + +QString SingleInstanceLocalServerName(const QString &hash) { + const auto idealSocketPath = AppRuntimeDirectory() + + hash + + '-' + + cGUIDStr(); + + if (idealSocketPath.size() >= 108) { + return AppRuntimeDirectory() + hash; + } else { + return idealSocketPath; + } +} + +QString GetIconName() { + static const auto Result = InFlatpak() + ? FlatpakID() + : kIconName.utf16(); + return Result; +} + +std::optional<bool> IsDarkMode() { [[maybe_unused]] static const auto Inited = [] { + static const auto Setter = [] { + crl::on_main([] { + Core::App().settings().setSystemDarkMode(IsDarkMode()); + }); + }; + QObject::connect( qGuiApp, &QGuiApplication::paletteChanged, - SetDarkMode); + 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( + [=]( + const Glib::ustring &group, + const Glib::ustring &key, + const Glib::VariantBase &value) { + if (group == "org.gnome.desktop.interface" + && key == "gtk-theme") { + Setter(); + } + }); + static const XDPSettingWatcher KdeColorSchemeWatcher( [=]( const Glib::ustring &group, @@ -356,33 +442,15 @@ void SetDarkMode() { const Glib::VariantBase &value) { if (group == "org.kde.kdeglobals.General" && key == "ColorScheme") { - SetDarkMode(); + Setter(); } }); #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION - const auto integration = BaseGtkIntegration::Instance(); - if (integration) { - integration->connectToSetting( - "gtk-theme-name", - SetDarkMode); - - if (integration->checkVersion(3, 0, 0)) { - integration->connectToSetting( - "gtk-application-prefer-dark-theme", - SetDarkMode); - } - } - return true; }(); std::optional<bool> result; - const auto setter = gsl::finally([&] { - crl::on_main([=] { - Core::App().settings().setSystemDarkMode(result); - }); - }); const auto styleName = QApplication::style()->metaObject()->className(); if (styleName != qstr("QFusionStyle") @@ -394,14 +462,54 @@ void SetDarkMode() { if (paletteBackgroundGray < kDarkColorLimit) { result = true; - return; + 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<Glib::ustring>( + *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"); @@ -421,7 +529,7 @@ void SetDarkMode() { if (kdeBackgroundGray < kDarkColorLimit) { result = true; - return; + return result; } } } @@ -429,97 +537,7 @@ void SetDarkMode() { } #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION - const auto integration = BaseGtkIntegration::Instance(); - if (integration) { - if (integration->checkVersion(3, 0, 0)) { - const auto preferDarkTheme = integration->getBoolSetting( - qsl("gtk-application-prefer-dark-theme")); - - if (preferDarkTheme.has_value()) { - result = false; - - if (*preferDarkTheme) { - result = true; - return; - } - } - } - - const auto themeName = integration->getStringSetting( - qsl("gtk-theme-name")); - - if (themeName.has_value()) { - result = false; - - if (themeName->contains(qsl("-dark"), Qt::CaseInsensitive)) { - result = true; - return; - } - } - } -} - -} // namespace - -void SetApplicationIcon(const QIcon &icon) { - QApplication::setWindowIcon(icon); -} - -bool InFlatpak() { - static const auto Result = QFileInfo::exists(qsl("/.flatpak-info")); - return Result; -} - -bool InSnap() { - static const auto Result = qEnvironmentVariableIsSet("SNAP"); - return Result; -} - -QString AppRuntimeDirectory() { - static const auto Result = [&] { - auto runtimeDir = QStandardPaths::writableLocation( - QStandardPaths::RuntimeLocation); - - if (InFlatpak()) { - runtimeDir += qsl("/app/") + FlatpakID(); - } - - if (!QFileInfo::exists(runtimeDir)) { // non-systemd distros - runtimeDir = QDir::tempPath(); - } - - if (!runtimeDir.endsWith('/')) { - runtimeDir += '/'; - } - - return runtimeDir; - }(); - - return Result; -} - -QString SingleInstanceLocalServerName(const QString &hash) { - const auto idealSocketPath = AppRuntimeDirectory() - + hash - + '-' - + cGUIDStr(); - - if (idealSocketPath.size() >= 108) { - return AppRuntimeDirectory() + hash; - } else { - return idealSocketPath; - } -} - -QString GetIconName() { - static const auto Result = InFlatpak() - ? FlatpakID() - : kIconName.utf16(); - return Result; -} - -std::optional<bool> IsDarkMode() { - return Core::App().settings().systemDarkMode(); + return result; } bool AutostartSupported() { @@ -653,8 +671,6 @@ void start() { Glib::set_prgname(cExeName().toStdString()); Glib::set_application_name(std::string(AppName)); - GtkIntegration::Start(GtkIntegration::Type::Base); - #ifndef DESKTOP_APP_DISABLE_WEBKITGTK const auto d = QFile::encodeName(QDir(cWorkingDir()).absolutePath()); char h[33] = { 0 }; @@ -792,19 +808,11 @@ void start() { LOG(("Icon theme: %1").arg(QIcon::themeName())); LOG(("Fallback icon theme: %1").arg(QIcon::fallbackThemeName())); - GtkIntegration::Autorestart(GtkIntegration::Type::Base); - - if (const auto integration = BaseGtkIntegration::Instance()) { - integration->load(GtkIntegration::AllowedBackends()); - } - // wait for interface announce to know if native window frame is supported if (const auto integration = UiWaylandIntegration::Instance()) { integration->waitForInterfaceAnnounce(); } - crl::async(SetDarkMode); - #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION FileDialog::XDP::Start(); #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION diff --git a/Telegram/lib_base b/Telegram/lib_base -Subproject e3591a6778ba63affb039eec7798740815ea12d +Subproject 4ccf5d6c8c7f04a3b4b583f713ada2434f3d824 diff --git a/Telegram/lib_ui b/Telegram/lib_ui -Subproject 29f339e26e11af5d56c5da1d6536bee0233d519 +Subproject af1429cb87d765be7e70308a318ee20d2478ae7 diff --git a/cmake b/cmake -Subproject 995b1e4cbd4ba0c02cb7432401bef029f480d69 +Subproject 95ee188c7b86b4448acbcfb01a42ac139cee638 |