diff --git a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp index 5fd718e697b..8cdd0a681bd 100644 --- a/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp +++ b/src/plugins/platforms/wayland/plugins/shellintegration/xdg-shell/qwaylandxdgshell.cpp @@ -36,13 +36,14 @@ QWaylandXdgSurface::Toplevel::Toplevel(QWaylandXdgSurface *xdgSurface) requestWindowFlags(window->flags()); if (auto transientParent = xdgSurface->window()->transientParent()) { auto parentSurface = qobject_cast(transientParent->shellSurface()); - if (parentSurface && parentSurface->m_toplevel) { + if (parentSurface && parentSurface->m_toplevel) set_parent(parentSurface->m_toplevel->object()); - if (window->modality() != Qt::NonModal && m_xdgSurface->m_shell->m_xdgDialogWm) { - m_xdgDialog.reset(m_xdgSurface->m_shell->m_xdgDialogWm->getDialog(object())); - m_xdgDialog->set_modal(); - } - } + } + + // Always use XDG Dialog, a window could be assigned a parent through XDG Foreign. + if (window->modality() != Qt::NonModal && m_xdgSurface->m_shell->m_xdgDialogWm) { + m_xdgDialog.reset(m_xdgSurface->m_shell->m_xdgDialogWm->getDialog(object())); + m_xdgDialog->set_modal(); } } diff --git a/tests/auto/wayland/xdgshell/tst_xdgshell.cpp b/tests/auto/wayland/xdgshell/tst_xdgshell.cpp index 311c408a9e5..45b78ed003f 100644 --- a/tests/auto/wayland/xdgshell/tst_xdgshell.cpp +++ b/tests/auto/wayland/xdgshell/tst_xdgshell.cpp @@ -35,6 +35,7 @@ private slots: void suspended(); void initiallySuspended(); void modality(); + void modalityWithoutTransientParent(); }; void tst_xdgshell::init() @@ -823,5 +824,35 @@ void tst_xdgshell::modality() QCOMPOSITOR_TRY_VERIFY(!xdgDialog()); } +void tst_xdgshell::modalityWithoutTransientParent() +{ + QRasterWindow child; + child.resize(400, 320); + child.show(); + QCOMPOSITOR_TRY_VERIFY(xdgToplevel()); + QCOMPOSITOR_VERIFY(!xdgDialog()); + + child.hide(); + child.setModality(Qt::WindowModal); + child.show(); + QCOMPOSITOR_TRY_VERIFY(xdgDialog()); + QCOMPOSITOR_VERIFY(xdgDialog()->modal); + + child.hide(); + QCOMPOSITOR_TRY_VERIFY(!xdgDialog()); + + child.setModality(Qt::ApplicationModal); + child.show(); + QCOMPOSITOR_TRY_VERIFY(xdgDialog()); + QCOMPOSITOR_VERIFY(xdgDialog()->modal); + + child.hide(); + QCOMPOSITOR_TRY_VERIFY(!xdgDialog()); + + child.show(); + child.setModality(Qt::NonModal); + QCOMPOSITOR_TRY_VERIFY(!xdgDialog()); +} + QCOMPOSITOR_TEST_MAIN(tst_xdgshell) #include "tst_xdgshell.moc"