scene_descriptor: Add scene_descriptor_find

This commit is contained in:
Alexander Orzechowski 2024-08-26 15:36:31 -04:00
parent d3f0929f79
commit 1a9b3ce0d0
2 changed files with 35 additions and 0 deletions

View file

@ -38,4 +38,14 @@ void *scene_descriptor_try_get(struct wlr_scene_node *node,
void scene_descriptor_destroy(struct wlr_scene_node *node, void scene_descriptor_destroy(struct wlr_scene_node *node,
enum sway_scene_descriptor_type type); 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 #endif

View file

@ -36,6 +36,31 @@ void *scene_descriptor_try_get(struct wlr_scene_node *node,
return desc->data; 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, void scene_descriptor_destroy(struct wlr_scene_node *node,
enum sway_scene_descriptor_type type) { enum sway_scene_descriptor_type type) {
struct scene_descriptor *desc = scene_node_get_descriptor(node, type); struct scene_descriptor *desc = scene_node_get_descriptor(node, type);