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 4fcdf19753
3 changed files with 38 additions and 0 deletions

View File

@ -12,12 +12,15 @@
#include <QtWaylandClient/private/qwaylanddisplay_p.h> #include <QtWaylandClient/private/qwaylanddisplay_p.h>
#include <QtWaylandClient/private/qwaylandwindow_p.h> #include <QtWaylandClient/private/qwaylandwindow_p.h>
#include <QPlatformSurfaceEvent>
namespace LayerShellQt namespace LayerShellQt
{ {
QWaylandLayerShellIntegration::QWaylandLayerShellIntegration() QWaylandLayerShellIntegration::QWaylandLayerShellIntegration()
: QWaylandShellIntegrationTemplate<QWaylandLayerShellIntegration>(5) : QWaylandShellIntegrationTemplate<QWaylandLayerShellIntegration>(5)
, m_xdgActivation(new QWaylandXdgActivationV1) , m_xdgActivation(new QWaylandXdgActivationV1)
{ {
qGuiApp->installEventFilter(this);
} }
QWaylandLayerShellIntegration::~QWaylandLayerShellIntegration() QWaylandLayerShellIntegration::~QWaylandLayerShellIntegration()
@ -32,4 +35,29 @@ QtWaylandClient::QWaylandShellSurface *QWaylandLayerShellIntegration::createShel
return new QWaylandLayerSurface(this, window); 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; QtWaylandClient::QWaylandShellSurface *createShellSurface(QtWaylandClient::QWaylandWindow *window) override;
private: private:
bool eventFilter(QObject *watched, QEvent *event) override;
QScopedPointer<QWaylandXdgActivationV1> m_xdgActivation; QScopedPointer<QWaylandXdgActivationV1> m_xdgActivation;
}; };

View File

@ -402,6 +402,15 @@
invalid_exclusive_edge protocol error will be raised. invalid_exclusive_edge protocol error will be raised.
</description> </description>
<arg name="edge" type="uint"/> <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> </request>
</interface> </interface>
</protocol> </protocol>