From 62e82a42fbbf866296e5c9e45cf515db43a3eee9 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Thu, 14 Apr 2022 04:24:48 +0400 Subject: [PATCH] Adapt to lib_base's XDP API changes --- .../platform/linux/linux_xdp_file_dialog.cpp | 33 +++++----------- .../linux/linux_xdp_open_with_dialog.cpp | 39 ++++++------------- .../platform/linux/specific_linux.cpp | 27 +++---------- Telegram/lib_base | 2 +- 4 files changed, 28 insertions(+), 73 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/linux_xdp_file_dialog.cpp b/Telegram/SourceFiles/platform/linux/linux_xdp_file_dialog.cpp index 392a77503..8ced6b7cf 100644 --- a/Telegram/SourceFiles/platform/linux/linux_xdp_file_dialog.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_xdp_file_dialog.cpp @@ -10,7 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "platform/platform_file_utilities.h" #include "base/platform/base_platform_info.h" #include "base/platform/linux/base_linux_glibmm_helper.h" -#include "base/platform/linux/base_linux_wayland_integration.h" +#include "base/platform/linux/base_linux_xdp_utilities.h" #include "storage/localstorage.h" #include "base/random.h" @@ -20,8 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include -using base::Platform::WaylandIntegration; - namespace Platform { namespace FileDialog { namespace XDP { @@ -29,9 +27,7 @@ namespace { using Type = ::FileDialog::internal::Type; -constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs; -constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs; -constexpr auto kXDGDesktopPortalFileChooserInterface = "org.freedesktop.portal.FileChooser"_cs; +constexpr auto kXDPFileChooserInterface = "org.freedesktop.portal.FileChooser"_cs; constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs; const char *filterRegExp = @@ -90,12 +86,12 @@ void ComputeFileChooserPortalVersion() { } connection->call( - std::string(kXDGDesktopPortalObjectPath), + std::string(base::Platform::XDP::kObjectPath), std::string(kPropertiesInterface), "Get", base::Platform::MakeGlibVariant(std::tuple{ Glib::ustring( - std::string(kXDGDesktopPortalFileChooserInterface)), + std::string(kXDPFileChooserInterface)), Glib::ustring("version"), }), [=](const Glib::RefPtr &result) { @@ -123,7 +119,7 @@ void ComputeFileChooserPortalVersion() { QString::fromStdString(e.what()))); } }, - std::string(kXDGDesktopPortalService)); + std::string(base::Platform::XDP::kService)); } // This is a patched copy of file dialog from qxdgdesktopportal theme plugin. @@ -262,17 +258,6 @@ XDPFileDialog::~XDPFileDialog() { } void XDPFileDialog::openPortal() { - std::stringstream parentWindowId; - - if (const auto integration = WaylandIntegration::Instance()) { - if (const auto handle = integration->nativeHandle(_parent) - ; !handle.isEmpty()) { - parentWindowId << "wayland:" << handle.toStdString(); - } - } else if (IsX11() && _parent) { - parentWindowId << "x11:" << std::hex << _parent->winId(); - } - std::map options; if (!_acceptLabel.empty()) { options["accept_label"] = Glib::Variant::create( @@ -448,13 +433,13 @@ void XDPFileDialog::openPortal() { requestPath); _dbusConnection->call( - std::string(kXDGDesktopPortalObjectPath), - std::string(kXDGDesktopPortalFileChooserInterface), + std::string(base::Platform::XDP::kObjectPath), + std::string(kXDPFileChooserInterface), _acceptMode == QFileDialog::AcceptSave ? "SaveFile" : "OpenFile", base::Platform::MakeGlibVariant(std::tuple{ - Glib::ustring(parentWindowId.str()), + base::Platform::XDP::ParentWindowID(_parent), _windowTitle, options, }), @@ -503,7 +488,7 @@ void XDPFileDialog::openPortal() { }); } }), - std::string(kXDGDesktopPortalService)); + std::string(base::Platform::XDP::kService)); } catch (...) { _failedToOpen = true; _reject.fire({}); diff --git a/Telegram/SourceFiles/platform/linux/linux_xdp_open_with_dialog.cpp b/Telegram/SourceFiles/platform/linux/linux_xdp_open_with_dialog.cpp index 52640768d..7b3bfbeaa 100644 --- a/Telegram/SourceFiles/platform/linux/linux_xdp_open_with_dialog.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_xdp_open_with_dialog.cpp @@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/platform/base_platform_info.h" #include "base/platform/linux/base_linux_glibmm_helper.h" -#include "base/platform/linux/base_linux_wayland_integration.h" +#include "base/platform/linux/base_linux_xdp_utilities.h" #include "core/application.h" #include "window/window_controller.h" #include "base/random.h" @@ -21,16 +21,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include -using base::Platform::WaylandIntegration; - namespace Platform { namespace File { namespace internal { namespace { -constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs; -constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs; -constexpr auto kXDGDesktopPortalOpenURIInterface = "org.freedesktop.portal.OpenURI"_cs; +constexpr auto kXDPOpenURIInterface = "org.freedesktop.portal.OpenURI"_cs; constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs; } // namespace @@ -41,15 +37,15 @@ bool ShowXDPOpenWithDialog(const QString &filepath) { Gio::DBus::BusType::BUS_TYPE_SESSION); auto reply = connection->call_sync( - std::string(kXDGDesktopPortalObjectPath), + std::string(base::Platform::XDP::kObjectPath), std::string(kPropertiesInterface), "Get", base::Platform::MakeGlibVariant(std::tuple{ Glib::ustring( - std::string(kXDGDesktopPortalOpenURIInterface)), + std::string(kXDPOpenURIInterface)), Glib::ustring("version"), }), - std::string(kXDGDesktopPortalService)); + std::string(base::Platform::XDP::kService)); const auto version = base::Platform::GlibVariantCast( base::Platform::GlibVariantCast( @@ -72,24 +68,13 @@ bool ShowXDPOpenWithDialog(const QString &filepath) { const auto fdGuard = gsl::finally([&] { ::close(fd); }); const auto parentWindowId = [&]() -> Glib::ustring { - std::stringstream result; - const auto activeWindow = Core::App().activeWindow(); if (!activeWindow) { - return result.str(); + return {}; } - const auto window = activeWindow->widget()->windowHandle(); - if (const auto integration = WaylandIntegration::Instance()) { - if (const auto handle = integration->nativeHandle(window) - ; !handle.isEmpty()) { - result << "wayland:" << handle.toStdString(); - } - } else if (IsX11()) { - result << "x11:" << std::hex << window->winId(); - } - - return result.str(); + return base::Platform::XDP::ParentWindowID( + activeWindow->widget()->windowHandle()); }(); const auto handleToken = Glib::ustring("tdesktop") @@ -122,7 +107,7 @@ bool ShowXDPOpenWithDialog(const QString &filepath) { const Glib::VariantContainerBase ¶meters) { loop->quit(); }, - std::string(kXDGDesktopPortalService), + std::string(base::Platform::XDP::kService), "org.freedesktop.portal.Request", "Response", requestPath); @@ -138,8 +123,8 @@ bool ShowXDPOpenWithDialog(const QString &filepath) { auto outFdList = Glib::RefPtr(); connection->call_sync( - std::string(kXDGDesktopPortalObjectPath), - std::string(kXDGDesktopPortalOpenURIInterface), + std::string(base::Platform::XDP::kObjectPath), + std::string(kXDPOpenURIInterface), "OpenFile", Glib::VariantContainerBase::create_tuple({ Glib::Variant::create(parentWindowId), @@ -160,7 +145,7 @@ bool ShowXDPOpenWithDialog(const QString &filepath) { }), fdList, outFdList, - std::string(kXDGDesktopPortalService)); + std::string(base::Platform::XDP::kService)); if (signalId != 0) { QWindow window; diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index a066c32c4..277e11aa1 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/random.h" #include "base/platform/base_platform_info.h" -#include "base/platform/linux/base_linux_wayland_integration.h" #include "platform/linux/linux_desktop_environment.h" #include "platform/linux/linux_wayland_integration.h" #include "lang/lang_keys.h" @@ -56,7 +55,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include using namespace Platform; -using BaseWaylandIntegration = base::Platform::WaylandIntegration; using Platform::internal::WaylandIntegration; namespace Platform { @@ -65,8 +63,6 @@ namespace { constexpr auto kDesktopFile = ":/misc/telegramdesktop.desktop"_cs; constexpr auto kIconName = "telegram"_cs; -constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs; -constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs; constexpr auto kIBusPortalService = "org.freedesktop.portal.IBus"_cs; constexpr auto kWebviewService = "org.telegram.desktop.GtkIntegration.WebviewHelper-%1-%2"_cs; @@ -81,24 +77,13 @@ void PortalAutostart(bool start, bool silent) { Gio::DBus::BusType::BUS_TYPE_SESSION); const auto parentWindowId = [&]() -> Glib::ustring { - std::stringstream result; - const auto activeWindow = Core::App().activeWindow(); if (!activeWindow) { - return result.str(); + return {}; } - const auto window = activeWindow->widget()->windowHandle(); - if (const auto integration = BaseWaylandIntegration::Instance()) { - if (const auto handle = integration->nativeHandle(window) - ; !handle.isEmpty()) { - result << "wayland:" << handle.toStdString(); - } - } else if (IsX11()) { - result << "x11:" << std::hex << window->winId(); - } - - return result.str(); + return base::Platform::XDP::ParentWindowID( + activeWindow->widget()->windowHandle()); }(); const auto handleToken = Glib::ustring("tdesktop") @@ -163,7 +148,7 @@ void PortalAutostart(bool start, bool silent) { loop->quit(); }, - std::string(kXDGDesktopPortalService), + std::string(base::Platform::XDP::kService), "org.freedesktop.portal.Request", "Response", requestPath); @@ -175,14 +160,14 @@ void PortalAutostart(bool start, bool silent) { }); connection->call_sync( - std::string(kXDGDesktopPortalObjectPath), + std::string(base::Platform::XDP::kObjectPath), "org.freedesktop.portal.Background", "RequestBackground", base::Platform::MakeGlibVariant(std::tuple{ parentWindowId, options, }), - std::string(kXDGDesktopPortalService)); + std::string(base::Platform::XDP::kService)); if (signalId != 0) { QWindow window; diff --git a/Telegram/lib_base b/Telegram/lib_base index a23ec1340..5ab3cdaef 160000 --- a/Telegram/lib_base +++ b/Telegram/lib_base @@ -1 +1 @@ -Subproject commit a23ec1340b65c37f551a9f0870897f0a8f9e5503 +Subproject commit 5ab3cdaef587b8ac8fdf1a96879961fd57ac7ace