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 1fc89d01eb
commit a7461d9d5b
13 changed files with 826 additions and 997 deletions

View file

@ -10,20 +10,21 @@ void set_rect_size(struct wlr_scene_rect *rect, int32_t width, int32_t height) {
enum corner_location set_client_corner_location(Client *c) {
enum corner_location current_corner_location = CORNER_LOCATION_ALL;
struct wlr_box target_geom = animations ? c->animation.current : c->geom;
if (target_geom.x + border_radius <= c->mon->m.x) {
current_corner_location &= ~CORNER_LOCATION_LEFT; // 清除左标志位
struct wlr_box target_geom =
config.animations ? c->animation.current : c->geom;
if (target_geom.x + config.border_radius <= c->mon->m.x) {
current_corner_location &= ~CORNER_LOCATION_LEFT;
}
if (target_geom.x + target_geom.width - border_radius >=
if (target_geom.x + target_geom.width - config.border_radius >=
c->mon->m.x + c->mon->m.width) {
current_corner_location &= ~CORNER_LOCATION_RIGHT; // 清除右标志位
current_corner_location &= ~CORNER_LOCATION_RIGHT;
}
if (target_geom.y + border_radius <= c->mon->m.y) {
current_corner_location &= ~CORNER_LOCATION_TOP; // 清除上标志位
if (target_geom.y + config.border_radius <= c->mon->m.y) {
current_corner_location &= ~CORNER_LOCATION_TOP;
}
if (target_geom.y + target_geom.height - border_radius >=
if (target_geom.y + target_geom.height - config.border_radius >=
c->mon->m.y + c->mon->m.height) {
current_corner_location &= ~CORNER_LOCATION_BOTTOM; // 清除下标志位
current_corner_location &= ~CORNER_LOCATION_BOTTOM;
}
return current_corner_location;
}
@ -54,15 +55,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 {
@ -77,7 +79,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;
@ -86,11 +89,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;
@ -223,7 +226,7 @@ void scene_buffer_apply_effect(struct wlr_scene_buffer *buffer, int32_t sx,
if (wlr_xdg_popup_try_from_wlr_surface(surface) != NULL)
return;
wlr_scene_buffer_set_corner_radius(buffer, border_radius,
wlr_scene_buffer_set_corner_radius(buffer, config.border_radius,
buffer_data->corner_location);
}
@ -241,7 +244,7 @@ void buffer_set_effect(Client *c, BufferData data) {
data.should_scale = false;
if (c->isnoradius || c->isfullscreen ||
(no_radius_when_single && c->mon &&
(config.no_radius_when_single && c->mon &&
c->mon->visible_tiling_clients == 1)) {
data.corner_location = CORNER_LOCATION_NONE;
}
@ -255,7 +258,7 @@ void client_draw_shadow(Client *c) {
if (c->iskilling || !client_surface(c)->mapped || c->isnoshadow)
return;
if (!shadows || (!c->isfloating && shadow_only_floating)) {
if (!config.shadows || (!c->isfloating && config.shadow_only_floating)) {
if (c->shadow->node.enabled)
wlr_scene_node_set_enabled(&c->shadow->node, false);
return;
@ -266,7 +269,7 @@ void client_draw_shadow(Client *c) {
bool hit_no_border = check_hit_no_border(c);
enum corner_location current_corner_location =
c->isfullscreen || (no_radius_when_single && c->mon &&
c->isfullscreen || (config.no_radius_when_single && c->mon &&
c->mon->visible_tiling_clients == 1)
? CORNER_LOCATION_NONE
: CORNER_LOCATION_ALL;
@ -276,9 +279,8 @@ void client_draw_shadow(Client *c) {
int32_t width, height;
client_actual_size(c, &width, &height);
int32_t delta = shadows_size + (int32_t)c->bw - bwoffset;
int32_t delta = config.shadows_size + (int32_t)c->bw - bwoffset;
/* we calculate where to clip the shadow */
struct wlr_box client_box = {
.x = bwoffset,
.y = bwoffset,
@ -287,22 +289,20 @@ void client_draw_shadow(Client *c) {
};
struct wlr_box shadow_box = {
.x = shadows_position_x + bwoffset,
.y = shadows_position_y + bwoffset,
.x = config.shadows_position_x + bwoffset,
.y = config.shadows_position_y + bwoffset,
.width = width + 2 * delta,
.height = height + 2 * delta,
};
struct wlr_box intersection_box;
wlr_box_intersection(&intersection_box, &client_box, &shadow_box);
/* clipped region takes shadow relative coords, so we translate everything
* by its position */
intersection_box.x -= shadows_position_x + bwoffset;
intersection_box.y -= shadows_position_y + bwoffset;
intersection_box.x -= config.shadows_position_x + bwoffset;
intersection_box.y -= config.shadows_position_y + bwoffset;
struct clipped_region clipped_region = {
.area = intersection_box,
.corner_radius = border_radius,
.corner_radius = config.border_radius,
.corners = current_corner_location,
};
@ -356,23 +356,23 @@ void apply_border(Client *c) {
bool hit_no_border = check_hit_no_border(c);
enum corner_location current_corner_location;
if (c->isfullscreen || (no_radius_when_single && c->mon &&
if (c->isfullscreen || (config.no_radius_when_single && c->mon &&
c->mon->visible_tiling_clients == 1)) {
current_corner_location = CORNER_LOCATION_NONE;
} else {
current_corner_location = set_client_corner_location(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) {
wlr_scene_rect_set_size(c->border, 0, 0);
wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw);
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;
}
@ -434,14 +434,14 @@ void apply_border(Client *c) {
struct clipped_region clipped_region = {
.area = {inner_surface_x, inner_surface_y, inner_surface_width,
inner_surface_height},
.corner_radius = border_radius,
.corner_radius = config.border_radius,
.corners = current_corner_location,
};
wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw);
wlr_scene_rect_set_size(c->border, rect_width, rect_height);
wlr_scene_node_set_position(&c->border->node, rect_x, rect_y);
wlr_scene_rect_set_corner_radius(c->border, border_radius,
wlr_scene_rect_set_corner_radius(c->border, config.border_radius,
current_corner_location);
wlr_scene_rect_set_clipped_region(c->border, clipped_region);
}
@ -523,7 +523,7 @@ void client_apply_clip(Client *c, float factor) {
enum corner_location current_corner_location =
set_client_corner_location(c);
if (!animations) {
if (!config.animations) {
c->animation.running = false;
c->need_output_flush = false;
c->animainit_geom = c->current = c->pending = c->animation.current =
@ -655,19 +655,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;
@ -768,14 +768,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);
@ -785,7 +785,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;
@ -802,7 +802,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;
@ -812,7 +812,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 -
@ -822,16 +822,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();
@ -866,12 +866,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;
@ -882,7 +881,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;
}
@ -951,16 +950,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;
}
@ -981,7 +980,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;
}
@ -1048,12 +1047,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;
@ -1067,15 +1066,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
@ -1110,13 +1108,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;
}
@ -1126,7 +1125,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);
@ -1187,7 +1186,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,