mirror of
https://invent.kde.org/plasma/layer-shell-qt.git
synced 2025-05-25 09:30:22 -04:00
Add request attaching a layer surface as toplevel parent
This commit is contained in:
parent
16a1debdca
commit
dcd0ae04c3
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
QtWaylandClient::QWaylandShellSurface *createShellSurface(QtWaylandClient::QWaylandWindow *window) override;
|
||||
|
||||
private:
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
QScopedPointer<QWaylandXdgActivationV1> m_xdgActivation;
|
||||
};
|
||||
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user