opt: use config.xxx instead of global presets

This commit is contained in:
tonybanters 2026-03-12 06:49:58 -07:00 committed by DreamMaoMao
parent b87756d420
commit 73616f07c4
13 changed files with 724 additions and 887 deletions

View file

@ -40,15 +40,16 @@ int32_t is_special_animation_rule(Client *c) {
} else if (c->mon->visible_tiling_clients == 1 && !c->isfloating) {
return DOWN;
} else if (c->mon->visible_tiling_clients == 2 && !c->isfloating &&
!new_is_master && is_horizontal_stack_layout(c->mon)) {
!config.new_is_master && is_horizontal_stack_layout(c->mon)) {
return RIGHT;
} else if (!c->isfloating && new_is_master &&
} else if (!c->isfloating && config.new_is_master &&
is_horizontal_stack_layout(c->mon)) {
return LEFT;
} else if (c->mon->visible_tiling_clients == 2 && !c->isfloating &&
!new_is_master && is_horizontal_right_stack_layout(c->mon)) {
!config.new_is_master &&
is_horizontal_right_stack_layout(c->mon)) {
return LEFT;
} else if (!c->isfloating && new_is_master &&
} else if (!c->isfloating && config.new_is_master &&
is_horizontal_right_stack_layout(c->mon)) {
return RIGHT;
} else {
@ -63,7 +64,8 @@ void set_client_open_animation(Client *c, struct wlr_box geo) {
int32_t special_direction;
int32_t center_x, center_y;
if ((!c->animation_type_open && strcmp(animation_type_open, "fade") == 0) ||
if ((!c->animation_type_open &&
strcmp(config.animation_type_open, "fade") == 0) ||
(c->animation_type_open &&
strcmp(c->animation_type_open, "fade") == 0)) {
c->animainit_geom.width = geo.width;
@ -72,11 +74,11 @@ void set_client_open_animation(Client *c, struct wlr_box geo) {
c->animainit_geom.y = geo.y;
return;
} else if ((!c->animation_type_open &&
strcmp(animation_type_open, "zoom") == 0) ||
strcmp(config.animation_type_open, "zoom") == 0) ||
(c->animation_type_open &&
strcmp(c->animation_type_open, "zoom") == 0)) {
c->animainit_geom.width = geo.width * zoom_initial_ratio;
c->animainit_geom.height = geo.height * zoom_initial_ratio;
c->animainit_geom.width = geo.width * config.zoom_initial_ratio;
c->animainit_geom.height = geo.height * config.zoom_initial_ratio;
c->animainit_geom.x = geo.x + (geo.width - c->animainit_geom.width) / 2;
c->animainit_geom.y =
geo.y + (geo.height - c->animainit_geom.height) / 2;
@ -246,15 +248,15 @@ void apply_shield(Client *c, struct wlr_box clip_box) {
void apply_border(Client *c) {
bool hit_no_border = false;
if (c->iskilling || !client_surface(c)->mapped || c->isnoshadow)
if (c->iskilling || !client_surface(c)->mapped)
return;
hit_no_border = check_hit_no_border(c);
if (hit_no_border && smartgaps) {
if (hit_no_border && config.smartgaps) {
c->bw = 0;
c->fake_no_border = true;
} else if (hit_no_border && !smartgaps) {
} else if (hit_no_border && !config.smartgaps) {
set_rect_size(c->border[0], 0, 0);
set_rect_size(c->border[1], 0, 0);
set_rect_size(c->border[2], 0, 0);
@ -263,7 +265,7 @@ void apply_border(Client *c) {
c->fake_no_border = true;
return;
} else if (!c->isfullscreen && VISIBLEON(c, c->mon)) {
c->bw = c->isnoborder ? 0 : borderpx;
c->bw = c->isnoborder ? 0 : config.borderpx;
c->fake_no_border = false;
}
@ -412,7 +414,7 @@ void client_apply_clip(Client *c, float factor) {
struct ivec2 offset;
BufferData buffer_data;
if (!animations) {
if (!config.animations) {
c->animation.running = false;
c->need_output_flush = false;
c->animainit_geom = c->current = c->pending = c->animation.current =
@ -546,19 +548,19 @@ void fadeout_client_animation_next_tick(Client *c) {
double opacity_eased_progress =
find_animation_curve_at(animation_passed, OPAFADEOUT);
double percent = fadeout_begin_opacity -
(opacity_eased_progress * fadeout_begin_opacity);
double percent = config.fadeout_begin_opacity -
(opacity_eased_progress * config.fadeout_begin_opacity);
double opacity = MAX(percent, 0);
if (animation_fade_out && !c->nofadeout)
if (config.animation_fade_out && !c->nofadeout)
wlr_scene_node_for_each_buffer(&c->scene->node,
scene_buffer_apply_opacity, &opacity);
if ((c->animation_type_close &&
strcmp(c->animation_type_close, "zoom") == 0) ||
(!c->animation_type_close &&
strcmp(animation_type_close, "zoom") == 0)) {
strcmp(config.animation_type_close, "zoom") == 0)) {
buffer_data.width = width;
buffer_data.height = height;
@ -663,14 +665,14 @@ void init_fadeout_client(Client *c) {
if ((c->animation_type_close &&
strcmp(c->animation_type_close, "none") == 0) ||
(!c->animation_type_close &&
strcmp(animation_type_close, "none") == 0)) {
strcmp(config.animation_type_close, "none") == 0)) {
return;
}
Client *fadeout_client = ecalloc(1, sizeof(*fadeout_client));
wlr_scene_node_set_enabled(&c->scene->node, true);
client_set_border_color(c, bordercolor);
client_set_border_color(c, config.bordercolor);
fadeout_client->scene =
wlr_scene_tree_snapshot(&c->scene->node, layers[LyrFadeOut]);
wlr_scene_node_set_enabled(&c->scene->node, false);
@ -680,7 +682,7 @@ void init_fadeout_client(Client *c) {
return;
}
fadeout_client->animation.duration = animation_duration_close;
fadeout_client->animation.duration = config.animation_duration_close;
fadeout_client->geom = fadeout_client->current =
fadeout_client->animainit_geom = fadeout_client->animation.initial =
c->animation.current;
@ -697,7 +699,7 @@ void init_fadeout_client(Client *c) {
fadeout_client->animation.initial.y = 0;
if ((!c->animation_type_close &&
strcmp(animation_type_close, "fade") == 0) ||
strcmp(config.animation_type_close, "fade") == 0) ||
(c->animation_type_close &&
strcmp(c->animation_type_close, "fade") == 0)) {
fadeout_client->current.x = 0;
@ -707,7 +709,7 @@ void init_fadeout_client(Client *c) {
} else if ((c->animation_type_close &&
strcmp(c->animation_type_close, "slide") == 0) ||
(!c->animation_type_close &&
strcmp(animation_type_close, "slide") == 0)) {
strcmp(config.animation_type_close, "slide") == 0)) {
fadeout_client->current.y =
c->geom.y + c->geom.height / 2 > c->mon->m.y + c->mon->m.height / 2
? c->mon->m.height -
@ -717,16 +719,16 @@ void init_fadeout_client(Client *c) {
} else {
fadeout_client->current.y =
(fadeout_client->geom.height -
fadeout_client->geom.height * zoom_end_ratio) /
fadeout_client->geom.height * config.zoom_end_ratio) /
2;
fadeout_client->current.x =
(fadeout_client->geom.width -
fadeout_client->geom.width * zoom_end_ratio) /
fadeout_client->geom.width * config.zoom_end_ratio) /
2;
fadeout_client->current.width =
fadeout_client->geom.width * zoom_end_ratio;
fadeout_client->geom.width * config.zoom_end_ratio;
fadeout_client->current.height =
fadeout_client->geom.height * zoom_end_ratio;
fadeout_client->geom.height * config.zoom_end_ratio;
}
fadeout_client->animation.time_started = get_now_in_ms();
@ -761,12 +763,11 @@ void client_set_pending_state(Client *c) {
if (!c || c->iskilling)
return;
// 判断是否需要动画
if (!animations) {
if (!config.animations) {
c->animation.should_animate = false;
} else if (animations && c->animation.tagining) {
} else if (config.animations && c->animation.tagining) {
c->animation.should_animate = true;
} else if (!animations || c == grabc ||
} else if (!config.animations || c == grabc ||
(!c->is_pending_open_animation &&
wlr_box_equal(&c->current, &c->pending))) {
c->animation.should_animate = false;
@ -777,7 +778,7 @@ void client_set_pending_state(Client *c) {
if (((c->animation_type_open &&
strcmp(c->animation_type_open, "none") == 0) ||
(!c->animation_type_open &&
strcmp(animation_type_open, "none") == 0)) &&
strcmp(config.animation_type_open, "none") == 0)) &&
c->animation.action == OPEN) {
c->animation.duration = 0;
}
@ -846,16 +847,16 @@ void resize(Client *c, struct wlr_box geo, int32_t interact) {
!c->animation.tagouting && wlr_box_equal(&c->geom, &c->current)) {
c->animation.action = c->animation.action;
} else if (c->animation.tagouting) {
c->animation.duration = animation_duration_tag;
c->animation.duration = config.animation_duration_tag;
c->animation.action = TAG;
} else if (c->animation.tagining) {
c->animation.duration = animation_duration_tag;
c->animation.duration = config.animation_duration_tag;
c->animation.action = TAG;
} else if (c->is_pending_open_animation) {
c->animation.duration = animation_duration_open;
c->animation.duration = config.animation_duration_open;
c->animation.action = OPEN;
} else {
c->animation.duration = animation_duration_move;
c->animation.duration = config.animation_duration_move;
c->animation.action = MOVE;
}
@ -876,7 +877,7 @@ void resize(Client *c, struct wlr_box geo, int32_t interact) {
}
bool hit_no_border = check_hit_no_border(c);
if (hit_no_border && smartgaps) {
if (hit_no_border && config.smartgaps) {
c->bw = 0;
c->fake_no_border = true;
}
@ -943,12 +944,12 @@ bool client_draw_fadeout_frame(Client *c) {
void client_set_focused_opacity_animation(Client *c) {
float *border_color = get_border_color(c);
if (!animations) {
if (!config.animations) {
setborder_color(c);
return;
}
c->opacity_animation.duration = animation_duration_focus;
c->opacity_animation.duration = config.animation_duration_focus;
memcpy(c->opacity_animation.target_border_color, border_color,
sizeof(c->opacity_animation.target_border_color));
c->opacity_animation.target_opacity = c->focused_opacity;
@ -962,15 +963,14 @@ void client_set_focused_opacity_animation(Client *c) {
}
void client_set_unfocused_opacity_animation(Client *c) {
// Start border color animation to unfocused
float *border_color = get_border_color(c);
if (!animations) {
if (!config.animations) {
setborder_color(c);
return;
}
c->opacity_animation.duration = animation_duration_focus;
c->opacity_animation.duration = config.animation_duration_focus;
memcpy(c->opacity_animation.target_border_color, border_color,
sizeof(c->opacity_animation.target_border_color));
// Start opacity animation to unfocused
@ -1005,13 +1005,14 @@ bool client_apply_focus_opacity(Client *c) {
double opacity_eased_progress =
find_animation_curve_at(linear_progress, OPAFADEIN);
float percent =
animation_fade_in && !c->nofadein ? opacity_eased_progress : 1.0;
float percent = config.animation_fade_in && !c->nofadein
? opacity_eased_progress
: 1.0;
float opacity =
c == selmon->sel ? c->focused_opacity : c->unfocused_opacity;
float target_opacity =
percent * (1.0 - fadein_begin_opacity) + fadein_begin_opacity;
float target_opacity = percent * (1.0 - config.fadein_begin_opacity) +
config.fadein_begin_opacity;
if (target_opacity > opacity) {
target_opacity = opacity;
}
@ -1021,7 +1022,7 @@ bool client_apply_focus_opacity(Client *c) {
c->opacity_animation.current_opacity = target_opacity;
client_set_opacity(c, target_opacity);
client_set_border_color(c, c->opacity_animation.target_border_color);
} else if (animations && c->opacity_animation.running) {
} else if (config.animations && c->opacity_animation.running) {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
@ -1082,7 +1083,7 @@ bool client_draw_frame(Client *c) {
return client_apply_focus_opacity(c);
}
if (animations && c->animation.running) {
if (config.animations && c->animation.running) {
client_animation_next_tick(c);
} else {
wlr_scene_node_set_position(&c->scene->node, c->pending.x,

View file

@ -2,21 +2,21 @@ struct dvec2 calculate_animation_curve_at(double t, int32_t type) {
struct dvec2 point;
double *animation_curve;
if (type == MOVE) {
animation_curve = animation_curve_move;
animation_curve = config.animation_curve_move;
} else if (type == OPEN) {
animation_curve = animation_curve_open;
animation_curve = config.animation_curve_open;
} else if (type == TAG) {
animation_curve = animation_curve_tag;
animation_curve = config.animation_curve_tag;
} else if (type == CLOSE) {
animation_curve = animation_curve_close;
animation_curve = config.animation_curve_close;
} else if (type == FOCUS) {
animation_curve = animation_curve_focus;
animation_curve = config.animation_curve_focus;
} else if (type == OPAFADEIN) {
animation_curve = animation_curve_opafadein;
animation_curve = config.animation_curve_opafadein;
} else if (type == OPAFADEOUT) {
animation_curve = animation_curve_opafadeout;
animation_curve = config.animation_curve_opafadeout;
} else {
animation_curve = animation_curve_move;
animation_curve = config.animation_curve_move;
}
point.x = 3 * t * (1 - t) * (1 - t) * animation_curve[0] +

View file

@ -212,7 +212,7 @@ void fadeout_layer_animation_next_tick(LayerSurface *l) {
buffer_data.height = height;
if ((!l->animation_type_close &&
strcmp(layer_animation_type_close, "zoom") == 0) ||
strcmp(config.layer_animation_type_close, "zoom") == 0) ||
(l->animation_type_close &&
strcmp(l->animation_type_close, "zoom") == 0)) {
wlr_scene_node_for_each_buffer(&l->scene->node,
@ -230,12 +230,12 @@ void fadeout_layer_animation_next_tick(LayerSurface *l) {
double opacity_eased_progress =
find_animation_curve_at(animation_passed, OPAFADEOUT);
double percent = fadeout_begin_opacity -
(opacity_eased_progress * fadeout_begin_opacity);
double percent = config.fadeout_begin_opacity -
(opacity_eased_progress * config.fadeout_begin_opacity);
double opacity = MAX(percent, 0.0f);
if (animation_fade_out)
if (config.animation_fade_out)
wlr_scene_node_for_each_buffer(&l->scene->node,
scene_buffer_apply_opacity, &opacity);
@ -278,11 +278,11 @@ void layer_animation_next_tick(LayerSurface *l) {
find_animation_curve_at(animation_passed, OPAFADEIN);
double opacity =
MIN(fadein_begin_opacity +
opacity_eased_progress * (1.0 - fadein_begin_opacity),
MIN(config.fadein_begin_opacity +
opacity_eased_progress * (1.0 - config.fadein_begin_opacity),
1.0f);
if (animation_fade_in)
if (config.animation_fade_in)
wlr_scene_node_for_each_buffer(&l->scene->node,
scene_buffer_apply_opacity, &opacity);
@ -298,7 +298,7 @@ void layer_animation_next_tick(LayerSurface *l) {
}
if ((!l->animation_type_open &&
strcmp(layer_animation_type_open, "zoom") == 0) ||
strcmp(config.layer_animation_type_open, "zoom") == 0) ||
(l->animation_type_open &&
strcmp(l->animation_type_open, "zoom") == 0)) {
wlr_scene_node_for_each_buffer(
@ -321,7 +321,7 @@ void layer_animation_next_tick(LayerSurface *l) {
void init_fadeout_layers(LayerSurface *l) {
if (!animations || !layer_animations || l->noanim) {
if (!config.animations || !config.layer_animations || l->noanim) {
return;
}
@ -331,7 +331,7 @@ void init_fadeout_layers(LayerSurface *l) {
if ((l->animation_type_close &&
strcmp(l->animation_type_close, "none") == 0) ||
(!l->animation_type_close &&
strcmp(layer_animation_type_close, "none") == 0)) {
strcmp(config.layer_animation_type_close, "none") == 0)) {
return;
}
@ -354,7 +354,7 @@ void init_fadeout_layers(LayerSurface *l) {
return;
}
fadeout_layer->animation.duration = animation_duration_close;
fadeout_layer->animation.duration = config.animation_duration_close;
fadeout_layer->geom = fadeout_layer->current =
fadeout_layer->animainit_geom = fadeout_layer->animation.initial =
l->animation.current;
@ -370,14 +370,14 @@ void init_fadeout_layers(LayerSurface *l) {
fadeout_layer->animation.initial.y = 0;
if ((!l->animation_type_close &&
strcmp(layer_animation_type_close, "zoom") == 0) ||
strcmp(config.layer_animation_type_close, "zoom") == 0) ||
(l->animation_type_close &&
strcmp(l->animation_type_close, "zoom") == 0)) {
// 算出要设置的绝对坐标和大小
fadeout_layer->current.width =
(float)l->animation.current.width * zoom_end_ratio;
(float)l->animation.current.width * config.zoom_end_ratio;
fadeout_layer->current.height =
(float)l->animation.current.height * zoom_end_ratio;
(float)l->animation.current.height * config.zoom_end_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 -
@ -389,7 +389,7 @@ void init_fadeout_layers(LayerSurface *l) {
fadeout_layer->current.y - l->animation.current.y;
} else if ((!l->animation_type_close &&
strcmp(layer_animation_type_close, "slide") == 0) ||
strcmp(config.layer_animation_type_close, "slide") == 0) ||
(l->animation_type_close &&
strcmp(l->animation_type_close, "slide") == 0)) {
// 获取slide动画的结束绝对坐标和大小
@ -434,17 +434,18 @@ void layer_set_pending_state(LayerSurface *l) {
if (l->animation.action == OPEN && !l->animation.running) {
if ((!l->animation_type_open &&
strcmp(layer_animation_type_open, "zoom") == 0) ||
strcmp(config.layer_animation_type_open, "zoom") == 0) ||
(l->animation_type_open &&
strcmp(l->animation_type_open, "zoom") == 0)) {
l->animainit_geom.width = l->geom.width * zoom_initial_ratio;
l->animainit_geom.height = l->geom.height * zoom_initial_ratio;
l->animainit_geom.width = l->geom.width * config.zoom_initial_ratio;
l->animainit_geom.height =
l->geom.height * config.zoom_initial_ratio;
l->animainit_geom.x = usable_area.x + usable_area.width / 2 -
l->animainit_geom.width / 2;
l->animainit_geom.y = usable_area.y + usable_area.height / 2 -
l->animainit_geom.height / 2;
} else if ((!l->animation_type_open &&
strcmp(layer_animation_type_open, "slide") == 0) ||
strcmp(config.layer_animation_type_open, "slide") == 0) ||
(l->animation_type_open &&
strcmp(l->animation_type_open, "slide") == 0)) {
@ -458,8 +459,7 @@ void layer_set_pending_state(LayerSurface *l) {
} else {
l->animainit_geom = l->animation.current;
}
// 判断是否需要动画
if (!animations || !layer_animations || l->noanim ||
if (!config.animations || !config.layer_animations || l->noanim ||
l->layer_surface->current.layer ==
ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND ||
l->layer_surface->current.layer == ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM) {
@ -471,7 +471,7 @@ void layer_set_pending_state(LayerSurface *l) {
if (((l->animation_type_open &&
strcmp(l->animation_type_open, "none") == 0) ||
(!l->animation_type_open &&
strcmp(layer_animation_type_open, "none") == 0)) &&
strcmp(config.layer_animation_type_open, "none") == 0)) &&
l->animation.action == OPEN) {
l->animation.should_animate = false;
}
@ -518,7 +518,8 @@ bool layer_draw_frame(LayerSurface *l) {
return false;
}
if (animations && layer_animations && l->animation.running && !l->noanim) {
if (config.animations && config.layer_animations && l->animation.running &&
!l->noanim) {
layer_animation_next_tick(l);
} else {
l->need_output_flush = false;

View file

@ -7,11 +7,11 @@ void set_tagin_animation(Monitor *m, Client *c) {
if (m->pertag->curtag > m->pertag->prevtag) {
c->animainit_geom.x = tag_animation_direction == VERTICAL
c->animainit_geom.x = config.tag_animation_direction == VERTICAL
? c->animation.current.x
: MAX(c->mon->m.x + c->mon->m.width,
c->geom.x + c->mon->m.width);
c->animainit_geom.y = tag_animation_direction == VERTICAL
c->animainit_geom.y = config.tag_animation_direction == VERTICAL
? MAX(c->mon->m.y + c->mon->m.height,
c->geom.y + c->mon->m.height)
: c->animation.current.y;
@ -19,11 +19,11 @@ void set_tagin_animation(Monitor *m, Client *c) {
} else {
c->animainit_geom.x =
tag_animation_direction == VERTICAL
config.tag_animation_direction == VERTICAL
? c->animation.current.x
: MIN(m->m.x - c->geom.width, c->geom.x - c->mon->m.width);
c->animainit_geom.y =
tag_animation_direction == VERTICAL
config.tag_animation_direction == VERTICAL
? MIN(m->m.y - c->geom.height, c->geom.y - c->mon->m.height)
: c->animation.current.y;
}
@ -39,7 +39,8 @@ void set_arrange_visible(Monitor *m, Client *c, bool want_animation) {
client_set_suspended(c, false);
if (!c->animation.tag_from_rule && want_animation &&
m->pertag->prevtag != 0 && m->pertag->curtag != 0 && animations) {
m->pertag->prevtag != 0 && m->pertag->curtag != 0 &&
config.animations) {
c->animation.tagining = true;
set_tagin_animation(m, c);
} else {
@ -57,10 +58,10 @@ void set_tagout_animation(Monitor *m, Client *c) {
if (m->pertag->curtag > m->pertag->prevtag) {
c->pending = c->geom;
c->pending.x =
tag_animation_direction == VERTICAL
config.tag_animation_direction == VERTICAL
? c->animation.current.x
: MIN(c->mon->m.x - c->geom.width, c->geom.x - c->mon->m.width);
c->pending.y = tag_animation_direction == VERTICAL
c->pending.y = config.tag_animation_direction == VERTICAL
? MIN(c->mon->m.y - c->geom.height,
c->geom.y - c->mon->m.height)
: c->animation.current.y;
@ -68,11 +69,11 @@ void set_tagout_animation(Monitor *m, Client *c) {
resize(c, c->geom, 0);
} else {
c->pending = c->geom;
c->pending.x = tag_animation_direction == VERTICAL
c->pending.x = config.tag_animation_direction == VERTICAL
? c->animation.current.x
: MAX(c->mon->m.x + c->mon->m.width,
c->geom.x + c->mon->m.width);
c->pending.y = tag_animation_direction == VERTICAL
c->pending.y = config.tag_animation_direction == VERTICAL
? MAX(c->mon->m.y + c->mon->m.height,
c->geom.y + c->mon->m.height)
: c->animation.current.y;
@ -82,7 +83,8 @@ void set_tagout_animation(Monitor *m, Client *c) {
void set_arrange_hidden(Monitor *m, Client *c, bool want_animation) {
if ((c->tags & (1 << (m->pertag->prevtag - 1))) &&
m->pertag->prevtag != 0 && m->pertag->curtag != 0 && animations) {
m->pertag->prevtag != 0 && m->pertag->curtag != 0 &&
config.animations) {
c->animation.tagouting = true;
c->animation.tagining = false;
set_tagout_animation(m, c);