From c142fd8f686aa86e333cb3f30a4d3802155ecae5 Mon Sep 17 00:00:00 2001 From: David Redondo Date: Wed, 23 Feb 2022 11:12:17 +0100 Subject: Send parent_window handle to desktop portal Sending parent_window to the portal allows it/the window manager to better place portal dialogs in respect to the application window, for example on top of it instead of a random position. For this use the focusWindow() (if available) since the API in QDesktopServices does not take a QWindow parameter. The file dialog has an explicit parent that can be used. The introduced virtual is provided as a hook for the wayland platform that already includes a class that inherits from QGenericUnixServices. Change-Id: I5571f08d07e5a4e3ae32efd1f09e2727cec9e7c5 Reviewed-by: David Edmundson --- .../xdgdesktopportal/qxdgdesktopportalfiledialog.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/plugins/platformthemes/xdgdesktopportal') diff --git a/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog.cpp b/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog.cpp index ecc5545e76..2ef591a591 100644 --- a/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog.cpp +++ b/src/plugins/platformthemes/xdgdesktopportal/qxdgdesktopportalfiledialog.cpp @@ -3,6 +3,10 @@ #include "qxdgdesktopportalfiledialog_p.h" +#include +#include +#include + #include #include #include @@ -157,8 +161,6 @@ void QXdgDesktopPortalFileDialog::openPortal(Qt::WindowFlags windowFlags, Qt::Wi "/org/freedesktop/portal/desktop"_L1, "org.freedesktop.portal.FileChooser"_L1, d->saveFile ? "SaveFile"_L1 : "OpenFile"_L1); - QString parentWindowId = "x11:"_L1 + QString::number(parent ? parent->winId() : 0, 16); - QVariantMap options; if (!d->acceptLabel.isEmpty()) options.insert("accept_label"_L1, d->acceptLabel); @@ -262,7 +264,14 @@ void QXdgDesktopPortalFileDialog::openPortal(Qt::WindowFlags windowFlags, Qt::Wi // TODO choices a(ssa(ss)s) // List of serialized combo boxes to add to the file chooser. - message << parentWindowId << d->title << options; + auto unixServices = dynamic_cast( + QGuiApplicationPrivate::platformIntegration()->services()); + if (parent && unixServices) + message << unixServices->portalWindowIdentifier(parent); + else + message << QString(); + + message << d->title << options; QDBusPendingCall pendingCall = QDBusConnection::sessionBus().asyncCall(message); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingCall); -- cgit v1.2.3