feat: layer zoom out animaiton

This commit is contained in:
DreamMaoMao 2025-07-12 14:46:22 +08:00
parent b9b82c1c96
commit 4f44d3dd06

View file

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