Skip to content
Snippets Groups Projects
Commit a19654b2 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇
Browse files

Make use of QWaylandWindow::surfaceRoleCreated for setMainWindow

New in Qt 6.8: It's emitted when the XDG Surface is assigned
a role (e.g. XDG Toplevel) which lets us more precisely set up
the XDG Foreign relationship and ensures the window doesn't
briefly flash in Task Manager as not transient.

While at it, make doSetMainWindow static since it doesn't access
`this` and avoids capturing it into the connection whose only
context is (wayland)Window.
parent 71ff1acc
No related branches found
No related tags found
1 merge request!160Make use of QWaylandWindow::surfaceRoleCreated for setMainWindow
Pipeline #811602 passed with stage
in 1 minute and 47 seconds
......@@ -224,16 +224,24 @@ void WindowSystem::setMainWindow(QWindow *window, const QString &handle)
if (window->isExposed()) {
doSetMainWindow(window, handle);
} else {
// We can only import an XDG toplevel. QtWayland currently has no proper signal
// for shell surface creation. wlSurfaceCreated() is too early.
// Instead, we wait for it being exposed and then set its parent.
// We can only import an XDG toplevel.
// QWaylandWindow::surfaceRoleCreated is only in Qt 6.8,
// in earlier versions wait for the window be exposed,
// since QWaylandWindow::wlSurfaceCreated is too early.
#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0)
window->setProperty(c_kdeXdgForeignPendingHandleProperty, handle);
window->installEventFilter(this);
#else
connect(waylandWindow, &QNativeInterface::Private::QWaylandWindow::surfaceRoleCreated, window, [window, handle] {
doSetMainWindow(window, handle);
});
#endif
}
}
bool WindowSystem::eventFilter(QObject *watched, QEvent *event)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0)
if (event->type() == QEvent::Expose) {
auto *window = static_cast<QWindow *>(watched);
if (window->isExposed()) {
......@@ -246,6 +254,7 @@ bool WindowSystem::eventFilter(QObject *watched, QEvent *event)
window->removeEventFilter(this);
}
}
#endif
return QObject::eventFilter(watched, event);
}
......
......@@ -32,7 +32,7 @@ protected:
bool eventFilter(QObject *watched, QEvent *event) override;
private:
void doSetMainWindow(QWindow *window, const QString &handle);
static void doSetMainWindow(QWindow *window, const QString &handle);
QString m_lastToken;
WindowManagement *m_windowManagement;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment