added fade out

This commit is contained in:
William McKinnon 2023-08-19 15:58:14 -04:00
parent 07665971dc
commit 87f33da112
2 changed files with 12 additions and 10 deletions

View file

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

View file

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