From 7e9ad9a67b7f66487a61f9ac97e8d5c4b88f74f4 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 | 7 +++++++ types/wlr_scene.c | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/wlr/types/wlr_scene.h b/include/wlr/types/wlr_scene.h index 300807fa7..549817b95 100644 --- a/include/wlr/types/wlr_scene.h +++ b/include/wlr/types/wlr_scene.h @@ -32,6 +32,7 @@ struct wlr_scene_node_state { struct wl_list children; // wlr_scene_node_state.link + bool enabled; int x, y; }; @@ -66,6 +67,12 @@ void wlr_scene_node_destroy(struct wlr_scene_node *node); * Atomically apply pending changes for this node and all of its children. */ void wlr_scene_node_commit(struct wlr_scene_node *node); +/** + * Enable or disable this node. If a node is disabled, all of its children are + * implicitly disabled as well. This state is double-buffered, see + * wlr_scene_node_commit. + */ +void wlr_scene_node_toggle(struct wlr_scene_node *node, bool enabled); /** * Set the position of the node relative to its parent. This state is * double-buffered, see wlr_scene_node_commit. diff --git a/types/wlr_scene.c b/types/wlr_scene.c index 626edf52d..eb4fa7335 100644 --- a/types/wlr_scene.c +++ b/types/wlr_scene.c @@ -21,6 +21,7 @@ static struct wlr_scene_surface *scene_node_get_surface( 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) { @@ -118,6 +119,7 @@ struct wlr_scene_surface *wlr_scene_surface_create(struct wlr_scene_node *parent static void scene_node_state_move(struct wlr_scene_node_state *dst, const struct wlr_scene_node_state *src) { + dst->enabled = src->enabled; dst->x = src->x; dst->y = src->y; } @@ -136,6 +138,10 @@ void wlr_scene_node_commit(struct wlr_scene_node *node) { } } +void wlr_scene_node_toggle(struct wlr_scene_node *node, bool enabled) { + node->pending.enabled = enabled; +} + void wlr_scene_node_move(struct wlr_scene_node *node, int x, int y) { node->pending.x = x; node->pending.y = y; @@ -172,6 +178,10 @@ static void surface_iterator(struct wlr_surface *surface, 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->current.enabled) { + return; + } + lx += node->current.x; ly += node->current.y;