diff --git a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell-v5/qwaylandxdgsurfacev5.cpp b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell-v5/qwaylandxdgsurfacev5.cpp index 31c7dff7b96..40e2a994daa 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell-v5/qwaylandxdgsurfacev5.cpp +++ b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell-v5/qwaylandxdgsurfacev5.cpp @@ -229,6 +229,7 @@ void QWaylandXdgSurfaceV5::xdg_surface_configure(int32_t width, int32_t height, void QWaylandXdgSurfaceV5::xdg_surface_close() { + m_window->window()->close(); } } diff --git a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6.cpp b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6.cpp index a8bfaac690a..986deceb19a 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6.cpp +++ b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6.cpp @@ -152,6 +152,7 @@ QWaylandXdgSurfaceV6::Popup::Popup(QWaylandXdgSurfaceV6 *xdgSurface, QWaylandXdg QtWayland::zxdg_positioner_v6 *positioner) : zxdg_popup_v6(xdgSurface->get_popup(parent->object(), positioner->object())) , m_xdgSurface(xdgSurface) + , m_parent(parent) { } @@ -159,6 +160,19 @@ QWaylandXdgSurfaceV6::Popup::~Popup() { if (isInitialized()) destroy(); + + if (m_grabbing) { + auto *shell = m_xdgSurface->m_shell; + Q_ASSERT(shell->m_topmostPopup == this); + shell->m_topmostPopup = m_parent->m_popup; + } +} + +void QWaylandXdgSurfaceV6::Popup::grab(QWaylandInputDevice *seat, uint serial) +{ + m_xdgSurface->m_shell->m_topmostPopup = this; + zxdg_popup_v6::grab(seat->wl_seat(), serial); + m_grabbing = true; } void QWaylandXdgSurfaceV6::Popup::zxdg_popup_v6_popup_done() @@ -192,8 +206,10 @@ QWaylandXdgSurfaceV6::~QWaylandXdgSurfaceV6() { if (m_toplevel) zxdg_toplevel_v6_destroy(m_toplevel->object()); - if (m_popup) - zxdg_popup_v6_destroy(m_popup->object()); + if (m_popup) { + delete m_popup; + m_popup = nullptr; + } destroy(); } @@ -277,6 +293,14 @@ void QWaylandXdgSurfaceV6::setPopup(QWaylandWindow *parent, QWaylandInputDevice Q_ASSERT(!m_toplevel && !m_popup); auto parentXdgSurface = static_cast(parent->shellSurface()); + + auto *top = m_shell->m_topmostPopup; + if (grab && top && top->m_xdgSurface != parentXdgSurface) { + qCWarning(lcQpaWayland) << "setPopup called for a surface that was not the topmost popup, positions might be off."; + parentXdgSurface = top->m_xdgSurface; + parent = top->m_xdgSurface->m_window; + } + auto positioner = new QtWayland::zxdg_positioner_v6(m_shell->create_positioner()); // set_popup expects a position relative to the parent QPoint transientPos = m_window->geometry().topLeft(); // this is absolute @@ -292,9 +316,8 @@ void QWaylandXdgSurfaceV6::setPopup(QWaylandWindow *parent, QWaylandInputDevice m_popup = new Popup(this, parentXdgSurface, positioner); positioner->destroy(); delete positioner; - if (grab) { - m_popup->grab(device->wl_seat(), serial); - } + if (grab) + m_popup->grab(device, serial); } void QWaylandXdgSurfaceV6::zxdg_surface_v6_configure(uint32_t serial) diff --git a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6_p.h b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6_p.h index 8168ae5650a..38b711f88d2 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6_p.h +++ b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell-v6/qwaylandxdgshellv6_p.h @@ -122,9 +122,12 @@ private: Popup(QWaylandXdgSurfaceV6 *xdgSurface, QWaylandXdgSurfaceV6 *parent, QtWayland::zxdg_positioner_v6 *positioner); ~Popup() override; + void grab(QWaylandInputDevice *seat, uint serial); void zxdg_popup_v6_popup_done() override; QWaylandXdgSurfaceV6 *m_xdgSurface = nullptr; + QWaylandXdgSurfaceV6 *m_parent = nullptr; + bool m_grabbing = false; }; void setToplevel(); @@ -137,6 +140,8 @@ private: bool m_configured = false; QRegion m_exposeRegion; uint m_pendingConfigureSerial = 0; + + friend class QWaylandXdgShellV6; }; class Q_WAYLAND_CLIENT_EXPORT QWaylandXdgShellV6 : public QtWayland::zxdg_shell_v6 @@ -150,6 +155,9 @@ public: private: void zxdg_shell_v6_ping(uint32_t serial) override; + QWaylandXdgSurfaceV6::Popup *m_topmostPopup = nullptr; + + friend class QWaylandXdgSurfaceV6; }; QT_END_NAMESPACE diff --git a/tests/auto/wayland/client/tst_client.cpp b/tests/auto/wayland/client/tst_client.cpp index 6b7daecd5f1..470db25a4c7 100644 --- a/tests/auto/wayland/client/tst_client.cpp +++ b/tests/auto/wayland/client/tst_client.cpp @@ -506,6 +506,7 @@ void tst_WaylandClient::mouseDrag() void tst_WaylandClient::dontCrashOnMultipleCommits() { + QSKIP("This test is flaky. See QTBUG-68756."); auto window = new TestWindow(); window->show();