From 3cb407e65c899dd87c09a8eb18cc32c2980e8fc5 Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Wed, 9 Aug 2023 00:52:51 -0400 Subject: [PATCH] moved animation to timer --- include/sway/tree/container.h | 2 ++ sway/desktop/output.c | 25 ----------------------- sway/tree/container.c | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 35df6c00..7fb0286f 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -124,6 +124,8 @@ struct sway_container { float target_alpha; float max_alpha; + struct wl_event_source *animation_present_timer; + int corner_radius; float dim; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 8c42ccca..fbcd2540 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -521,29 +521,6 @@ static bool scan_out_fullscreen_view(struct sway_output *output, return wlr_output_commit(wlr_output); } -static void containers_tick_alpha(list_t *containers, struct sway_output *output) { - float alpha_step; - struct sway_container *con = NULL; - for (int i = 0; i < containers->length; ++i) { - con = containers->items[i]; - if (con->pending.children) { - containers_tick_alpha(con->pending.children, output); - } else { // should this else be removed? - if (con->alpha == con->target_alpha) { - continue; - } - if (config->animation_duration == 0) { - con->alpha = con->target_alpha; - continue; - } - alpha_step = (con->max_alpha * output->refresh_sec) / config->animation_duration; - con->alpha = con->alpha < con->target_alpha ? MIN(con->alpha + alpha_step, con->target_alpha) - : MAX(con->alpha - alpha_step, con->target_alpha); - output_damage_whole_container(output, con); - } - } -} - static int output_repaint_timer_handler(void *data) { struct sway_output *output = data; if (output->wlr_output == NULL) { @@ -591,8 +568,6 @@ static int output_repaint_timer_handler(void *data) { return 0; } - containers_tick_alpha(workspace->current.tiling, output); - pixman_region32_t damage; pixman_region32_init(&damage); diff --git a/sway/tree/container.c b/sway/tree/container.c index de7ec80d..49000bdb 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -30,6 +30,32 @@ #include "log.h" #include "stringop.h" +// TODO determine return val +// TODO no longer need output->refresh sec? +// TODO signal instead of timer? +// TODO better timing +static int animation_timer(void *data) { + struct sway_container *con = data; + unsigned int fastest_output_refresh_ns = 0; + for (int i = 0; i < con->outputs->length; ++i) { + struct sway_output *output = root->outputs->items[i]; + fastest_output_refresh_ns = MAX(fastest_output_refresh_ns, output->refresh_nsec); + + float alpha_step = config->animation_duration ? + (con->max_alpha * output->refresh_sec) / config->animation_duration : con->max_alpha; + con->alpha = con->alpha < con->target_alpha ? MIN(con->alpha + alpha_step, con->target_alpha) + : MAX(con->alpha - alpha_step, con->target_alpha); + } + if (con->alpha != con->target_alpha) { + wl_event_source_timer_update(con->animation_present_timer, fastest_output_refresh_ns / 1000000); + } else { + wl_event_source_remove(con->animation_present_timer); + } + container_damage_whole(con); + + return 1; +} + struct sway_container *container_create(struct sway_view *view) { struct sway_container *c = calloc(1, sizeof(struct sway_container)); if (!c) { @@ -56,6 +82,13 @@ struct sway_container *container_create(struct sway_view *view) { c->outputs = create_list(); wl_signal_init(&c->events.destroy); + + c->animation_present_timer = wl_event_loop_add_timer(server.wl_event_loop, + animation_timer, c); + // TODO: pass 0 instead of animation_duration_msec? + int animation_duration_msec = (int)(config->animation_duration * 1000); + wl_event_source_timer_update(c->animation_present_timer, animation_duration_msec); + wl_signal_emit_mutable(&root->events.new_node, &c->node); return c; @@ -88,6 +121,10 @@ void container_destroy(struct sway_container *con) { wlr_texture_destroy(con->marks_urgent); wlr_texture_destroy(con->marks_focused_tab_title); + if (con->animation_present_timer) { + wl_event_source_remove(con->animation_present_timer); + } + if (con->view && con->view->container == con) { con->view->container = NULL; if (con->view->destroying) {