surface: allow placing subsurfaces below parent

Prior to this commit, subsurfaces could only be placed above their
parent. Any place_{above,below} request involving the parent would
fail with a protocol error.

However the Wayland protocol allows using the parent surface in the
place_{above,below} requests, and allows subsurfaces to be placed
below their parent.

Weston's implementation adds a dummy wl_list node in the subsurface
list. However this is potentially dangerous: iterating the list
requires making sure the dummy wl_list node is checked for, otherwise
memory corruption will happen.

Instead, split the list in two: one for subsurfaces above the parent,
the other for subsurfaces below.

Tested with wleird's subsurfaces demo client.

Closes: https://github.com/swaywm/wlroots/issues/1865
This commit is contained in:
Simon Ser 2021-06-01 12:18:53 +02:00
parent 11040d4942
commit 9e58301df7
2 changed files with 102 additions and 38 deletions

View file

@ -139,10 +139,13 @@ struct wlr_surface {
struct wl_signal destroy;
} events;
struct wl_list subsurfaces; // wlr_subsurface::parent_link
// wlr_subsurface.parent_link
struct wl_list subsurfaces_below;
struct wl_list subsurfaces_above;
// wlr_subsurface::parent_pending_link
struct wl_list subsurface_pending_list;
// wlr_subsurface.parent_pending_link
struct wl_list subsurfaces_pending_below;
struct wl_list subsurfaces_pending_above;
struct wl_list current_outputs; // wlr_surface_output::link