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 <laszlo.agocs@theqtcompany.com>
This commit is contained in:
Giulio Camuffo 2015-01-18 15:53:46 +02:00
parent b52533db83
commit 817633a831

View File

@ -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();
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<QWaylandWlShellSurface*>(mShellSurface);
if (mMouseDevice && wlshellSurface) {
wlshellSurface->setPopup(transientParent(), mMouseDevice, mMouseSerial);
wlshellSurface->setPopup(parent, mMouseDevice, mMouseSerial);
}
}
}