From 7f29f57c3dd9bb432a71137538d84340910b6215 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Mon, 1 Jun 2020 12:33:24 +0400 Subject: [PATCH] Use custom gtk file dialog only on gtk-based DEs --- .../platform/linux/file_utilities_linux.cpp | 14 ++++++++++---- .../SourceFiles/platform/linux/specific_linux.cpp | 10 +++++----- .../SourceFiles/platform/linux/specific_linux.h | 2 +- Telegram/cmake/telegram_options.cmake | 10 +++++----- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp index bb7445ef0b..d135160511 100644 --- a/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/file_utilities_linux.cpp @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/linux/linux_libs.h" #include "platform/linux/linux_gdk_helper.h" +#include "platform/linux/linux_desktop_environment.h" #include "platform/linux/specific_linux.h" #include "core/application.h" #include "mainwindow.h" @@ -124,10 +125,15 @@ using Type = ::FileDialog::internal::Type; #ifndef TDESKTOP_DISABLE_GTK_INTEGRATION bool NativeSupported(Type type = Type::ReadFile) { -#ifndef TDESKTOP_FORCE_GTK_FILE_DIALOG - return false; -#endif // TDESKTOP_FORCE_GTK_FILE_DIALOG - return (!Platform::UseXDGDesktopPortal() || type == Type::ReadFolder) + // use gtk file dialog on gtk-based desktop environments + // or if QT_QPA_PLATFORMTHEME=(gtk2|gtk3) + // or if portals is used and operation is not to open folder + // (it isn't supported by portals yet) + return Platform::UseGtkFileDialog() + && (Platform::DesktopEnvironment::IsGtkBased() + || Platform::IsGtkIntegrationForced() + || Platform::UseXDGDesktopPortal()) + && (!Platform::UseXDGDesktopPortal() || type == Type::ReadFolder) && 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 c902ceff77..5ba4d782fc 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -277,12 +277,12 @@ bool IsGtkIntegrationForced() { return false; } -bool IsGtkFileDialogForced() { -#ifdef TDESKTOP_FORCE_GTK_FILE_DIALOG +bool UseGtkFileDialog() { +#ifdef TDESKTOP_USE_GTK_FILE_DIALOG return true; -#else // TDESKTOP_FORCE_GTK_FILE_DIALOG +#else // TDESKTOP_USE_GTK_FILE_DIALOG return false; -#endif // !TDESKTOP_FORCE_GTK_FILE_DIALOG +#endif // !TDESKTOP_USE_GTK_FILE_DIALOG } bool IsQtPluginsBundled() { @@ -668,7 +668,7 @@ void start() { if(IsStaticBinary() || InAppImage() || InSnap() - || IsGtkFileDialogForced() + || UseGtkFileDialog() || IsQtPluginsBundled()) { LOG(("Checking for XDG Desktop Portal...")); // this can give us a chance to use a proper file dialog for current session diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.h b/Telegram/SourceFiles/platform/linux/specific_linux.h index e6fca0147e..0651c3c0e7 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.h +++ b/Telegram/SourceFiles/platform/linux/specific_linux.h @@ -25,7 +25,7 @@ bool InSnap(); bool InAppImage(); bool IsStaticBinary(); bool IsGtkIntegrationForced(); -bool IsGtkFileDialogForced(); +bool UseGtkFileDialog(); bool IsQtPluginsBundled(); bool IsXDGDesktopPortalPresent(); diff --git a/Telegram/cmake/telegram_options.cmake b/Telegram/cmake/telegram_options.cmake index 7dd50e8ee0..d6bde1b9b9 100644 --- a/Telegram/cmake/telegram_options.cmake +++ b/Telegram/cmake/telegram_options.cmake @@ -5,7 +5,7 @@ # https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL option(TDESKTOP_USE_FONTCONFIG_FALLBACK "Use custom fonts.conf (Linux only)." OFF) -option(TDESKTOP_FORCE_GTK_FILE_DIALOG "Force using GTK file dialog (Linux only)." OFF) +option(TDESKTOP_USE_GTK_FILE_DIALOG "Use custom code for GTK file dialog (Linux only)." OFF) option(TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME "Disable automatic 'tg://' URL scheme handler registration." ${DESKTOP_APP_USE_PACKAGED}) option(TDESKTOP_DISABLE_NETWORK_PROXY "Disable all code for working through Socks5 or MTProxy." OFF) option(TDESKTOP_USE_PACKAGED_TGVOIP "Find libtgvoip using CMake instead of bundled one." ${DESKTOP_APP_USE_PACKAGED}) @@ -43,10 +43,10 @@ if (TDESKTOP_API_ID STREQUAL "0" OR TDESKTOP_API_HASH STREQUAL "") endif() if (NOT DESKTOP_APP_USE_PACKAGED) - set(TDESKTOP_FORCE_GTK_FILE_DIALOG ON) + set(TDESKTOP_USE_GTK_FILE_DIALOG ON) endif() -if (NOT TDESKTOP_FORCE_GTK_FILE_DIALOG) +if (NOT TDESKTOP_USE_GTK_FILE_DIALOG) set(TDESKTOP_DISABLE_GTK_INTEGRATION ON) endif() @@ -68,8 +68,8 @@ if (TDESKTOP_USE_FONTCONFIG_FALLBACK) target_compile_definitions(Telegram PRIVATE TDESKTOP_USE_FONTCONFIG_FALLBACK) endif() -if (TDESKTOP_FORCE_GTK_FILE_DIALOG) - target_compile_definitions(Telegram PRIVATE TDESKTOP_FORCE_GTK_FILE_DIALOG) +if (TDESKTOP_USE_GTK_FILE_DIALOG) + target_compile_definitions(Telegram PRIVATE TDESKTOP_USE_GTK_FILE_DIALOG) endif() if (TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME)