From 69c103c8467bce312f367a5ba9ed8202b8728d9f Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sun, 2 Mar 2025 19:40:34 +0800 Subject: [PATCH] feat: close animation curve --- README.md | 13 +++++-------- config.conf | 1 + maomao.c | 14 +++++++++++++- parse_config.h | 11 +++++++++++ preset_config.h | 1 + 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d592417..610a2f4 100644 --- a/README.md +++ b/README.md @@ -124,10 +124,9 @@ because your keybinds contain shift, the `2` cover to `at` animation_curve_open=0.46,1.0,0.29,1.1 animation_curve_move=0.46,1.0,0.29,1 animation_curve_tag=0.46,1.0,0.29,1 +animation_curve_close=0.46,1.0,0.29,1 ``` -notice: close and move animations are the same curve. - You can design your animaition curve in: [here, on cssportal.com](https://www.cssportal.com/css-cubic-bezier-generator/), @@ -203,12 +202,10 @@ or you can just choice a curve in: - https://gitlab.freedesktop.org/wlroots/wlroots - Implementation of wayland protocol -- https://github.com/dqrk0jeste/owl - Implementation of simple basic animation +- https://github.com/dqrk0jeste/owl - for basal window animaition -- https://github.com/djpohly/dwl - Basic compositor functionality +- https://github.com/djpohly/dwl - for basal dwl feature -- https://github.com/guyuming76/dwl - Implementation of text-input protocol +- https://github.com/guyuming76/dwl - for text-input -- https://github.com/swaywm/sway - Demonstration application of the protocol - -- https://github.com/ErikReider/fx-comp - More cool effect +- https://github.com/swaywm/sway - for foreign-toplevel diff --git a/config.conf b/config.conf index f5b839c..d624866 100644 --- a/config.conf +++ b/config.conf @@ -12,6 +12,7 @@ animation_duration_close=500 animation_curve_open=0.46,1.0,0.29,1 animation_curve_move=0.46,1.0,0.29,1 animation_curve_tag=0.46,1.0,0.29,1 +animation_curve_close=0.46,1.0,0.29,1 # Scroller Layout Setting scroller_structs=20 diff --git a/maomao.c b/maomao.c index 621924a..a12fd54 100644 --- a/maomao.c +++ b/maomao.c @@ -690,6 +690,7 @@ struct vec2 { struct vec2 *baked_points_move; struct vec2 *baked_points_open; struct vec2 *baked_points_tag; +struct vec2 *baked_points_close; struct vec2 calculate_animation_curve_at(double t, int type) { struct vec2 point; @@ -700,6 +701,8 @@ struct vec2 calculate_animation_curve_at(double t, int type) { animation_curve = animation_curve_open; } else if (type == TAG) { animation_curve = animation_curve_tag; + } else if (type == CLOSE) { + animation_curve = animation_curve_close; } point.x = 3 * t * (1 - t) * (1 - t) * animation_curve[0] + @@ -715,6 +718,7 @@ void init_baked_points(void) { baked_points_move = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_move)); baked_points_open = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_open)); baked_points_tag = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_tag)); + baked_points_close = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_close)); for (size_t i = 0; i < BAKED_POINTS_COUNT; i++) { baked_points_move[i] = calculate_animation_curve_at( @@ -728,6 +732,10 @@ void init_baked_points(void) { baked_points_tag[i] = calculate_animation_curve_at((double)i / (BAKED_POINTS_COUNT - 1), TAG); } + for (size_t i = 0; i < BAKED_POINTS_COUNT; i++) { + baked_points_close[i] = + calculate_animation_curve_at((double)i / (BAKED_POINTS_COUNT - 1), CLOSE); + } } double find_animation_curve_at(double t, int type) { @@ -742,7 +750,10 @@ double find_animation_curve_at(double t, int type) { baked_points = baked_points_open; } else if (type == TAG) { baked_points = baked_points_tag; + } else if (type == CLOSE) { + baked_points = baked_points_close; } + while (up - down != 1) { if (baked_points[middle].x <= t) { down = middle; @@ -802,7 +813,7 @@ void fadeout_client_animation_next_tick(Client *c) { double animation_passed = (double)c->animation.passed_frames / c->animation.total_frames; - int type = c->animation.action == NONE ? MOVE : c->animation.action; + 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; @@ -5746,6 +5757,7 @@ void init_fadeout_client(Client *c) { fadeout_cient->animation.initial = c->animation.current; fadeout_cient->mon = c->mon; fadeout_cient->animation_type = c->animation_type; + fadeout_cient->animation.action = CLOSE; // 这里snap节点的坐标设置是使用的相对坐标,所以不能加上原来坐标 // 这跟普通node有区别 diff --git a/parse_config.h b/parse_config.h index 20bb9a1..5c76b8f 100644 --- a/parse_config.h +++ b/parse_config.h @@ -79,6 +79,7 @@ typedef struct { double animation_curve_move[4]; double animation_curve_open[4]; double animation_curve_tag[4]; + double animation_curve_close[4]; int scroller_structs; float scroller_default_proportion; @@ -510,6 +511,12 @@ void parse_config_line(Config *config, const char *line) { &config->animation_curve_tag[3]) != 4) { fprintf(stderr, "Error: Invalid animation_curve_tag format: %s\n", value); } + } else if (strcmp(key, "animation_curve_close") == 0) { + if (sscanf(value, "%lf,%lf,%lf,%lf", &config->animation_curve_close[0], + &config->animation_curve_close[1], &config->animation_curve_close[2], + &config->animation_curve_close[3]) != 4) { + fprintf(stderr, "Error: Invalid animation_curve_close format: %s\n", value); + } } else if (strcmp(key, "scroller_structs") == 0) { config->scroller_structs = atoi(value); } else if (strcmp(key, "scroller_default_proportion") == 0) { @@ -1070,6 +1077,8 @@ void override_config(void) { sizeof(animation_curve_open)); memcpy(animation_curve_tag, config.animation_curve_tag, sizeof(animation_curve_tag)); + memcpy(animation_curve_close, config.animation_curve_close, + sizeof(animation_curve_close)); scroller_structs = config.scroller_structs; scroller_default_proportion = config.scroller_default_proportion; @@ -1180,6 +1189,8 @@ void set_value_default() { sizeof(animation_curve_open)); memcpy(config.animation_curve_tag, animation_curve_tag, sizeof(animation_curve_tag)); + memcpy(config.animation_curve_close, animation_curve_close, + sizeof(animation_curve_close)); } void parse_config(void) { diff --git a/preset_config.h b/preset_config.h index b9af003..fde2697 100644 --- a/preset_config.h +++ b/preset_config.h @@ -18,6 +18,7 @@ uint32_t animation_duration_close = 300; // Animation close 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}; // 动画曲线 /* appearance */ unsigned int axis_bind_apply_timeout = 100; // 滚轮绑定动作的触发的时间间隔