From 819572a8d9eaaaae920d8d7b6228f39dae7890bd Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Sat, 20 Apr 2024 16:47:42 -0400 Subject: [PATCH] logic improvements --- sway/server.c | 13 +++++++++---- sway/tree/container.c | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sway/server.c b/sway/server.c index 0ea58752..7ca2521c 100644 --- a/sway/server.c +++ b/sway/server.c @@ -97,6 +97,10 @@ static int animation_timer(void *data) { int num_containers; memcpy(&num_containers, &server->animated_containers->length, sizeof(int)); + if (num_containers == 0) { + return 1; + } + int num_animations_complete = 0; int completed_animation_indices[100]; // TODO: this can be better bool is_container_close_animation_complete = false; @@ -105,6 +109,8 @@ static int animation_timer(void *data) { // update state for (int i = 0; i < num_containers; i++) { struct sway_container *con = server->animated_containers->items[i]; + sway_assert(con->view, "container being animated is not a view container"); + bool is_closing = con->alpha > con->target_alpha; float alpha_step = config->animation_duration ? (con->max_alpha * fastest_output_refresh_s) / config->animation_duration : con->max_alpha; @@ -130,15 +136,14 @@ static int animation_timer(void *data) { } else { for (int i = 0; i < num_containers; i++) { struct sway_container *con = server->animated_containers->items[i]; - // TODO: remove add assertion for con->view & investigate what happens when split h containers are spawned - if (con->view && view_is_visible(con->view)) { + if (view_is_visible(con->view)) { container_damage_whole(con); } } } - // clean up list - for (int i = 0; i < num_animations_complete; i++) { + // clean up list: del containers that are done animating from last to first in order prevent later indices being incorrect + for (int i = num_animations_complete - 1; i >= 0; i--) { int container_index = completed_animation_indices[i]; list_del(server->animated_containers, container_index); } diff --git a/sway/tree/container.c b/sway/tree/container.c index 4d0e20e6..9907c4e9 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -48,6 +48,8 @@ struct sway_container *container_create(struct sway_view *view) { if (!view) { c->pending.children = create_list(); c->current.children = create_list(); + } else { + list_add(server.animated_containers, c); } c->marks = create_list(); c->outputs = create_list(); @@ -55,7 +57,6 @@ struct sway_container *container_create(struct sway_view *view) { wl_signal_init(&c->events.destroy); wl_signal_emit_mutable(&root->events.new_node, &c->node); - list_add(server.animated_containers, c); return c; }