From fa1a070cf690a5ffe9867bc0cc8d3d502f7cf0b6 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 27 Mar 2023 14:33:31 +0300 Subject: Client: Provide hooks for parent windows to attach popups to them The xdg-shell protocol allows to attach xdg_popups to parent surfaces that are not xdg_surfaces. For example, in order to attach an xdg_popup to a layer_surface, you would need to initialize the popup as follows xdg_popup popup = xdg_surface.get_popup(nil, positioner) zwlr_layer_surface_v1.get_popup(popup) QWaylandShellSurface::attachPopup() provides a way to perform parent-specific initialization, i.e. call zwlr_layer_surface_v1.get_popup. QWaylandShellSurface::detachPopup() was added mostly for futureproofing. The xdg-shell doesn't say exactly how the parent surface must be attached. In the example provided above, a request is used to associate the popup with its parent layer surface. But one could also create an object to represent the relationship between the two. The detachPopup() hook can be used to call the destructor request for that object. Change-Id: I43b10e77bd70751d8b4c3a0b5e1d294690bc471a Reviewed-by: David Edmundson --- src/client/qwaylandshellsurface_p.h | 3 +++ src/client/qwaylandwindow.cpp | 4 ++++ 2 files changed, 7 insertions(+) (limited to 'src') diff --git a/src/client/qwaylandshellsurface_p.h b/src/client/qwaylandshellsurface_p.h index 51116c52..6499a2bb 100644 --- a/src/client/qwaylandshellsurface_p.h +++ b/src/client/qwaylandshellsurface_p.h @@ -84,6 +84,9 @@ public: virtual std::any surfaceRole() const { return std::any(); }; + virtual void attachPopup(QWaylandShellSurface *popup) { Q_UNUSED(popup); } + virtual void detachPopup(QWaylandShellSurface *popup) { Q_UNUSED(popup); } + protected: void resizeFromApplyConfigure(const QSize &sizeWithMargins, const QPoint &offset = {0, 0}); void repositionFromApplyConfigure(const QPoint &position); diff --git a/src/client/qwaylandwindow.cpp b/src/client/qwaylandwindow.cpp index 74db519f..c48c9ddd 100644 --- a/src/client/qwaylandwindow.cpp +++ b/src/client/qwaylandwindow.cpp @@ -1635,11 +1635,15 @@ void QWaylandWindow::setXdgActivationToken(const QString &token) void QWaylandWindow::addChildPopup(QWaylandWindow *child) { + if (mShellSurface) + mShellSurface->attachPopup(child->shellSurface()); mChildPopups.append(child); } void QWaylandWindow::removeChildPopup(QWaylandWindow *child) { + if (mShellSurface) + mShellSurface->detachPopup(child->shellSurface()); mChildPopups.removeAll(child); } -- cgit v1.2.1