scene_descriptor: Add scene_descriptor_reassign

Same as the assign variant, but lets us mutate an existing descriptor
if it exists instead of asserting.
This commit is contained in:
Alexander Orzechowski 2024-08-26 15:46:55 -04:00
parent 93961e988b
commit bdcffbd611
2 changed files with 14 additions and 0 deletions

View file

@ -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);

View file

@ -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);
}