From 0d4b45c710e6387588651f504615ad06e5cb262d Mon Sep 17 00:00:00 2001 From: Felix Kratz Date: Tue, 3 Oct 2023 17:32:21 +0200 Subject: [PATCH] remove an animation only after it has displayed its last frame (#404) --- src/animation.c | 15 +++++++++------ src/animation.h | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/animation.c b/src/animation.c index 11b0563..4d46076 100644 --- a/src/animation.c +++ b/src/animation.c @@ -57,11 +57,13 @@ static bool animation_update(struct animation* animation, double time_scale) { return false; } - double slider = (animation->duration > 1 - && animation->counter < animation->duration) - ? animation->interp_function(animation->counter - / animation->duration) - : 1.0; + bool final_frame = !((animation->duration > 1 + && animation->counter < animation->duration)); + + double slider = final_frame + ? 1.0 + : animation->interp_function(animation->counter + / animation->duration); int value; if (animation->separate_bytes) { @@ -106,6 +108,7 @@ static bool animation_update(struct animation* animation, double time_scale) { if (!found_item && needs_update) g_bar_manager.bar_needs_update = true; + animation->finished = final_frame; return needs_update; } @@ -268,7 +271,7 @@ bool animator_update(struct animator* animator) { needs_refresh |= animation_update(animator->animations[i], animator->time_scale ); - if (animator->animations[i]->counter > animator->animations[i]->duration) { + if (animator->animations[i]->finished) { remove[remove_count++] = animator->animations[i]; } } diff --git a/src/animation.h b/src/animation.h index 1e5ed5e..cca3a7b 100644 --- a/src/animation.h +++ b/src/animation.h @@ -85,6 +85,7 @@ struct animation { bool separate_bytes; bool as_float; bool locked; + bool finished; double duration; double counter;