From 0759138c9cf395bbc3ef227560e2cb8a64b55dd1 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 11 Sep 2025 00:57:44 +0200 Subject: [PATCH] Window: Ensure we integrate windows that were already were shown in a different shell --- src/interfaces/window.cpp | 43 +++++++++++++++++++++++---------------- src/interfaces/window.h | 2 ++ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/interfaces/window.cpp b/src/interfaces/window.cpp index e2635f1..e903d00 100644 --- a/src/interfaces/window.cpp +++ b/src/interfaces/window.cpp @@ -187,6 +187,9 @@ Window::Window(QWindow *window) { s_map.insert(d->parentWindow, this); window->installEventFilter(this); + if (window->handle()) { + qCWarning(LAYERSHELLQT) << d->parentWindow << "already has a shell integration. Call QWindow::close() first and show it again."; + } } bool Window::eventFilter(QObject *watched, QEvent *event) @@ -196,28 +199,32 @@ bool Window::eventFilter(QObject *watched, QEvent *event) return false; } if (event->type() == QEvent::PlatformSurface) { - auto waylandWindow = dynamic_cast(window->handle()); - if (!waylandWindow) { - qCWarning(LAYERSHELLQT) << window << "is not a wayland window. Not creating zwlr_layer_surface"; - return false; - } - - static QWaylandLayerShellIntegration *shellIntegration = nullptr; - if (!shellIntegration) { - shellIntegration = new QWaylandLayerShellIntegration(); - if (!shellIntegration->initialize(waylandWindow->display())) { - delete shellIntegration; - shellIntegration = nullptr; - qCWarning(LAYERSHELLQT) - << "Failed to initialize layer-shell integration, possibly because compositor does not support the layer-shell protocol"; - return false; - } - } - waylandWindow->setShellIntegration(shellIntegration); + initializeShell(); } return false; } +void Window::initializeShell() +{ + auto waylandWindow = dynamic_cast(d->parentWindow->handle()); + if (!waylandWindow) { + qCWarning(LAYERSHELLQT) << d->parentWindow << "is not a wayland window. Not creating zwlr_layer_surface"; + return; + } + + static QWaylandLayerShellIntegration *shellIntegration = nullptr; + if (!shellIntegration) { + shellIntegration = new QWaylandLayerShellIntegration(); + if (!shellIntegration->initialize(waylandWindow->display())) { + delete shellIntegration; + shellIntegration = nullptr; + qCWarning(LAYERSHELLQT) << "Failed to initialize layer-shell integration, possibly because compositor does not support the layer-shell protocol"; + return; + } + } + waylandWindow->setShellIntegration(shellIntegration); +} + Window *Window::get(QWindow *window) { if (!window) { diff --git a/src/interfaces/window.h b/src/interfaces/window.h index 9c084c7..b9e4824 100644 --- a/src/interfaces/window.h +++ b/src/interfaces/window.h @@ -150,6 +150,8 @@ Q_SIGNALS: void layerChanged(); private: + void initializeShell(); + Window(QWindow *window); QScopedPointer d; };