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 <davidedmundson@kde.org>
This commit is contained in:
Vlad Zahorodnii 2023-03-27 14:33:31 +03:00
parent e1ef4a7f89
commit 25e7d1ed11
2 changed files with 7 additions and 0 deletions

View File

@ -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);

View File

@ -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);
}