moved animation to timer

This commit is contained in:
William McKinnon 2023-08-09 00:52:51 -04:00
parent 1c3b4a12ee
commit 3cb407e65c
3 changed files with 39 additions and 25 deletions

View file

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

View file

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

View file

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