From 86e9309808ae147dff0ac3884148d53b2c3edf2b Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 6 May 2020 16:16:45 +0200 Subject: [PATCH] scene: add wlr_scene_node_toggle This allows compositors to easily enable or disable a scene-graph node. This can be used to show/hide a surface when the xdg_surface is mapped/unmapped. --- include/wlr/types/wlr_scene.h | 6 ++++++ types/wlr_scene.c | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/include/wlr/types/wlr_scene.h b/include/wlr/types/wlr_scene.h index 953b1b876..b56905753 100644 --- a/include/wlr/types/wlr_scene.h +++ b/include/wlr/types/wlr_scene.h @@ -35,6 +35,7 @@ struct wlr_scene_node_state { struct wl_list children; // wlr_scene_node_state.link + bool enabled; int x, y; // relative to parent }; @@ -68,6 +69,11 @@ struct wlr_scene_surface { * Immediately destroy the scene-graph node. */ void wlr_scene_node_destroy(struct wlr_scene_node *node); +/** + * Enable or disable this node. If a node is disabled, all of its children are + * implicitly disabled as well. + */ +void wlr_scene_node_set_enabled(struct wlr_scene_node *node, bool enabled); /** * Set the position of the node relative to its parent. */ diff --git a/types/wlr_scene.c b/types/wlr_scene.c index 7b1690e93..453a960cf 100644 --- a/types/wlr_scene.c +++ b/types/wlr_scene.c @@ -21,6 +21,7 @@ static struct wlr_scene_surface *scene_surface_from_node( static void scene_node_state_init(struct wlr_scene_node_state *state) { wl_list_init(&state->children); wl_list_init(&state->link); + state->enabled = true; } static void scene_node_state_finish(struct wlr_scene_node_state *state) { @@ -108,6 +109,10 @@ struct wlr_scene_surface *wlr_scene_surface_create(struct wlr_scene_node *parent return scene_surface; } +void wlr_scene_node_set_enabled(struct wlr_scene_node *node, bool enabled) { + node->state.enabled = enabled; +} + void wlr_scene_node_set_position(struct wlr_scene_node *node, int x, int y) { node->state.x = x; node->state.y = y; @@ -132,6 +137,10 @@ void wlr_scene_node_place_below(struct wlr_scene_node *node, 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) { + if (!node->state.enabled) { + return; + } + lx += node->state.x; ly += node->state.y;