From 414456d00338a513d2cfa51e6a2c1ba7f2ad1baf Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Tue, 10 Aug 2021 17:15:05 +0400 Subject: [PATCH] Revert "Use gtk clipboard when available to avoid https://bugreports.qt.io/browse/QTBUG-56595" Fixed in Qt by https://codereview.qt-project.org/c/qt/qtbase/+/306771 This reverts commit 3a91003eeacb038032499d60f3a47e3ef6e4c14f. --- Telegram/CMakeLists.txt | 2 - .../SourceFiles/boxes/edit_caption_box.cpp | 5 +- Telegram/SourceFiles/boxes/send_files_box.cpp | 6 +- .../SourceFiles/history/history_widget.cpp | 6 +- .../view/history_view_replies_section.cpp | 6 +- .../view/history_view_scheduled_section.cpp | 6 +- .../platform/linux/linux_gtk_integration.cpp | 186 ------------------ .../platform/linux/linux_gtk_integration.h | 2 - .../linux/linux_gtk_integration_dummy.cpp | 4 - .../platform/linux/linux_gtk_integration_p.h | 6 - .../platform/linux/specific_linux.cpp | 8 - .../SourceFiles/platform/mac/specific_mac.h | 4 - .../SourceFiles/platform/platform_specific.h | 1 - .../SourceFiles/platform/win/specific_win.h | 4 - 14 files changed, 5 insertions(+), 241 deletions(-) diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index cb484ff5fe..3df81d83f8 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -1298,8 +1298,6 @@ else() if (NOT DESKTOP_APP_DISABLE_X11_INTEGRATION) target_link_libraries(Telegram PRIVATE X11) endif() - - target_link_libraries(Telegram PRIVATE rt) endif() endif() diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index 3b198bb4c2..e99924643a 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -67,10 +67,7 @@ auto ListFromMimeData(not_null data) { if (result.error == Error::None) { return result; } else if (data->hasImage()) { - auto image = Platform::GetImageFromClipboard(); - if (image.isNull()) { - image = qvariant_cast(data->imageData()); - } + auto image = qvariant_cast(data->imageData()); if (!image.isNull()) { return Storage::PrepareMediaFromImage( std::move(image), diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index 283f6f1d06..08eecbe1c0 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "boxes/send_files_box.h" -#include "platform/platform_specific.h" #include "lang/lang_keys.h" #include "storage/localstorage.h" #include "storage/storage_media_prepare.h" @@ -799,10 +798,7 @@ bool SendFilesBox::addFiles(not_null data) { if (result.error == Ui::PreparedList::Error::None) { return result; } else if (data->hasImage()) { - auto image = Platform::GetImageFromClipboard(); - if (image.isNull()) { - image = qvariant_cast(data->imageData()); - } + auto image = qvariant_cast(data->imageData()); if (!image.isNull()) { return Storage::PrepareMediaFromImage( std::move(image), diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 8dd8317422..07ea802bae 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -88,7 +88,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "chat_helpers/bot_keyboard.h" #include "chat_helpers/message_field.h" #include "chat_helpers/send_context_menu.h" -#include "platform/platform_specific.h" #include "mtproto/mtproto_config.h" #include "lang/lang_keys.h" #include "mainwidget.h" @@ -4491,10 +4490,7 @@ bool HistoryWidget::confirmSendingFiles( } if (hasImage) { - auto image = Platform::GetImageFromClipboard(); - if (image.isNull()) { - image = qvariant_cast(data->imageData()); - } + auto image = qvariant_cast(data->imageData()); if (!image.isNull()) { confirmSendingFiles( std::move(image), diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 0174fb380c..2d1d522048 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -55,7 +55,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_media_prepare.h" #include "storage/storage_account.h" #include "inline_bots/inline_bot_result.h" -#include "platform/platform_specific.h" #include "lang/lang_keys.h" #include "facades.h" #include "styles/style_chat.h" @@ -598,10 +597,7 @@ bool RepliesWidget::confirmSendingFiles( } if (hasImage) { - auto image = Platform::GetImageFromClipboard(); - if (image.isNull()) { - image = qvariant_cast(data->imageData()); - } + auto image = qvariant_cast(data->imageData()); if (!image.isNull()) { confirmSendingFiles( std::move(image), diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index a15735f77c..234c35e2bf 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -48,7 +48,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/storage_media_prepare.h" #include "storage/storage_account.h" #include "inline_bots/inline_bot_result.h" -#include "platform/platform_specific.h" #include "lang/lang_keys.h" #include "facades.h" #include "styles/style_chat.h" @@ -338,10 +337,7 @@ bool ScheduledWidget::confirmSendingFiles( } if (hasImage) { - auto image = Platform::GetImageFromClipboard(); - if (image.isNull()) { - image = qvariant_cast(data->imageData()); - } + auto image = qvariant_cast(data->imageData()); if (!image.isNull()) { confirmSendingFiles( std::move(image), diff --git a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp b/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp index 60f109c9dd..4cac96d1d1 100644 --- a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp @@ -32,10 +32,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include -#include -#include -#include - namespace Platform { namespace internal { @@ -49,7 +45,6 @@ constexpr auto kBaseService = "org.telegram.desktop.BaseGtkIntegration-%1"_cs; constexpr auto kWebviewService = "org.telegram.desktop.GtkIntegration.WebviewHelper-%1-%2"_cs; constexpr auto kObjectPath = "/org/telegram/desktop/GtkIntegration"_cs; constexpr auto kInterface = "org.telegram.desktop.GtkIntegration"_cs; -constexpr auto kGifcShmId = "tdesktop-gtk-gifc"_cs; constexpr auto kIntrospectionXML = R"INTROSPECTION( @@ -60,74 +55,14 @@ constexpr auto kIntrospectionXML = R"INTROSPECTION( - - - - )INTROSPECTION"_cs; -struct GtkSelectionDataDeleter { - void operator()(GtkSelectionData *gsel) { - if (gsel) { - gtk_selection_data_free(gsel); - } - } -}; - -using GtkSelectionDataPointer = std::unique_ptr; - Glib::ustring ServiceName; -bool GetImageFromClipboardSupported() { - return (gtk_clipboard_get != nullptr) - && (gtk_clipboard_wait_for_contents != nullptr) - && (gtk_selection_data_get_data != nullptr) - && (gtk_selection_data_get_length != nullptr) - && (gtk_selection_data_free != nullptr) - && (gdk_atom_intern != nullptr); -} - -std::vector GetImageFromClipboard() { - if (!GetImageFromClipboardSupported()) { - return {}; - } - - const auto clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); - if (!clipboard) { - return {}; - } - - static const auto supportedFormats = { - gdk_atom_intern("image/png", true), - gdk_atom_intern("image/jpeg", true), - gdk_atom_intern("image/gif", true), - gdk_atom_intern("image/bmp", true), - }; - - const auto gsel = [&]() -> GtkSelectionDataPointer { - for (const auto &format : supportedFormats) { - if (auto result = GtkSelectionDataPointer( - gtk_clipboard_wait_for_contents(clipboard, format)) - ; result && gtk_selection_data_get_length(result.get()) > 0) { - return result; - } - } - return nullptr; - }(); - - if (!gsel) { - return {}; - } - - const auto data = gtk_selection_data_get_data(gsel.get()); - const auto length = gtk_selection_data_get_length(gsel.get()); - return std::vector(data, data + length); -} - } // namespace class GtkIntegration::Private { @@ -226,57 +161,6 @@ void GtkIntegration::Private::handleMethodCall( invocation->return_value({}); return; } - } else if (method_name == "GetImageFromClipboard") { - const auto image = GetImageFromClipboard(); - if (!image.empty()) { - const auto fd = shm_open( - kGifcShmId.utf8().constData(), - O_RDWR | O_CREAT, - S_IRUSR | S_IWUSR); - - if (fd == -1) { - throw std::exception(); - } - - const auto fdGuard = gsl::finally([&] { - close(fd); - shm_unlink(kGifcShmId.utf8().constData()); - }); - - if (ftruncate(fd, image.size())) { - throw std::exception(); - } - - const auto mapped = mmap( - nullptr, - image.size(), - PROT_WRITE, - MAP_SHARED, - fd, - 0); - - if (mapped == MAP_FAILED) { - throw std::exception(); - } - - const auto mappedGuard = gsl::finally([&] { - munmap(mapped, image.size()); - }); - - memcpy(mapped, image.data(), image.size()); - - const auto fdList = Gio::UnixFDList::create(); - fdList->append(fd); - - invocation->return_value( - Glib::VariantContainerBase::create_tuple({ - Glib::wrap(g_variant_new_handle(0)), - Glib::Variant::create(image.size()), - }), - fdList); - - return; - } } } catch (...) { } @@ -350,18 +234,11 @@ void GtkIntegration::load(const QString &allowedBackends) { LOAD_GTK_SYMBOL(lib, gtk_widget_get_window); LOAD_GTK_SYMBOL(lib, gtk_widget_realize); LOAD_GTK_SYMBOL(lib, gtk_widget_destroy); - LOAD_GTK_SYMBOL(lib, gtk_clipboard_get); - LOAD_GTK_SYMBOL(lib, gtk_clipboard_wait_for_contents); - LOAD_GTK_SYMBOL(lib, gtk_selection_data_get_data); - LOAD_GTK_SYMBOL(lib, gtk_selection_data_get_length); - LOAD_GTK_SYMBOL(lib, gtk_selection_data_free); LOAD_GTK_SYMBOL(lib, gtk_app_chooser_dialog_new); LOAD_GTK_SYMBOL(lib, gtk_app_chooser_get_app_info); LOAD_GTK_SYMBOL(lib, gtk_app_chooser_get_type); - LOAD_GTK_SYMBOL(lib, gdk_atom_intern); - GdkHelperLoad(lib); Loaded = true; } @@ -508,69 +385,6 @@ bool GtkIntegration::showOpenWithDialog(const QString &filepath) const { return result; } -QImage GtkIntegration::getImageFromClipboard() const { - if (_private->remoting) { - if (!_private->dbusConnection) { - return {}; - } - - try { - Glib::RefPtr outFdList; - - const auto loop = Glib::MainLoop::create(); - Glib::VariantContainerBase reply; - _private->dbusConnection->call( - std::string(kObjectPath), - std::string(kInterface), - "GetImageFromClipboard", - {}, - [&](const Glib::RefPtr &result) { - try { - reply = _private->dbusConnection->call_finish( - result, - outFdList); - } catch (...) { - } - loop->quit(); - }, - ServiceName); - - loop->run(); - - if (!reply) { - return {}; - } - - const auto dataSize = base::Platform::GlibVariantCast( - reply.get_child(1)); - - const auto mapped = mmap( - nullptr, - dataSize, - PROT_READ, - MAP_SHARED, - outFdList->get(0), - 0); - - if (mapped == MAP_FAILED) { - return {}; - } - - std::vector result(dataSize); - memcpy(result.data(), mapped, result.size()); - munmap(mapped, result.size()); - - return QImage::fromData(result.data(), result.size()); - } catch (...) { - } - - return {}; - } - - const auto result = GetImageFromClipboard(); - return QImage::fromData(result.data(), result.size()); -} - QString GtkIntegration::AllowedBackends() { return Platform::IsWayland() ? qsl("wayland,x11") diff --git a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.h b/Telegram/SourceFiles/platform/linux/linux_gtk_integration.h index ebff11d5cc..531e136da4 100644 --- a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.h +++ b/Telegram/SourceFiles/platform/linux/linux_gtk_integration.h @@ -25,8 +25,6 @@ public: [[nodiscard]] bool showOpenWithDialog(const QString &filepath) const; - [[nodiscard]] QImage getImageFromClipboard() const; - static QString AllowedBackends(); static int Exec( diff --git a/Telegram/SourceFiles/platform/linux/linux_gtk_integration_dummy.cpp b/Telegram/SourceFiles/platform/linux/linux_gtk_integration_dummy.cpp index 927a7119d2..42c07ae81c 100644 --- a/Telegram/SourceFiles/platform/linux/linux_gtk_integration_dummy.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_gtk_integration_dummy.cpp @@ -33,10 +33,6 @@ bool GtkIntegration::showOpenWithDialog(const QString &filepath) const { return false; } -QImage GtkIntegration::getImageFromClipboard() const { - return {}; -} - QString GtkIntegration::AllowedBackends() { return {}; } diff --git a/Telegram/SourceFiles/platform/linux/linux_gtk_integration_p.h b/Telegram/SourceFiles/platform/linux/linux_gtk_integration_p.h index 09b12a5a8d..75934bf4f0 100644 --- a/Telegram/SourceFiles/platform/linux/linux_gtk_integration_p.h +++ b/Telegram/SourceFiles/platform/linux/linux_gtk_integration_p.h @@ -19,15 +19,9 @@ inline void (*gtk_widget_show)(GtkWidget *widget) = nullptr; inline GdkWindow* (*gtk_widget_get_window)(GtkWidget *widget) = nullptr; inline void (*gtk_widget_realize)(GtkWidget *widget) = nullptr; inline void (*gtk_widget_destroy)(GtkWidget *widget) = nullptr; -inline GtkClipboard* (*gtk_clipboard_get)(GdkAtom selection) = nullptr; -inline GtkSelectionData* (*gtk_clipboard_wait_for_contents)(GtkClipboard *clipboard, GdkAtom target) = nullptr; -inline const guchar* (*gtk_selection_data_get_data)(const GtkSelectionData *selection_data) = nullptr; -inline gint (*gtk_selection_data_get_length)(const GtkSelectionData *selection_data) = nullptr; -inline void (*gtk_selection_data_free)(GtkSelectionData *data) = nullptr; inline GType (*gtk_app_chooser_get_type)(void) G_GNUC_CONST = nullptr; inline GtkWidget* (*gtk_app_chooser_dialog_new)(GtkWindow *parent, GtkDialogFlags flags, GFile *file) = nullptr; inline GAppInfo* (*gtk_app_chooser_get_app_info)(GtkAppChooser *self) = nullptr; -inline GdkAtom (*gdk_atom_intern)(const gchar *atom_name, gboolean only_if_exists) = nullptr; } // namespace Gtk } // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index eda7c0017b..8db679b3a1 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -513,14 +513,6 @@ QString GetIconName() { return Result; } -QImage GetImageFromClipboard() { - if (const auto integration = GtkIntegration::Instance()) { - return integration->getImageFromClipboard(); - } - - return {}; -} - std::optional IsDarkMode() { return Core::App().settings().systemDarkMode(); } diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.h b/Telegram/SourceFiles/platform/mac/specific_mac.h index adc5d3cdd9..66c940fe91 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.h +++ b/Telegram/SourceFiles/platform/mac/specific_mac.h @@ -18,10 +18,6 @@ namespace Platform { [[nodiscard]] bool IsDarkMenuBar(); -inline QImage GetImageFromClipboard() { - return {}; -} - inline bool AutostartSupported() { return false; } diff --git a/Telegram/SourceFiles/platform/platform_specific.h b/Telegram/SourceFiles/platform/platform_specific.h index 0dec322f76..a220a68674 100644 --- a/Telegram/SourceFiles/platform/platform_specific.h +++ b/Telegram/SourceFiles/platform/platform_specific.h @@ -37,7 +37,6 @@ void IgnoreApplicationActivationRightNow(); bool AutostartSupported(); bool TrayIconSupported(); bool SkipTaskbarSupported(); -[[nodiscard]] QImage GetImageFromClipboard(); void WriteCrashDumpDetails(); [[nodiscard]] std::optional IsDarkMode(); diff --git a/Telegram/SourceFiles/platform/win/specific_win.h b/Telegram/SourceFiles/platform/win/specific_win.h index 84a8c8250b..a659e37b35 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.h +++ b/Telegram/SourceFiles/platform/win/specific_win.h @@ -19,10 +19,6 @@ namespace Platform { inline void IgnoreApplicationActivationRightNow() { } -inline QImage GetImageFromClipboard() { - return {}; -} - inline bool TrayIconSupported() { return true; }