From 817633a83136e0442557a0bf3b2955e602289385 Mon Sep 17 00:00:00 2001 From: Giulio Camuffo Date: Sun, 18 Jan 2015 15:53:46 +0200 Subject: [PATCH] Fix popup menus with no parent windows The QMenu API doesn't play well with Wayland. You can do: QMenu menu; menu.popup(someGlobalPos); which is completely broken on wayland. If some popup window doesn't have a transient parent use the current focus window for that. Fixes right-click popups in qdbusviewer and other apps. Change-Id: I3227f4ec27431ca8ec156971cbfdbf1e848a0527 Reviewed-by: Laszlo Agocs --- .../platforms/wayland/qwaylandwindow.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) 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); + } } }