diff --git a/src/plugins/platforms/wayland/qwaylandwindow.cpp b/src/plugins/platforms/wayland/qwaylandwindow.cpp index 965511528c1..13408b25924 100644 --- a/src/plugins/platforms/wayland/qwaylandwindow.cpp +++ b/src/plugins/platforms/wayland/qwaylandwindow.cpp @@ -226,14 +226,21 @@ void QWaylandWindow::setGeometry(const QRect &rect) void QWaylandWindow::setVisible(bool visible) { if (visible) { - if (window()->type() == Qt::Popup && transientParent()) { + if (window()->type() == Qt::Popup) { QWaylandWindow *parent = transientParent(); - mMouseDevice = parent->mMouseDevice; - mMouseSerial = parent->mMouseSerial; + if (!parent) { + // Try with the current focus window. It may be the wrong one but we need to have + // some parent to have popups act as popups. + parent = mDisplay->currentInputDevice()->pointerFocus(); + } + if (parent) { + mMouseDevice = parent->mMouseDevice; + mMouseSerial = parent->mMouseSerial; - QWaylandWlShellSurface *wlshellSurface = dynamic_cast(mShellSurface); - if (mMouseDevice && wlshellSurface) { - wlshellSurface->setPopup(transientParent(), mMouseDevice, mMouseSerial); + QWaylandWlShellSurface *wlshellSurface = dynamic_cast(mShellSurface); + if (mMouseDevice && wlshellSurface) { + wlshellSurface->setPopup(parent, mMouseDevice, mMouseSerial); + } } }