From 0161e35840d234f8bf4936071e9c5a3d02a3f9af Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sat, 26 Apr 2025 22:28:01 +0800 Subject: [PATCH] feat:Support vertical tag switching animation --- config.conf | 2 ++ src/maomao.c | 39 +++++++++++++++++++++++++++++++-------- src/parse_config.h | 5 +++++ src/preset_config.h | 1 + 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/config.conf b/config.conf index c2354e7..4ea7604 100644 --- a/config.conf +++ b/config.conf @@ -1,8 +1,10 @@ # Animation Configuration(support type:zoom,slide) +# tag_animation_direction: 0-horizontal,1-vertical animations=1 animation_type_open=slide animation_type_close=slide animation_fade_in=1 +tag_animation_direction=1 zoom_initial_ratio=0.5 fadein_begin_opacity=0.5 fadeout_begin_opacity=0.8 diff --git a/src/maomao.c b/src/maomao.c index 9094059..7268fa6 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -109,6 +109,7 @@ #define BAKED_POINTS_COUNT 256 /* enums */ +enum { VERTICAL, HORIZONTAL}; enum { SWIPE_UP, SWIPE_DOWN, SWIPE_LEFT, SWIPE_RIGHT }; enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */ enum { XDGShell, LayerShell, X11 }; /* client types */ @@ -1694,19 +1695,31 @@ arrange(Monitor *m, bool want_animation) { wlr_scene_node_set_enabled(&c->scene->node, true); } client_set_suspended(c, false); - if (!c->animation.from_rule && want_animation && - m->pertag->prevtag != 0 && m->pertag->curtag != 0 && animations) { + if (!c->animation.from_rule && + want_animation && + m->pertag->prevtag != 0 && + m->pertag->curtag != 0 && + animations && !c->animation.running) { c->animation.tagining = true; if (m->pertag->curtag > m->pertag->prevtag) { - c->animainit_geom.x = c->animation.running + c->animainit_geom.x = tag_animation_direction == VERTICAL ? c->animation.current.x : c->mon->m.x + c->mon->m.width; + c->animainit_geom.y = tag_animation_direction == VERTICAL + ? c->mon->m.y + c->mon->m.height + : c->animation.current.y; + } else { - c->animainit_geom.x = c->animation.running ? c->animation.current.x - : m->m.x - c->geom.width; + c->animainit_geom.x = tag_animation_direction == VERTICAL + ? c->animation.current.x + : m->m.x - c->geom.width; + c->animainit_geom.y = tag_animation_direction == VERTICAL + ? m->m.y - c->geom.height + : c->animation.current.y; } } else { c->animainit_geom.x = c->animation.current.x; + c->animainit_geom.y = c->animation.current.y; } c->animation.from_rule = false; @@ -1722,11 +1735,22 @@ arrange(Monitor *m, bool want_animation) { c->animation.tagining = false; if (m->pertag->curtag > m->pertag->prevtag) { c->pending = c->geom; - c->pending.x = c->mon->m.x - c->geom.width; + c->pending.x = tag_animation_direction == VERTICAL + ? c->animation.current.x + : c->mon->m.x - c->geom.width; + c->pending.y = tag_animation_direction == VERTICAL + ? c->mon->m.y - c->geom.height + : c->animation.current.y; + resize(c, c->geom, 0); } else { c->pending = c->geom; - c->pending.x = c->mon->m.x + c->mon->m.width; + c->pending.x = tag_animation_direction == VERTICAL + ? c->animation.current.x + : c->mon->m.x + c->mon->m.width; + c->pending.y = tag_animation_direction == VERTICAL + ? c->mon->m.y + c->mon->m.height + : c->animation.current.y; resize(c, c->geom, 0); } } else { @@ -4861,7 +4885,6 @@ void resize(Client *c, struct wlr_box geo, int interact) { } else if (c->animation.tagining) { c->animainit_geom.height = c->animation.current.height; c->animainit_geom.width = c->animation.current.width; - c->animainit_geom.y = c->animation.current.y; } else if (c->is_open_animation) { set_open_animaiton(c, c->geom); } else { diff --git a/src/parse_config.h b/src/parse_config.h index 939fa5a..85cbd88 100644 --- a/src/parse_config.h +++ b/src/parse_config.h @@ -88,6 +88,7 @@ typedef struct { char animation_type_open[10]; char animation_type_close[10]; char animation_fade_in; + int tag_animation_direction; float zoom_initial_ratio; float fadein_begin_opacity; float fadeout_begin_opacity; @@ -528,6 +529,8 @@ void parse_config_line(Config *config, const char *line) { snprintf(config->animation_type_close, sizeof(config->animation_type_close), "%.9s", value); // string limit to 9 char } else if (strcmp(key, "animation_fade_in") == 0) { config->animation_fade_in = atoi(value); + } else if (strcmp(key, "tag_animation_direction") == 0) { + config->tag_animation_direction = atoi(value); } else if (strcmp(key, "zoom_initial_ratio") == 0) { config->zoom_initial_ratio = atof(value); } else if (strcmp(key, "fadein_begin_opacity") == 0) { @@ -1171,6 +1174,7 @@ void override_config(void) { animation_type_open = config.animation_type_open; animation_type_close = config.animation_type_close; animation_fade_in = config.animation_fade_in; + tag_animation_direction = config.tag_animation_direction; zoom_initial_ratio = config.zoom_initial_ratio; fadein_begin_opacity = config.fadein_begin_opacity; fadeout_begin_opacity = config.fadeout_begin_opacity; @@ -1245,6 +1249,7 @@ void set_value_default() { /* animaion */ config.animations = animations; // 是否启用动画 config.animation_fade_in = animation_fade_in; // Enable animation fade in + config.tag_animation_direction = tag_animation_direction; // 标签动画方向 config.zoom_initial_ratio = zoom_initial_ratio; // 动画起始窗口比例 config.fadein_begin_opacity = fadein_begin_opacity; // Begin opac window ratio for animations config.fadeout_begin_opacity = fadeout_begin_opacity; diff --git a/src/preset_config.h b/src/preset_config.h index d0d6f8a..752719c 100644 --- a/src/preset_config.h +++ b/src/preset_config.h @@ -8,6 +8,7 @@ char *animation_type_open = "slide"; // 是否启用动画 //slide,zoom char *animation_type_close = "slide"; // 是否启用动画 //slide,zoom int animations = 1; // 是否启用动画 +int tag_animation_direction = HORIZONTAL; // 标签动画方向 char animation_fade_in = 1; // Enable animation fade in float zoom_initial_ratio = 0.5; // 动画起始窗口比例 float fadein_begin_opacity = 0.5; // Begin opac window ratio for animations