From 87f33da112539e26528b4ba0bbaa1733f0575036 Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Sat, 19 Aug 2023 15:58:14 -0400 Subject: [PATCH] added fade out --- sway/tree/container.c | 17 ++++++++++------- sway/tree/view.c | 5 ++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/sway/tree/container.c b/sway/tree/container.c index 055326b7..818ef76c 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -30,27 +30,31 @@ #include "log.h" #include "stringop.h" +// TODO signal instead of timer? // 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; + bool is_closing = con->alpha > con->target_alpha; + 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); + con->alpha = is_closing ? MAX(con->alpha - alpha_step, con->target_alpha) : + MIN(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 if (is_closing && con->view->impl->close) { + con->view->impl->close(con->view); } - container_damage_whole(con); + container_damage_whole(con); return 1; } @@ -84,8 +88,7 @@ struct sway_container *container_create(struct sway_view *view) { 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_event_source_timer_update(c->animation_present_timer, 1000); wl_signal_emit_mutable(&root->events.new_node, &c->node); diff --git a/sway/tree/view.c b/sway/tree/view.c index 272967f4..d37cfb40 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -428,9 +428,8 @@ void view_set_tiled(struct sway_view *view, bool tiled) { } void view_close(struct sway_view *view) { - if (view->impl->close) { - view->impl->close(view); - } + view->container->target_alpha = 0; + wl_event_source_timer_update(view->container->animation_present_timer, 1); } void view_close_popups(struct sway_view *view) {