From e51fda46d362240c4bb99c1612659d78915a1488 Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Thu, 20 Jul 2023 00:58:57 -0400 Subject: [PATCH] initial fade-out groundwork --- include/sway/tree/container.h | 1 + sway/commands/opacity.c | 5 +++-- sway/desktop/output.c | 10 ++++------ sway/tree/container.c | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 0707a605..35df6c00 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -122,6 +122,7 @@ struct sway_container { // TODO: move alpha to state? float alpha; float target_alpha; + float max_alpha; int corner_radius; diff --git a/sway/commands/opacity.c b/sway/commands/opacity.c index f8c10645..2ec48fb9 100644 --- a/sway/commands/opacity.c +++ b/sway/commands/opacity.c @@ -24,9 +24,9 @@ struct cmd_results *cmd_opacity(int argc, char **argv) { } if (!strcasecmp(argv[0], "plus")) { - val = con->target_alpha + val; + val = con->max_alpha + val; } else if (!strcasecmp(argv[0], "minus")) { - val = con->target_alpha - val; + val = con->max_alpha - val; } else if (argc > 1 && strcasecmp(argv[0], "set")) { return cmd_results_new(CMD_INVALID, "Expected: set|plus|minus <0..1>: %s", argv[0]); @@ -36,6 +36,7 @@ struct cmd_results *cmd_opacity(int argc, char **argv) { return cmd_results_new(CMD_FAILURE, "opacity value out of bounds"); } + con->max_alpha = val; con->target_alpha = val; container_damage_whole(con); return cmd_results_new(CMD_SUCCESS, NULL); diff --git a/sway/desktop/output.c b/sway/desktop/output.c index d824bd05..ff9a6ed6 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -527,19 +527,17 @@ 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) { - struct sway_container *con = containers->items[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; - } else if (con->alpha < con->target_alpha) { // fade-in animation - alpha_step = (con->target_alpha * output->refresh_sec) / config->animation_duration; - con->alpha = MIN(con->alpha + alpha_step, con->target_alpha); - } else if (con->alpha > con->target_alpha) { // fade-out animation - // TODO } + 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); } } diff --git a/sway/tree/container.c b/sway/tree/container.c index 14e01225..de7ec80d 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -41,6 +41,7 @@ struct sway_container *container_create(struct sway_view *view) { c->view = view; c->alpha = 0.0f; c->target_alpha = 1.0f; + c->max_alpha = 1.0f; c->saturation = 1.0f; c->dim = config->default_dim_inactive; c->shadow_enabled = config->shadow_enabled;