wlr_scene: Allow a node to be detached from a scene tree
Currently, when a scene node is created it must have a parent specified and must stay in the scene tree it was originally added to for its entire lifetime. That's fine for most situations, but it assumes that from the moment an xdg_surface's scene tree is created (which is probably when the xdg_surface itself is created since the scene tree needs to be there for popups to be added to it) and throughout its entire lifetime the compositor knows exactly where the node should be, including when it isn't mapped onto the screen. That could be a problem if, for example, the compositor wanted to make a tree of nodes to help position views in a tiling window manager layout and wanted a view to be able to appear on multiple workspaces, in which case the compositor would only know where in a per-workspace sub-tree the view should be placed once a workspace with the view is mapped. In that situation the compositor may want to have the view or xdg_surace's root node detached from the main scene tree while it isn't mapped and attach it at the right place when it needs to be visible. Right now you can more-or-less still do that, by attaching the node at an arbitrary place in the scene tree and keeping it disabled, but that seems unintuitive.
I haven't thoroughly reviewed the relevant parts of the codebase, but this seems like a failry trivial change to make, and I think it would make some design patterns a bit easier. The API shouldn't need any major changes, either. The parent argument in functions like wlr_scene_tree_create
and wlr_scene_node_reparent
could be passed as NULL
to indicate the node shouldn't have a parent, which would currently just result in a failed assertion.
Similarly, I think it would be helpful to allow a scene node to be transferred to a different scene tree. I don't even know if that would need any code changes, but the documentation for wlr_scene_node_reparent
at least implies otherwise: Move the node to another location in the tree
.