Add request attaching a layer surface as toplevel parent

This commit is contained in:
David Redondo 2024-07-10 15:13:42 +02:00
parent 16a1debdca
commit dcd0ae04c3
3 changed files with 35 additions and 0 deletions

View File

@ -12,12 +12,15 @@
#include <QtWaylandClient/private/qwaylanddisplay_p.h>
#include <QtWaylandClient/private/qwaylandwindow_p.h>
#include <QPlatformSurfaceEvent>
namespace LayerShellQt
{
QWaylandLayerShellIntegration::QWaylandLayerShellIntegration()
: QWaylandShellIntegrationTemplate<QWaylandLayerShellIntegration>(5)
, m_xdgActivation(new QWaylandXdgActivationV1)
{
qGuiApp->installEventFilter(this);
}
QWaylandLayerShellIntegration::~QWaylandLayerShellIntegration()
@ -32,4 +35,29 @@ QtWaylandClient::QWaylandShellSurface *QWaylandLayerShellIntegration::createShel
return new QWaylandLayerSurface(this, window);
}
bool QWaylandLayerShellIntegration::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::PlatformSurface && static_cast<QPlatformSurfaceEvent *>(event)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) {
QWindow *window = qobject_cast<QWindow *>(watched);
if (!window) {
return false;
}
auto child = static_cast<QtWaylandClient::QWaylandWindow *>(window->handle());
auto maybeSetParent = [child]() {
auto transientParent = child->window()->transientParent();
if (!transientParent) {
return;
}
if (auto layerParent = qobject_cast<QWaylandLayerSurface *>(static_cast<QtWaylandClient::QWaylandWindow *>(transientParent->handle())->shellSurface())) {
if (auto topevel = child->surfaceRole<xdg_toplevel>()) {
layerParent->set_parent_of(topevel);
}
}
};
maybeSetParent();
connect(window, &QWindow::transientParentChanged, child, maybeSetParent);
connect(child, &QtWaylandClient::QWaylandWindow::surfaceRoleCreated, this, maybeSetParent);
}
return false;
}
}

View File

@ -32,6 +32,7 @@ public:
QtWaylandClient::QWaylandShellSurface *createShellSurface(QtWaylandClient::QWaylandWindow *window) override;
private:
bool eventFilter(QObject *watched, QEvent *event) override;
QScopedPointer<QWaylandXdgActivationV1> m_xdgActivation;
};

View File

@ -403,5 +403,11 @@
</description>
<arg name="edge" type="uint"/>
</request>
<request name="set_parent_of">
<description summary="assign this layer_surface as an xdg_toplevel parent">
</description>
<arg name="toplevel" type="object" interface="xdg_toplevel" />
</request>
</interface>
</protocol>