From 91f4604199d6fc7f0296fc4e0f78e342b8761d01 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Fri, 12 Dec 2025 11:08:53 +0800 Subject: [PATCH] feat: add fadein fadeout curve --- config.conf | 2 ++ src/animation/client.h | 14 ++++++++++++-- src/animation/common.h | 20 ++++++++++++++++++++ src/animation/layer.h | 18 ++++++++++++++---- src/config/parse_config.h | 34 ++++++++++++++++++++++++++++++++++ src/config/preset.h | 12 +++++++----- src/mango.c | 4 +++- 7 files changed, 92 insertions(+), 12 deletions(-) diff --git a/config.conf b/config.conf index 4c8d8d3..e93b3e6 100644 --- a/config.conf +++ b/config.conf @@ -48,6 +48,8 @@ animation_curve_move=0.46,1.0,0.29,1 animation_curve_tag=0.46,1.0,0.29,1 animation_curve_close=0.08,0.92,0,1 animation_curve_focus=0.46,1.0,0.29,1 +animation_curve_opafadeout=0.5,0.5,0.5,0.5 +animation_curve_opafadein=0.46,1.0,0.29,1 # Scroller Layout Setting scroller_structs=20 diff --git a/src/animation/client.h b/src/animation/client.h index 67f4c10..b4f70e0 100644 --- a/src/animation/client.h +++ b/src/animation/client.h @@ -630,6 +630,7 @@ void fadeout_client_animation_next_tick(Client *c) { int type = c->animation.action = c->animation.action; double factor = find_animation_curve_at(animation_passed, type); + uint32_t width = c->animation.initial.width + (c->current.width - c->animation.initial.width) * factor; uint32_t height = @@ -650,7 +651,13 @@ void fadeout_client_animation_next_tick(Client *c) { .height = height, }; - double opacity = MAX(fadeout_begin_opacity - animation_passed, 0); + double opacity_eased_progress = + find_animation_curve_at(animation_passed, OPAFADEOUT); + + double percent = fadeout_begin_opacity - + (opacity_eased_progress * fadeout_begin_opacity); + + double opacity = MAX(percent, 0); if (animation_fade_out && !c->nofadeout) wlr_scene_node_for_each_buffer(&c->scene->node, @@ -1109,8 +1116,11 @@ bool client_apply_focus_opacity(Client *c) { ? (double)passed_time / (double)c->animation.duration : 1.0; + double opacity_eased_progress = + find_animation_curve_at(linear_progress, OPAFADEIN); + float percent = - animation_fade_in && !c->nofadein ? linear_progress : 1.0; + animation_fade_in && !c->nofadein ? opacity_eased_progress : 1.0; float opacity = c == selmon->sel ? c->focused_opacity : c->unfocused_opacity; diff --git a/src/animation/common.h b/src/animation/common.h index 2ff6744..0f662d6 100644 --- a/src/animation/common.h +++ b/src/animation/common.h @@ -11,6 +11,10 @@ struct dvec2 calculate_animation_curve_at(double t, int type) { animation_curve = animation_curve_close; } else if (type == FOCUS) { animation_curve = animation_curve_focus; + } else if (type == OPAFADEIN) { + animation_curve = animation_curve_opafadein; + } else if (type == OPAFADEOUT) { + animation_curve = animation_curve_opafadeout; } else { animation_curve = animation_curve_move; } @@ -32,6 +36,10 @@ void init_baked_points(void) { calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_close)); baked_points_focus = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_focus)); + baked_points_opafadein = + calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_opafadein)); + baked_points_opafadeout = + calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_opafadeout)); for (uint32_t i = 0; i < BAKED_POINTS_COUNT; i++) { baked_points_move[i] = calculate_animation_curve_at( @@ -53,6 +61,14 @@ void init_baked_points(void) { baked_points_focus[i] = calculate_animation_curve_at( (double)i / (BAKED_POINTS_COUNT - 1), FOCUS); } + for (uint32_t i = 0; i < BAKED_POINTS_COUNT; i++) { + baked_points_opafadein[i] = calculate_animation_curve_at( + (double)i / (BAKED_POINTS_COUNT - 1), OPAFADEIN); + } + for (uint32_t i = 0; i < BAKED_POINTS_COUNT; i++) { + baked_points_opafadeout[i] = calculate_animation_curve_at( + (double)i / (BAKED_POINTS_COUNT - 1), OPAFADEOUT); + } } double find_animation_curve_at(double t, int type) { @@ -71,6 +87,10 @@ double find_animation_curve_at(double t, int type) { baked_points = baked_points_close; } else if (type == FOCUS) { baked_points = baked_points_focus; + } else if (type == OPAFADEIN) { + baked_points = baked_points_opafadein; + } else if (type == OPAFADEOUT) { + baked_points = baked_points_opafadeout; } else { baked_points = baked_points_move; } diff --git a/src/animation/layer.h b/src/animation/layer.h index e36ddd1..57e0c14 100644 --- a/src/animation/layer.h +++ b/src/animation/layer.h @@ -276,7 +276,13 @@ void fadeout_layer_animation_next_tick(LayerSurface *l) { .height = height, }; - double opacity = MAX(fadeout_begin_opacity - animation_passed, 0.0f); + double opacity_eased_progress = + find_animation_curve_at(animation_passed, OPAFADEOUT); + + double percent = fadeout_begin_opacity - + (opacity_eased_progress * fadeout_begin_opacity); + + double opacity = MAX(percent, 0.0f); if (animation_fade_out) wlr_scene_node_for_each_buffer(&l->scene->node, @@ -318,9 +324,13 @@ void layer_animation_next_tick(LayerSurface *l) { uint32_t y = l->animation.initial.y + (l->current.y - l->animation.initial.y) * factor; - double opacity = MIN(fadein_begin_opacity + - animation_passed * (1.0 - fadein_begin_opacity), - 1.0f); + double opacity_eased_progress = + find_animation_curve_at(animation_passed, OPAFADEIN); + + double opacity = + MIN(fadein_begin_opacity + + opacity_eased_progress * (1.0 - fadein_begin_opacity), + 1.0f); if (animation_fade_in) wlr_scene_node_for_each_buffer(&l->scene->node, diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 0479c6d..4da82c5 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -194,6 +194,8 @@ typedef struct { double animation_curve_tag[4]; double animation_curve_close[4]; double animation_curve_focus[4]; + double animation_curve_opafadein[4]; + double animation_curve_opafadeout[4]; int scroller_structs; float scroller_default_proportion; @@ -1181,6 +1183,22 @@ void parse_option(Config *config, char *key, char *value) { "Error: Failed to parse animation_curve_focus: %s\n", value); } + } else if (strcmp(key, "animation_curve_opafadein") == 0) { + int num = + parse_double_array(value, config->animation_curve_opafadein, 4); + if (num != 4) { + fprintf(stderr, + "Error: Failed to parse animation_curve_opafadein: %s\n", + value); + } + } else if (strcmp(key, "animation_curve_opafadeout") == 0) { + int num = + parse_double_array(value, config->animation_curve_opafadeout, 4); + if (num != 4) { + fprintf(stderr, + "Error: Failed to parse animation_curve_opafadeout: %s\n", + value); + } } else if (strcmp(key, "scroller_structs") == 0) { config->scroller_structs = atoi(value); } else if (strcmp(key, "scroller_default_proportion") == 0) { @@ -2398,6 +2416,14 @@ void free_baked_points(void) { free(baked_points_focus); baked_points_focus = NULL; } + if (baked_points_opafadein) { + free(baked_points_opafadein); + baked_points_opafadein = NULL; + } + if (baked_points_opafadeout) { + free(baked_points_opafadeout); + baked_points_opafadeout = NULL; + } } void free_config(void) { @@ -2810,6 +2836,10 @@ void override_config(void) { sizeof(animation_curve_close)); memcpy(animation_curve_focus, config.animation_curve_focus, sizeof(animation_curve_focus)); + memcpy(animation_curve_opafadein, config.animation_curve_opafadein, + sizeof(animation_curve_opafadein)); + memcpy(animation_curve_opafadeout, config.animation_curve_opafadeout, + sizeof(animation_curve_opafadeout)); } void set_value_default() { @@ -2958,6 +2988,10 @@ void set_value_default() { sizeof(animation_curve_close)); memcpy(config.animation_curve_focus, animation_curve_focus, sizeof(animation_curve_focus)); + memcpy(config.animation_curve_opafadein, animation_curve_opafadein, + sizeof(animation_curve_opafadein)); + memcpy(config.animation_curve_opafadeout, animation_curve_opafadeout, + sizeof(animation_curve_opafadeout)); memcpy(config.rootcolor, rootcolor, sizeof(rootcolor)); memcpy(config.bordercolor, bordercolor, sizeof(bordercolor)); diff --git a/src/config/preset.h b/src/config/preset.h index ed743a8..7b45315 100644 --- a/src/config/preset.h +++ b/src/config/preset.h @@ -26,11 +26,13 @@ uint32_t animation_duration_open = 400; // Animation open speed uint32_t animation_duration_tag = 300; // Animation tag speed uint32_t animation_duration_close = 300; // Animation close speed uint32_t animation_duration_focus = 0; // Animation focus opacity speed -double animation_curve_move[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 -double animation_curve_open[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 -double animation_curve_tag[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 -double animation_curve_close[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 -double animation_curve_focus[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_move[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_open[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_tag[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_close[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_focus[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_opafadein[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_opafadeout[4] = {0.5, 0.5, 0.5, 0.5}; // 动画曲线 /* appearance */ uint32_t axis_bind_apply_timeout = 100; // 滚轮绑定动作的触发的时间间隔 diff --git a/src/mango.c b/src/mango.c index ce22e31..45a0e64 100644 --- a/src/mango.c +++ b/src/mango.c @@ -165,7 +165,7 @@ enum { }; /* EWMH atoms */ #endif enum { UP, DOWN, LEFT, RIGHT, UNDIR }; /* smartmovewin */ -enum { NONE, OPEN, MOVE, CLOSE, TAG, FOCUS }; +enum { NONE, OPEN, MOVE, CLOSE, TAG, FOCUS, OPAFADEIN, OPAFADEOUT }; enum { UNFOLD, FOLD, INVALIDFOLD }; enum { PREV, NEXT }; enum { STATE_UNSPECIFIED = 0, STATE_ENABLED, STATE_DISABLED }; @@ -850,6 +850,8 @@ struct dvec2 *baked_points_open; struct dvec2 *baked_points_tag; struct dvec2 *baked_points_close; struct dvec2 *baked_points_focus; +struct dvec2 *baked_points_opafadein; +struct dvec2 *baked_points_opafadeout; static struct wl_event_source *hide_source; static bool cursor_hidden = false;