From 4f44d3dd06cacbb454d44de86fb9acba7e973b1e Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sat, 12 Jul 2025 14:46:22 +0800 Subject: [PATCH] feat: layer zoom out animaiton --- src/animation/layer.h | 58 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/src/animation/layer.h b/src/animation/layer.h index b6fa817..12d520f 100644 --- a/src/animation/layer.h +++ b/src/animation/layer.h @@ -219,6 +219,13 @@ void layer_scene_buffer_apply_effect(struct wlr_scene_buffer *buffer, int sx, } } +void layer_fadeout_scene_buffer_apply_effect(struct wlr_scene_buffer *buffer, + int sx, int sy, void *data) { + animationScale *scale_data = (animationScale *)data; + wlr_scene_buffer_set_dest_size(buffer, scale_data->width, + scale_data->height); +} + void fadeout_layer_animation_next_tick(LayerSurface *l) { if (!l) return; @@ -241,6 +248,20 @@ void fadeout_layer_animation_next_tick(LayerSurface *l) { wlr_scene_node_set_position(&l->scene->node, x, y); + animationScale scale_data; + scale_data.width = width; + scale_data.height = height; + + if (((!l->animation_type_close && + strcmp(layer_animation_type_close, "zoom") == 0) || + (l->animation_type_close && + strcmp(l->animation_type_close, "zoom") == 0)) && + (width != l->current.width || height != l->current.height)) { + wlr_scene_node_for_each_buffer(&l->scene->node, + layer_fadeout_scene_buffer_apply_effect, + &scale_data); + } + l->animation.current = (struct wlr_box){ .x = x, .y = y, @@ -293,12 +314,12 @@ void layer_animation_next_tick(LayerSurface *l) { wlr_scene_node_for_each_buffer(&l->scene->node, scene_buffer_apply_opacity, &opacity); + wlr_scene_node_set_position(&l->scene->node, x, y); + animationScale scale_data; scale_data.width_scale = (float)width / (float)l->current.width; scale_data.height_scale = (float)height / (float)l->current.height; - wlr_scene_node_set_position(&l->scene->node, x, y); - if (((!l->animation_type_open && strcmp(layer_animation_type_open, "zoom") == 0) || (l->animation_type_open && @@ -350,6 +371,14 @@ void init_fadeout_layers(LayerSurface *l) { LayerSurface *fadeout_layer = ecalloc(1, sizeof(*fadeout_layer)); + const struct wlr_layer_surface_v1_state *state = &l->layer_surface->current; + struct wlr_box usable_area; + + if (state->exclusive_zone > 0 || state->exclusive_zone == -1) + usable_area = l->mon->m; + else + usable_area = l->mon->w; + wlr_scene_node_set_enabled(&l->scene->node, true); fadeout_layer->scene = wlr_scene_tree_snapshot(&l->scene->node, layers[LyrFadeOut]); @@ -366,6 +395,8 @@ void init_fadeout_layers(LayerSurface *l) { l->animation.current; fadeout_layer->mon = l->mon; fadeout_layer->animation.action = CLOSE; + fadeout_layer->animation_type_close = l->animation_type_close; + fadeout_layer->animation_type_open = l->animation_type_open; // 这里snap节点的坐标设置是使用的相对坐标,所以不能加上原来坐标 // 这跟普通node有区别 @@ -374,9 +405,28 @@ void init_fadeout_layers(LayerSurface *l) { fadeout_layer->animation.initial.y = 0; if ((!l->animation_type_close && - strcmp(layer_animation_type_close, "slide") == 0) || + strcmp(layer_animation_type_close, "zoom") == 0) || (l->animation_type_close && - strcmp(l->animation_type_close, "slide") == 0)) { + strcmp(l->animation_type_close, "zoom") == 0)) { + fadeout_layer->current.width = + (float)l->geom.width * zoom_initial_ratio; + fadeout_layer->current.height = + (float)l->geom.height * zoom_initial_ratio; + fadeout_layer->current.x = usable_area.x + usable_area.width / 2 - + fadeout_layer->current.width / 2; + fadeout_layer->current.y = usable_area.y + usable_area.height / 2 - + fadeout_layer->current.height / 2; + // 算出偏差 + fadeout_layer->current.x = fadeout_layer->current.x - l->geom.x; + fadeout_layer->current.y = fadeout_layer->current.y - l->geom.y; + + // wlr_log(WLR_ERROR,"%d %d %d + // %d",fadeout_layer->current.x,fadeout_layer->current.y,fadeout_layer->current.width,fadeout_layer->current.height); + + } else if ((!l->animation_type_close && + strcmp(layer_animation_type_close, "slide") == 0) || + (l->animation_type_close && + strcmp(l->animation_type_close, "slide") == 0)) { set_layer_dir_animaiton(l, &fadeout_layer->current); fadeout_layer->current.x = fadeout_layer->current.x - l->geom.x; fadeout_layer->current.y = fadeout_layer->current.y - l->geom.y;