From ca1623f34a5aafd8f7d4b9044fa399c0b689b5da Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 19 Feb 2020 18:44:26 +0400 Subject: [PATCH] Use XDG Desktop Portal only when variable is set --- .../platform/linux/file_utilities_linux.cpp | 2 +- .../platform/linux/specific_linux.cpp | 32 +++++++++++++------ .../platform/linux/specific_linux.h | 1 + 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp index d1676cdba5..47dd56a411 100644 --- a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp @@ -87,7 +87,7 @@ bool NativeSupported() { #ifndef TDESKTOP_FORCE_GTK_FILE_DIALOG return false; #endif // TDESKTOP_FORCE_GTK_FILE_DIALOG - return !Platform::IsXDGDesktopPortalPresent() + return !Platform::UseXDGDesktopPortal() && Platform::internal::GdkHelperLoaded() && (Libs::gtk_widget_hide_on_delete != nullptr) && (Libs::gtk_clipboard_store != nullptr) diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index b83ddd0c72..08c9ab45cc 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -45,8 +45,6 @@ namespace { constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs; constexpr auto kSnapLauncherDir = "/var/lib/snapd/desktop/applications/"_cs; -bool XDGDesktopPortalPresent = false; - #ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION void SandboxAutostart(bool autostart) { QVariantMap options; @@ -203,9 +201,22 @@ bool InSnap() { } bool IsXDGDesktopPortalPresent() { +#ifdef TDESKTOP_DISABLE_DBUS_INTEGRATION + static const auto XDGDesktopPortalPresent = false; +#else // TDESKTOP_DISABLE_DBUS_INTEGRATION + static const auto XDGDesktopPortalPresent = QDBusInterface( + "org.freedesktop.portal.Desktop", + "/org/freedesktop/portal/desktop").isValid(); +#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION return XDGDesktopPortalPresent; } +bool UseXDGDesktopPortal() { + static const auto UsePortal = qEnvironmentVariableIsSet("TDESKTOP_USE_PORTAL") + && IsXDGDesktopPortalPresent(); + return UsePortal; +} + QString ProcessNameByPID(const QString &pid) { constexpr auto kMaxPath = 1024; char result[kMaxPath] = { 0 }; @@ -414,20 +425,21 @@ namespace Platform { void start() { FallbackFontConfig(); -#if !defined(TDESKTOP_DISABLE_DBUS_INTEGRATION) && defined(TDESKTOP_FORCE_GTK_FILE_DIALOG) +#ifdef TDESKTOP_FORCE_GTK_FILE_DIALOG LOG(("Checking for XDG Desktop Portal...")); - XDGDesktopPortalPresent = QDBusInterface( - "org.freedesktop.portal.Desktop", - "/org/freedesktop/portal/desktop").isValid(); - // this can give us a chance to use a proper file dialog for current session - if(XDGDesktopPortalPresent) { + if(IsXDGDesktopPortalPresent()) { LOG(("XDG Desktop Portal is present!")); - qputenv("QT_QPA_PLATFORMTHEME", "xdgdesktopportal"); + if(UseXDGDesktopPortal()) { + LOG(("Usage of XDG Desktop Portal is enabled.")); + qputenv("QT_QPA_PLATFORMTHEME", "xdgdesktopportal"); + } else { + LOG(("Usage of XDG Desktop Portal is disabled.")); + } } else { LOG(("XDG Desktop Portal is not present :(")); } -#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION && TDESKTOP_FORCE_GTK_FILE_DIALOG +#endif // TDESKTOP_FORCE_GTK_FILE_DIALOG } void finish() { diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.h b/Telegram/SourceFiles/platform/linux/specific_linux.h index 3ce0640ff3..f878dac711 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.h +++ b/Telegram/SourceFiles/platform/linux/specific_linux.h @@ -24,6 +24,7 @@ bool InSandbox(); bool InSnap(); bool IsXDGDesktopPortalPresent(); +bool UseXDGDesktopPortal(); QString ProcessNameByPID(const QString &pid); QString CurrentExecutablePath(int argc, char *argv[]);