From b5457082bb6ae1b321e8bbe69237e8d3f4ed934a Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Wed, 27 Jul 2022 00:02:04 +0400 Subject: QGtk3Theme: Support setting dialog parent on Wayland This adds support for setting parent window for GTK dialogs on Wayland using the new API added for portals Change-Id: I29085c926ce4338ff2ad75728d566ec843d3aa5a Reviewed-by: Liang Qi --- .../platformthemes/gtk3/qgtk3dialoghelpers.cpp | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/plugins/platformthemes') diff --git a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp index ce8e2ff756..24fea73dd2 100644 --- a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp +++ b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp @@ -12,6 +12,8 @@ #include #include +#include +#include #include #undef signals @@ -23,6 +25,10 @@ #include #endif +#ifdef GDK_WINDOWING_WAYLAND +#include +#endif + // The size of the preview we display for selected image files. We set height // larger than width because generally there is more free space vertically // than horizontally (setting the preview image will always expand the width of @@ -98,14 +104,27 @@ bool QGtk3Dialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWind GdkWindow *gdkWindow = gtk_widget_get_window(gtkWidget); if (parent) { + if (false) { +#if defined(GDK_WINDOWING_WAYLAND) && GTK_CHECK_VERSION(3, 22, 0) + } else if (GDK_IS_WAYLAND_WINDOW(gdkWindow)) { + const auto unixServices = dynamic_cast( + QGuiApplicationPrivate::platformIntegration()->services()); + if (unixServices) { + const auto handle = unixServices->portalWindowIdentifier(parent); + if (handle.startsWith("wayland:"_L1)) { + auto handleBa = handle.sliced(8).toUtf8(); + gdk_wayland_window_set_transient_for_exported(gdkWindow, handleBa.data()); + } + } +#endif #if QT_CONFIG(xlib) && defined(GDK_WINDOWING_X11) - if (GDK_IS_X11_WINDOW(gdkWindow)) { + } else if (GDK_IS_X11_WINDOW(gdkWindow)) { GdkDisplay *gdkDisplay = gdk_window_get_display(gdkWindow); XSetTransientForHint(gdk_x11_display_get_xdisplay(gdkDisplay), gdk_x11_window_get_xid(gdkWindow), parent->winId()); - } #endif + } } if (modality != Qt::NonModal) { -- cgit v1.2.3