From bdcffbd6118c91471eb8050d16de87fd116a8c17 Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Mon, 26 Aug 2024 15:46:55 -0400 Subject: [PATCH] scene_descriptor: Add scene_descriptor_reassign Same as the assign variant, but lets us mutate an existing descriptor if it exists instead of asserting. --- include/sway/scene_descriptor.h | 3 +++ sway/scene_descriptor.c | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/sway/scene_descriptor.h b/include/sway/scene_descriptor.h index f29bb6b1..e71b5c42 100644 --- a/include/sway/scene_descriptor.h +++ b/include/sway/scene_descriptor.h @@ -32,6 +32,9 @@ enum sway_scene_descriptor_type { bool scene_descriptor_assign(struct wlr_scene_node *node, enum sway_scene_descriptor_type type, void *data); +bool scene_descriptor_reassign(struct wlr_scene_node *node, + enum sway_scene_descriptor_type type, void *data); + void *scene_descriptor_try_get(struct wlr_scene_node *node, enum sway_scene_descriptor_type type); diff --git a/sway/scene_descriptor.c b/sway/scene_descriptor.c index 68cd6e7f..2f03fc59 100644 --- a/sway/scene_descriptor.c +++ b/sway/scene_descriptor.c @@ -89,3 +89,14 @@ bool scene_descriptor_assign(struct wlr_scene_node *node, desc->data = data; return true; } + +bool scene_descriptor_reassign(struct wlr_scene_node *node, + enum sway_scene_descriptor_type type, void *data) { + struct scene_descriptor *desc = scene_node_get_descriptor(node, type); + if (desc) { + desc->data = data; + return true; + } + + return scene_descriptor_assign(node, type, data); +}