Skip to content

A hardened Linux desktop, rebuilt from scratch, with your Windows apps built in. Free and open source.

2.9 KB
Raw Blame
Description: Open and Save dialogs attach to their app's window on Wayland
 Qt and KDE apps ask the desktop portal for their Open and Save dialog
 through this platform theme's copy of Qt's portal file dialog, which names
 the parent window "x11:" and its id even on Wayland, where that names no
 window. The dialog then came up on its own with a taskbar button of its
 own, and could fall behind its app. It now asks Qt's platform services
 for the name, as Qt's own portal code does: "wayland:" and an xdg-foreign
 handle on Wayland, "x11:" and the id on X11.
Author: Wild OS Developers <[email protected]>
Forwarded: not-needed

--- a/qt6/src/platformtheme/qxdgdesktopportalfiledialog.cpp
+++ b/qt6/src/platformtheme/qxdgdesktopportalfiledialog.cpp
@@ -25,8 +25,13 @@
 #include <QMimeDatabase>
 #include <QMimeType>
 #include <QRandomGenerator>
+#include <QPointer>
 #include <QWindow>
 
+#include <private/qgenericunixservices_p.h>
+#include <private/qguiapplication_p.h>
+#include <qpa/qplatformintegration.h>
+
 QT_BEGIN_NAMESPACE
 
 QDBusArgument &operator<<(QDBusArgument &arg, const QXdgDesktopPortalFileDialog::FilterCondition &filterCondition)
@@ -80,6 +85,7 @@
     }
 
     WId winId = 0;
+    QPointer<QWindow> parent;
     bool modal = false;
     bool multipleFiles = false;
     bool selectDirectory = false;
@@ -149,7 +155,19 @@
                                                           QStringLiteral("/org/freedesktop/portal/desktop"),
                                                           QStringLiteral("org.freedesktop.portal.FileChooser"),
                                                           d->saveFile ? QStringLiteral("SaveFile") : QStringLiteral("OpenFile"));
-    QString parentWindowId = QStringLiteral("x11:") + QString::number(d->winId, 16);
+    // Wild OS: on Wayland an X11 id names no window, so the dialog came up
+    // as a window of its own, with its own taskbar button, instead of
+    // attached to the app's. Qt's platform services name the parent the way
+    // the session needs: "wayland:" and an xdg-foreign handle, or "x11:".
+    QString parentWindowId;
+    if (d->parent) {
+        if (auto services = dynamic_cast<QGenericUnixServices *>(QGuiApplicationPrivate::platformIntegration()->services())) {
+            parentWindowId = services->portalWindowIdentifier(d->parent);
+        }
+    }
+    if (parentWindowId.isEmpty()) {
+        parentWindowId = QStringLiteral("x11:") + QString::number(d->winId, 16);
+    }
 
     QVariantMap options;
     if (!d->acceptLabel.isEmpty())
@@ -357,6 +375,7 @@
 
     d->modal = windowModality != Qt::NonModal;
     d->winId = parent ? parent->winId() : 0;
+    d->parent = parent;
 
     if (d->nativeFileDialog && (options()->fileMode() == QFileDialogOptions::Directory || options()->fileMode() == QFileDialogOptions::DirectoryOnly))
         return d->nativeFileDialog->show(windowFlags, windowModality, parent);