feat: Distinguish between closed and open animation types

This commit is contained in:
DreamMaoMao 2025-03-11 14:12:11 +08:00
parent c2a6914662
commit 20bd9841ae
5 changed files with 44 additions and 26 deletions

View file

@ -41,7 +41,8 @@ See below for more features.
- isfloating: type-num(0 or 1)
- isfullscreen: type-num(0 or 1)
- scroller_proportion: type-float(0.1-1.0)
- animation_type : type-string(zoom,slide)
- animation_type_open : type-string(zoom,slide)
- animation_type_close : type-string(zoom,slide)
- isnoborder : type-num(0 or 1)
- monitor : type-num(0-99999)
- width : type-num(0-9999)

View file

@ -1,6 +1,7 @@
# Animation Configuration
animations=1
animation_type=slide
animation_type_open=zoom
animation_type_close=slide
animation_fade_in=1
zoom_initial_ratio=0.5
fadein_begin_opacity=0.5
@ -94,7 +95,8 @@ tags=id:9,layout_name:tile
# isfloating: type-num(0 or 1)
# isfullscreen: type-num(0 or 1)
# scroller_proportion: type-float(0.1-1.0)
# animation_type : type-string(zoom,slide)
# animation_type_open : type-string(zoom,slide)
# animation_type_close : type-string(zoom,slide)
# isnoborder : type-num(0 or 1)
# monitor : type-int(0-99999)
# width : type-num(0-9999)
@ -110,7 +112,7 @@ tags=id:9,layout_name:tile
# windowrule=isfloating:1,appid:Rofi
# windowrule=isfloating:1,appid:wofi
# windowrule=isnoborder:1,appid:wofi
# windowrule=animation_type:zoom,appid:wofi
# windowrule=animation_type_open:zoom,appid:wofi
# open in specific tag
# windowrule=tags:4,appid:Google-chrome

View file

