From 1a9b3ce0d04073faff0bcf1d0480cc1c0fe5b830 Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Mon, 26 Aug 2024 15:36:31 -0400 Subject: [PATCH] scene_descriptor: Add scene_descriptor_find --- include/sway/scene_descriptor.h | 10 ++++++++++ sway/scene_descriptor.c | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/sway/scene_descriptor.h b/include/sway/scene_descriptor.h index 9ffb2e5d..f29bb6b1 100644 --- a/include/sway/scene_descriptor.h +++ b/include/sway/scene_descriptor.h @@ -38,4 +38,14 @@ void *scene_descriptor_try_get(struct wlr_scene_node *node, void scene_descriptor_destroy(struct wlr_scene_node *node, enum sway_scene_descriptor_type type); +/* + * Searches the scene node and all its parents for this scene descriptor. + * + * Note that while searching, SWAY_SCENE_DESC_POPUP types will start tracking + * its relative node. With popups, they are part of a seperate layer in the scene + * graph, but that's irrelavent to users of this function. + */ +void *scene_descriptor_find(struct wlr_scene_node *node, + enum sway_scene_descriptor_type type); + #endif diff --git a/sway/scene_descriptor.c b/sway/scene_descriptor.c index a30d4664..68cd6e7f 100644 --- a/sway/scene_descriptor.c +++ b/sway/scene_descriptor.c @@ -36,6 +36,31 @@ void *scene_descriptor_try_get(struct wlr_scene_node *node, return desc->data; } +void *scene_descriptor_find(struct wlr_scene_node *node, + enum sway_scene_descriptor_type type) { + while (node) { + struct scene_descriptor *desc = scene_node_get_descriptor(node, type); + if (desc) { + return desc->data; + } + + struct sway_popup_desc *popup = + scene_descriptor_try_get(node, SWAY_SCENE_DESC_POPUP); + if (popup) { + node = popup->relative; + continue; + } + + if (!node->parent) { + break; + } + + node = &node->parent->node; + } + + return NULL; +} + void scene_descriptor_destroy(struct wlr_scene_node *node, enum sway_scene_descriptor_type type) { struct scene_descriptor *desc = scene_node_get_descriptor(node, type);