From 3f5511d09e1859bc5ebf4df7f2e7eb6c644f610c Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Tue, 23 May 2023 01:17:20 -0400 Subject: [PATCH] ensured alpha isn't exceeded, added calculation for alpha_step from animation_duration --- sway/desktop/output.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index cff1bac1..0d4d04ee 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -522,13 +522,21 @@ static bool scan_out_fullscreen_view(struct sway_output *output, } static void containers_tick_alpha(list_t *containers, struct sway_output *output) { - // TODO: config for alpha_step - float alpha_step = 0.01; + // TODO: config for animation_duration + float animation_duration = 0.5; + + const long NSEC_IN_SECONDS = 1000000000; + float output_refresh_seconds = (float)output->refresh_nsec / NSEC_IN_SECONDS; + float num_refreshes = animation_duration / output_refresh_seconds; + + float alpha_step; for (int i = 0; i < containers->length; ++i) { struct sway_container *con = containers->items[i]; if (con->current_alpha < con->alpha) { + alpha_step = (con->alpha) / num_refreshes; + // ensure that the current alpha does not exceed the set alpha for the con + con->current_alpha = MIN(con->current_alpha + alpha_step, con->alpha); output_damage_whole_container(output, con); - con->current_alpha += alpha_step; } } }