From a1d462fa81682d4820d13020769ba86286868b60 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Mon, 23 Aug 2021 14:32:59 -0500 Subject: [PATCH] scene: add node reparent function If nodes are arranged in a tree rather than at a single level, then it makes sense that there should be a way to move them to a completely different parent in addition to moving up or down among siblings. --- include/wlr/types/wlr_scene.h | 5 +++++ types/wlr_scene.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/wlr/types/wlr_scene.h b/include/wlr/types/wlr_scene.h index 8a327262..a489d6af 100644 --- a/include/wlr/types/wlr_scene.h +++ b/include/wlr/types/wlr_scene.h @@ -90,6 +90,11 @@ void wlr_scene_node_place_above(struct wlr_scene_node *node, */ void wlr_scene_node_place_below(struct wlr_scene_node *node, struct wlr_scene_node *sibling); +/** + * Move the node to another location in the tree. + */ +void wlr_scene_node_reparent(struct wlr_scene_node *node, + struct wlr_scene_node *new_parent); /** * Call `iterator` on each surface in the scene-graph, with the surface's * position in layout coordinates. The function is called from root to leaves diff --git a/types/wlr_scene.c b/types/wlr_scene.c index 7e8c332b..99b8076a 100644 --- a/types/wlr_scene.c +++ b/types/wlr_scene.c @@ -133,6 +133,20 @@ void wlr_scene_node_place_below(struct wlr_scene_node *node, wl_list_insert(sibling->state.link.prev, &node->state.link); } +void wlr_scene_node_reparent(struct wlr_scene_node *node, + struct wlr_scene_node *new_parent) { + if (node->parent == new_parent) { + return; + } + + wl_list_remove(&node->state.link); + + node->parent = new_parent; + if (new_parent != NULL) { + wl_list_insert(new_parent->state.children.prev, &node->state.link); + } +} + static void scene_node_for_each_surface(struct wlr_scene_node *node, int lx, int ly, wlr_surface_iterator_func_t user_iterator, void *user_data) {