diff --git a/src/interfaces/window.cpp b/src/interfaces/window.cpp index 2ef96da..e2635f1 100644 --- a/src/interfaces/window.cpp +++ b/src/interfaces/window.cpp @@ -186,27 +186,36 @@ Window::Window(QWindow *window) , d(new WindowPrivate(window)) { s_map.insert(d->parentWindow, this); + window->installEventFilter(this); +} - window->create(); - - auto waylandWindow = dynamic_cast(window->handle()); - if (!waylandWindow) { - qCWarning(LAYERSHELLQT) << window << "is not a wayland window. Not creating zwlr_layer_surface"; - return; +bool Window::eventFilter(QObject *watched, QEvent *event) +{ + auto window = qobject_cast(watched); + if (!window) { + 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; + 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; } - } - waylandWindow->setShellIntegration(shellIntegration); + 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); + } + return false; } Window *Window::get(QWindow *window) diff --git a/src/interfaces/window.h b/src/interfaces/window.h index 083e467..9c084c7 100644 --- a/src/interfaces/window.h +++ b/src/interfaces/window.h @@ -138,6 +138,8 @@ public: static Window *qmlAttachedProperties(QObject *object); + bool eventFilter(QObject *watched, QEvent *event) override; + Q_SIGNALS: void anchorsChanged(); void exclusionZoneChanged(); diff --git a/tests/become-layershell.qml b/tests/become-layershell.qml new file mode 100644 index 0000000..821db77 --- /dev/null +++ b/tests/become-layershell.qml @@ -0,0 +1,42 @@ +/* + * SPDX-FileCopyrightText: 2025 Aleix Pol i Gonzalez + * + * SPDX-License-Identifier: LGPL-3.0-or-later + */ + +import QtQuick +import QtQuick.Controls +import org.kde.layershell 1.0 as LayerShell + +Item +{ + Button { + text: "Convert" + anchors.centerIn: parent + + onClicked: { + win.close() + win.LayerShell.Window.anchors = LayerShell.Window.AnchorLeft; + win.LayerShell.Window.layer = LayerShell.Window.LayerTop; + win.LayerShell.Window.exclusionZone = -1; + win.show() + } + } + + Window { + id: win + + width: 100 + height: 100 + Rectangle { + anchors.fill: parent + color: "red" + + Text { + anchors.centerIn: parent + text: "top" + } + } + visible: true + } +}