@ -227,7 +227,8 @@ struct Client {
struct wl_listener destroy_decoration;
unsigned int ignore_clear_fullscreen;
const char *animation_type;
const char *animation_type_open;
const char *animation_type_close;
int is_in_scratchpad;
int is_scratchpad_show;
int isglobal;
@ -352,7 +353,8 @@ typedef struct {
int isfloating;
int isfullscreen;
float scroller_proportion;
const char *animation_type;
const char *animation_type_open;
const char *animation_type_close;
int isnoborder;
int monitor;
unsigned int width;
@ -855,8 +857,8 @@ void fadeout_client_animation_next_tick(Client *c) {
apply_opacity_to_rect_nodes(c, &c->scene->node, animation_passed);
if ((c->animation_type && strcmp(c->animation_type, "zoom") == 0) ||
(!c->animation_type && strcmp(animation_type, "zoom") == 0)) {
if ((c->animation_type_close && strcmp(c->animation_type_close, "zoom") == 0) ||
(!c->animation_type_close && strcmp(animation_type_close, "zoom") == 0)) {
scale_data.width = width;
scale_data.height = height;
@ -1439,8 +1441,10 @@ applyrules(Client *c) {
c->isterm = r->isterm > 0 ? r->isterm : c->isterm;
c->noswallow = r->noswallow > 0? r->noswallow : c->noswallow;
c->isfloating = r->isfloating > 0 ? r->isfloating : c->isfloating;
c->animation_type =
r->animation_type == NULL ? c->animation_type : r->animation_type;
c->animation_type_open =
r->animation_type_open == NULL ? c->animation_type_open : r->animation_type_open;
c->animation_type_close =
r->animation_type_close == NULL ? c->animation_type_close : r->animation_type_close;
c->scroller_proportion = r->scroller_proportion > 0
? r->scroller_proportion
: scroller_default_proportion;
@ -4197,8 +4201,8 @@ void set_open_animaiton(Client *c, struct wlr_box geo) {
int vertical, vertical_value;
int special_direction;
int center_x, center_y;
if (strcmp(animation_type, "zoom") == 0 ||
(c->animation_type && strcmp(c->animation_type, "zoom") == 0)) {
if (strcmp(animation_type_open, "zoom") == 0 ||
(c->animation_type_open && strcmp(c->animation_type_open, "zoom") == 0)) {
c->animainit_geom.width = c->geom.width * zoom_initial_ratio;
c->animainit_geom.height = c->geom.height * zoom_initial_ratio;
c->animainit_geom.x = c->geom.x + (c->geom.width - c->animainit_geom.width) / 2;
@ -5861,7 +5865,7 @@ void init_fadeout_client(Client *c) {
fadeout_cient->geom = fadeout_cient->current = fadeout_cient->animainit_geom =
fadeout_cient->animation.initial = c->animation.current;
fadeout_cient->mon = c->mon;
fadeout_cient->animation_type = c->animation_type;
fadeout_cient->animation_type_close = c->animation_type_close;
fadeout_cient->animation.action = CLOSE;
fadeout_cient->bw = c->bw;
@ -5870,8 +5874,8 @@ void init_fadeout_client(Client *c) {
fadeout_cient->animation.initial.x = 0;
fadeout_cient->animation.initial.y = 0;
if ((c->animation_type && strcmp(c->animation_type, "slide") == 0) ||
(!c->animation_type && strcmp(animation_type, "slide") == 0)) {
if ((c->animation_type_close && strcmp(c->animation_type_close, "slide") == 0) ||
(!c->animation_type_close && strcmp(animation_type_close, "slide") == 0)) {
fadeout_cient->current.y =
c->geom.y + c->geom.height / 2 > c->mon->m.y + c->mon->m.height / 2
? c->mon->m.height -

View file

@ -14,7 +14,8 @@ typedef struct {
int isfloating;
int isfullscreen;
float scroller_proportion;
const char *animation_type;
const char *animation_type_open;
const char *animation_type_close;
int isnoborder;
int monitor;
int width;
@ -71,7 +72,8 @@ typedef struct {
typedef struct {
int animations;
char animation_type[10];
char animation_type_open[10];
char animation_type_close[10];
char animation_fade_in;
float zoom_initial_ratio;
float fadein_begin_opacity;
@ -481,8 +483,10 @@ void parse_config_line(Config *config, const char *line) {
if (strcmp(key, "animations") == 0) {
config->animations = atoi(value);
} else if (strcmp(key, "animation_type") == 0) {
strncpy(config->animation_type, value, sizeof(config->animation_type));
} else if (strcmp(key, "animation_type_open") == 0) {
strncpy(config->animation_type_open, value, sizeof(config->animation_type_open));
} else if (strcmp(key, "animation_type_close") == 0) {
strncpy(config->animation_type_close, value, sizeof(config->animation_type_close));
} else if (strcmp(key, "animation_fade_in") == 0) {
config->animation_fade_in = atoi(value);
} else if (strcmp(key, "zoom_initial_ratio") == 0) {
@ -792,7 +796,8 @@ void parse_config_line(Config *config, const char *line) {
rule->monitor = -1;
rule->width = -1;
rule->height = -1;
rule->animation_type = NULL;
rule->animation_type_open = NULL;
rule->animation_type_close = NULL;
rule->scroller_proportion = -1;
rule->id = NULL;
rule->title = NULL;
@ -812,8 +817,10 @@ void parse_config_line(Config *config, const char *line) {
rule->title = strdup(val);
} else if (strcmp(key, "appid") == 0) {
rule->id = strdup(val);
} else if (strcmp(key, "animation_type") == 0) {
rule->animation_type = strdup(val);
} else if (strcmp(key, "animation_type_open") == 0) {
rule->animation_type_open = strdup(val);
} else if (strcmp(key, "animation_type_close") == 0) {
rule->animation_type_close = strdup(val);
} else if (strcmp(key, "tags") == 0) {
rule->tags = 1 << (atoi(val) - 1);
} else if (strcmp(key, "monitor") == 0) {
@ -1029,8 +1036,10 @@ void free_config(void) {
free((void *)rule->id);
if (rule->title)
free((void *)rule->title);
if (rule->animation_type)
free((void *)rule->animation_type);
if (rule->animation_type_open)
free((void *)rule->animation_type_open);
if (rule->animation_type_close)
free((void *)rule->animation_type_close);
}
free(config.window_rules);
@ -1076,7 +1085,8 @@ void free_config(void) {
void override_config(void) {
animations = config.animations;
animation_type = config.animation_type;
animation_type_open = config.animation_type_open;
animation_type_close = config.animation_type_close;
animation_fade_in = config.animation_fade_in;
zoom_initial_ratio = config.zoom_initial_ratio;
fadein_begin_opacity = config.fadein_begin_opacity;

View file

@ -5,7 +5,8 @@
((hex >> 8) & 0xFF) / 255.0f, (hex & 0xFF) / 255.0f}
/* animaion */
char *animation_type = "slide"; // 是否启用动画 //slide,zoom
char *animation_type_open = "slide"; // 是否启用动画 //slide,zoom
char *animation_type_close = "slide"; // 是否启用动画 //slide,zoom
int animations = 1; // 是否启用动画
char animation_fade_in = 1; // Enable animation fade in
float zoom_initial_ratio = 0.5; // 动画起始窗口比例