Use custom gtk file dialog only on gtk-based DEs

This commit is contained in:
Ilya Fedin 2020-06-01 12:33:24 +04:00 committed by John Preston
parent 1fb1d57a27
commit 7f29f57c3d
4 changed files with 21 additions and 15 deletions

View File

@ -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)

View File

@ -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

View File

@ -25,7 +25,7 @@ bool InSnap();
bool InAppImage();
bool IsStaticBinary();
bool IsGtkIntegrationForced();
bool IsGtkFileDialogForced();
bool UseGtkFileDialog();
bool IsQtPluginsBundled();
bool IsXDGDesktopPortalPresent();

View File

@ -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)