mirror of
https://invent.kde.org/plasma/layer-shell-qt.git
synced 2025-10-16 08:34:57 -04:00
window: Improve how we tell the window to do layer-shell
Instead of telling it in the construction after forcing the window creation, install an event handler that sets it when we get the PlatformSurface event. It has the advantage that it will also trigger in subsequent platform surface events (e.g. after hide and show).
This commit is contained in:
@ -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<QtWaylandClient::QWaylandWindow *>(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<QWindow *>(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<QtWaylandClient::QWaylandWindow *>(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)
|
||||
|
@ -138,6 +138,8 @@ public:
|
||||
|
||||
static Window *qmlAttachedProperties(QObject *object);
|
||||
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void anchorsChanged();
|
||||
void exclusionZoneChanged();
|
||||
|
41
tests/become-layershell.qml
Normal file
41
tests/become-layershell.qml
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Aleix Pol i Gonzalez <aleixpol@kde.org>
|
||||
*
|
||||
* 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.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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user