Ensure QWaylandWindow::transientParent has a shell surface

This may not be a perfect solution, but it's better than the current one, where
the transient parent may not have a shell surface (because the window may be
hidden or not yet initialized).

Task-number: QTBUG-63840
Change-Id: Ia5f04376d4b6d12b41ceeab5ba13cdc1b63b4e3c
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
This commit is contained in:
Johan Klokkhammer Helsing 2017-10-19 12:13:01 +02:00 committed by Johan Helsing
parent 1fbffb9dfb
commit 7f8d9b7f54

View File

@ -785,22 +785,27 @@ QWaylandAbstractDecoration *QWaylandWindow::decoration() const
return mWindowDecoration; return mWindowDecoration;
} }
static QWindow *topLevelWindow(QWindow *window) static QWaylandWindow *closestShellSurfaceWindow(QWindow *window)
{ {
while (QWindow *parent = window->parent()) while (window) {
window = parent; auto w = static_cast<QWaylandWindow *>(window->handle());
return window; if (w->shellSurface())
return w;
window = window->transientParent() ? window->transientParent() : window->parent();
}
return nullptr;
} }
QWaylandWindow *QWaylandWindow::transientParent() const QWaylandWindow *QWaylandWindow::transientParent() const
{ {
// Take the top level window here, since the transient parent may be a QWidgetWindow // Take the closest window with a shell surface, since the transient parent may be a
// or some other window without a shell surface, which is then not able to get mouse // QWidgetWindow or some other window without a shell surface, which is then not able to
// events. // get mouse events.
if (auto transientParent = window()->transientParent()) if (auto transientParent = closestShellSurfaceWindow(window()->transientParent()))
return static_cast<QWaylandWindow *>(topLevelWindow(transientParent)->handle()); return transientParent;
else if (QGuiApplication::focusWindow() && (window()->type() == Qt::ToolTip || window()->type() == Qt::Popup))
return static_cast<QWaylandWindow *>(topLevelWindow(QGuiApplication::focusWindow())->handle()); if (QGuiApplication::focusWindow() && (window()->type() == Qt::ToolTip || window()->type() == Qt::Popup))
return closestShellSurfaceWindow(QGuiApplication::focusWindow());
return nullptr; return nullptr;
} }