initial fade-out groundwork

This commit is contained in:
William McKinnon 2023-07-20 00:58:57 -04:00
parent 6084ea42ec
commit e51fda46d3
4 changed files with 9 additions and 8 deletions

View file

@ -122,6 +122,7 @@ struct sway_container {
// TODO: move alpha to state?
float alpha;
float target_alpha;
float max_alpha;
int corner_radius;

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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;