opt: optimize code struct

This commit is contained in:
DreamMaoMao
2026-01-01 12:26:19 +08:00
parent ec6d54148d
commit 89e0805d54
6 changed files with 59 additions and 70 deletions

View File

@@ -3347,7 +3347,7 @@ void reset_option(void) {
reapply_tagrule(); reapply_tagrule();
reapply_monitor_rules(); reapply_monitor_rules();
arrange(selmon, false); arrange(selmon, false, false);
} }
int reload_config(const Arg *arg) { int reload_config(const Arg *arg) {

View File

@@ -244,7 +244,7 @@ int incnmaster(const Arg *arg) {
return 0; return 0;
selmon->pertag->nmasters[selmon->pertag->curtag] = selmon->pertag->nmasters[selmon->pertag->curtag] =
MAX(selmon->pertag->nmasters[selmon->pertag->curtag] + arg->i, 0); MAX(selmon->pertag->nmasters[selmon->pertag->curtag] + arg->i, 0);
arrange(selmon, false); arrange(selmon, false, false);
return 0; return 0;
} }
@@ -308,7 +308,7 @@ int setmfact(const Arg *arg) {
c->master_mfact_per = f; c->master_mfact_per = f;
} }
} }
arrange(selmon, false); arrange(selmon, false, false);
return 0; return 0;
} }
@@ -491,7 +491,7 @@ int restore_minimized(const Arg *arg) {
c->isnamedscratchpad = 0; c->isnamedscratchpad = 0;
show_hide_client(c); show_hide_client(c);
setborder_color(c); setborder_color(c);
arrange(c->mon, false); arrange(c->mon, false, false);
focusclient(c, 0); focusclient(c, 0);
warp_cursor(c); warp_cursor(c);
return 0; return 0;
@@ -507,7 +507,7 @@ int setlayout(const Arg *arg) {
if (strcmp(layouts[jk].name, arg->v) == 0) { if (strcmp(layouts[jk].name, arg->v) == 0) {
selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[jk]; selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[jk];
clear_fullscreen_and_maximized_state(selmon); clear_fullscreen_and_maximized_state(selmon);
arrange(selmon, false); arrange(selmon, false, false);
printstatus(); printstatus();
return 0; return 0;
} }
@@ -541,7 +541,7 @@ int set_proportion(const Arg *arg) {
selmon->sel->scroller_proportion = arg->f; selmon->sel->scroller_proportion = arg->f;
selmon->sel->geom.width = max_client_width * arg->f; selmon->sel->geom.width = max_client_width * arg->f;
// resize(selmon->sel, selmon->sel->geom, 0); // resize(selmon->sel, selmon->sel->geom, 0);
arrange(selmon, false); arrange(selmon, false, false);
} }
return 0; return 0;
} }
@@ -740,7 +740,7 @@ int centerwin(const Arg *arg) {
c->geom.y = selmon->w.y + (selmon->w.height - c->geom.height) / 2; c->geom.y = selmon->w.y + (selmon->w.height - c->geom.height) / 2;
} }
arrange(selmon, false); arrange(selmon, false, false);
return 0; return 0;
} }
@@ -923,7 +923,7 @@ int switch_layout(const Arg *arg) {
} }
} }
clear_fullscreen_and_maximized_state(selmon); clear_fullscreen_and_maximized_state(selmon);
arrange(selmon, false); arrange(selmon, false, false);
printstatus(); printstatus();
return 0; return 0;
} }
@@ -934,7 +934,7 @@ int switch_layout(const Arg *arg) {
selmon->pertag->ltidxs[selmon->pertag->curtag] = selmon->pertag->ltidxs[selmon->pertag->curtag] =
jk == LENGTH(layouts) - 1 ? &layouts[0] : &layouts[jk + 1]; jk == LENGTH(layouts) - 1 ? &layouts[0] : &layouts[jk + 1];
clear_fullscreen_and_maximized_state(selmon); clear_fullscreen_and_maximized_state(selmon);
arrange(selmon, false); arrange(selmon, false, false);
printstatus(); printstatus();
return 0; return 0;
} }
@@ -981,7 +981,7 @@ int switch_proportion_preset(const Arg *arg) {
selmon->sel->scroller_proportion = target_proportion; selmon->sel->scroller_proportion = target_proportion;
selmon->sel->geom.width = max_client_width * target_proportion; selmon->sel->geom.width = max_client_width * target_proportion;
// resize(selmon->sel, selmon->sel->geom, 0); // resize(selmon->sel, selmon->sel->geom, 0);
arrange(selmon, false); arrange(selmon, false, false);
} }
return 0; return 0;
} }
@@ -1055,7 +1055,7 @@ int tagmon(const Arg *arg) {
target = get_tags_first_tag(c->tags); target = get_tags_first_tag(c->tags);
view(&(Arg){.ui = target}, true); view(&(Arg){.ui = target}, true);
focusclient(c, 1); focusclient(c, 1);
arrange(selmon, false); arrange(selmon, false, false);
} }
if (warpcursor) { if (warpcursor) {
warp_cursor_to_selmon(c->mon); warp_cursor_to_selmon(c->mon);
@@ -1079,7 +1079,7 @@ int tagsilent(const Arg *arg) {
} }
} }
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(target_client->mon, false); arrange(target_client->mon, false, false);
return 0; return 0;
} }
@@ -1122,7 +1122,7 @@ int toggle_named_scratchpad(const Arg *arg) {
int toggle_render_border(const Arg *arg) { int toggle_render_border(const Arg *arg) {
render_border = !render_border; render_border = !render_border;
arrange(selmon, false); arrange(selmon, false, false);
return 0; return 0;
} }
@@ -1215,7 +1215,7 @@ int toggleglobal(const Arg *arg) {
int togglegaps(const Arg *arg) { int togglegaps(const Arg *arg) {
enablegaps ^= 1; enablegaps ^= 1;
arrange(selmon, false); arrange(selmon, false, false);
return 0; return 0;
} }
@@ -1275,7 +1275,7 @@ int toggletag(const Arg *arg) {
if (newtags) { if (newtags) {
sel->tags = newtags; sel->tags = newtags;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(selmon, false); arrange(selmon, false, false);
} }
printstatus(); printstatus();
return 0; return 0;
@@ -1293,7 +1293,7 @@ int toggleview(const Arg *arg) {
if (newtagset) { if (newtagset) {
selmon->tagset[selmon->seltags] = newtagset; selmon->tagset[selmon->seltags] = newtagset;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(selmon, false); arrange(selmon, false, false);
} }
printstatus(); printstatus();
return 0; return 0;
@@ -1407,7 +1407,7 @@ int comboview(const Arg *arg) {
if (tag_combo) { if (tag_combo) {
selmon->tagset[selmon->seltags] |= newtags; selmon->tagset[selmon->seltags] |= newtags;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(selmon, false); arrange(selmon, false, false);
} else { } else {
tag_combo = true; tag_combo = true;
view(&(Arg){.ui = newtags}, false); view(&(Arg){.ui = newtags}, false);
@@ -1446,7 +1446,7 @@ int zoom(const Arg *arg) {
wl_list_insert(&clients, &sel->link); wl_list_insert(&clients, &sel->link);
focusclient(sel, 1); focusclient(sel, 1);
arrange(selmon, false); arrange(selmon, false, false);
return 0; return 0;
} }

View File

@@ -238,7 +238,7 @@ void dwl_ipc_output_set_client_tags(struct wl_client *client,
selected_client->tags = newtags; selected_client->tags = newtags;
if (selmon == monitor) if (selmon == monitor)
focusclient(focustop(monitor), 1); focusclient(focustop(monitor), 1);
arrange(selmon, false); arrange(selmon, false, false);
printstatus(); printstatus();
} }
@@ -257,7 +257,7 @@ void dwl_ipc_output_set_layout(struct wl_client *client,
monitor->pertag->ltidxs[monitor->pertag->curtag] = &layouts[index]; monitor->pertag->ltidxs[monitor->pertag->curtag] = &layouts[index];
clear_fullscreen_and_maximized_state(monitor); clear_fullscreen_and_maximized_state(monitor);
arrange(monitor, false); arrange(monitor, false, false);
printstatus(); printstatus();
} }

View File

@@ -15,7 +15,7 @@ void handle_foreign_activate_request(struct wl_listener *listener, void *data) {
c->is_scratchpad_show = 0; c->is_scratchpad_show = 0;
setborder_color(c); setborder_color(c);
show_hide_client(c); show_hide_client(c);
arrange(c->mon, true); arrange(c->mon, true, false);
return; return;
} }
@@ -60,7 +60,7 @@ void handle_foreign_minimize_request(struct wl_listener *listener, void *data) {
c->is_scratchpad_show = 0; c->is_scratchpad_show = 0;
setborder_color(c); setborder_color(c);
show_hide_client(c); show_hide_client(c);
arrange(c->mon, true); arrange(c->mon, true, false);
return; return;
} }
} }

View File

@@ -200,13 +200,13 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int offsetx,
grabc->stack_inner_per = new_stack_inner_per; grabc->stack_inner_per = new_stack_inner_per;
if (!isdrag) { if (!isdrag) {
arrange(grabc->mon, false); arrange(grabc->mon, false, false);
return; return;
} }
if (last_apply_drap_time == 0 || if (last_apply_drap_time == 0 ||
time - last_apply_drap_time > drag_refresh_interval) { time - last_apply_drap_time > drag_refresh_interval) {
arrange(grabc->mon, false); arrange(grabc->mon, false, false);
last_apply_drap_time = time; last_apply_drap_time = time;
} }
} }
@@ -357,13 +357,13 @@ void resize_tile_master_vertical(Client *grabc, bool isdrag, int offsetx,
grabc->stack_inner_per = new_stack_inner_per; grabc->stack_inner_per = new_stack_inner_per;
if (!isdrag) { if (!isdrag) {
arrange(grabc->mon, false); arrange(grabc->mon, false, false);
return; return;
} }
if (last_apply_drap_time == 0 || if (last_apply_drap_time == 0 ||
time - last_apply_drap_time > drag_refresh_interval) { time - last_apply_drap_time > drag_refresh_interval) {
arrange(grabc->mon, false); arrange(grabc->mon, false, false);
last_apply_drap_time = time; last_apply_drap_time = time;
} }
} }
@@ -461,13 +461,13 @@ void resize_tile_scroller(Client *grabc, bool isdrag, int offsetx, int offsety,
grabc->scroller_proportion = new_scroller_proportion; grabc->scroller_proportion = new_scroller_proportion;
if (!isdrag) { if (!isdrag) {
arrange(grabc->mon, false); arrange(grabc->mon, false, false);
return; return;
} }
if (last_apply_drap_time == 0 || if (last_apply_drap_time == 0 ||
time - last_apply_drap_time > drag_refresh_interval) { time - last_apply_drap_time > drag_refresh_interval) {
arrange(grabc->mon, false); arrange(grabc->mon, false, false);
last_apply_drap_time = time; last_apply_drap_time = time;
} }
} }
@@ -576,25 +576,8 @@ void reset_size_per_mon(Monitor *m, int tile_cilent_num,
} }
} }
void reset_multi_tag_client_per(Monitor *m) {
Client *c = NULL;
wl_list_for_each(c, &clients, link) {
if (c->isglobal || c->isunglobal) {
set_size_per(m, c);
}
if (!VISIBLEON(c, m))
continue;
if (!client_only_in_one_tag(c)) {
set_size_per(m, c);
}
}
}
void // 17 void // 17
arrange(Monitor *m, bool want_animation) { arrange(Monitor *m, bool want_animation, bool from_view) {
Client *c = NULL; Client *c = NULL;
double total_stack_inner_percent = 0; double total_stack_inner_percent = 0;
double total_master_inner_percent = 0; double total_master_inner_percent = 0;
@@ -617,6 +600,10 @@ arrange(Monitor *m, bool want_animation) {
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link) {
if (from_view && (c->isglobal || c->isunglobal)) {
set_size_per(m, c);
}
if (c->mon == m && (c->isglobal || c->isunglobal)) { if (c->mon == m && (c->isglobal || c->isunglobal)) {
c->tags = m->tagset[m->seltags]; c->tags = m->tagset[m->seltags];
if (c->mon->sel == NULL) if (c->mon->sel == NULL)
@@ -624,6 +611,10 @@ arrange(Monitor *m, bool want_animation) {
} }
if (VISIBLEON(c, m)) { if (VISIBLEON(c, m)) {
if (from_view && !client_only_in_one_tag(c)) {
set_size_per(m, c);
}
if (!c->isunglobal) if (!c->isunglobal)
m->visible_clients++; m->visible_clients++;

View File

@@ -534,9 +534,8 @@ static void applybounds(
Client *c, Client *c,
struct wlr_box *bbox); // 设置边界规则,能让一些窗口拥有比较适合的大小 struct wlr_box *bbox); // 设置边界规则,能让一些窗口拥有比较适合的大小
static void applyrules(Client *c); // 窗口规则应用,应用config.h中定义的窗口规则 static void applyrules(Client *c); // 窗口规则应用,应用config.h中定义的窗口规则
static void static void arrange(Monitor *m, bool want_animation,
arrange(Monitor *m, bool from_view); // 布局函数,让窗口俺平铺规则移动和重置大小
bool want_animation); // 布局函数,让窗口俺平铺规则移动和重置大小
static void arrangelayer(Monitor *m, struct wl_list *list, static void arrangelayer(Monitor *m, struct wl_list *list,
struct wlr_box *usable_area, int exclusive); struct wlr_box *usable_area, int exclusive);
static void arrangelayers(Monitor *m); static void arrangelayers(Monitor *m);
@@ -1093,7 +1092,7 @@ bool switch_scratchpad_client_state(Client *c) {
if (c->is_scratchpad_show) { if (c->is_scratchpad_show) {
c->tags = get_tags_first_tag(selmon->tagset[selmon->seltags]); c->tags = get_tags_first_tag(selmon->tagset[selmon->seltags]);
resize(c, c->float_geom, 0); resize(c, c->float_geom, 0);
arrange(selmon, false); arrange(selmon, false, false);
focusclient(c, true); focusclient(c, true);
c->scratchpad_switching_mon = false; c->scratchpad_switching_mon = false;
return true; return true;
@@ -1106,7 +1105,7 @@ bool switch_scratchpad_client_state(Client *c) {
if (c->is_in_scratchpad && c->is_scratchpad_show && if (c->is_in_scratchpad && c->is_scratchpad_show &&
(c->mon->tagset[c->mon->seltags] & c->tags) == 0) { (c->mon->tagset[c->mon->seltags] & c->tags) == 0) {
c->tags = c->mon->tagset[c->mon->seltags]; c->tags = c->mon->tagset[c->mon->seltags];
arrange(c->mon, false); arrange(c->mon, false, false);
focusclient(c, true); focusclient(c, true);
return true; return true;
} else if (c->is_in_scratchpad && c->is_scratchpad_show && } else if (c->is_in_scratchpad && c->is_scratchpad_show &&
@@ -1415,7 +1414,7 @@ void applyrules(Client *c) {
VISIBLEON(fc, c->mon) && ISFULLSCREEN(fc) && VISIBLEON(fc, c->mon) && ISFULLSCREEN(fc) &&
!c->isfloating) { !c->isfloating) {
clear_fullscreen_flag(fc); clear_fullscreen_flag(fc);
arrange(c->mon, false); arrange(c->mon, false, false);
} }
if (c->isfloating && !hit_rule_pos && !c->isnamedscratchpad) { if (c->isfloating && !hit_rule_pos && !c->isnamedscratchpad) {
@@ -1614,7 +1613,7 @@ void arrangelayers(Monitor *m) {
if (!wlr_box_equal(&usable_area, &m->w)) { if (!wlr_box_equal(&usable_area, &m->w)) {
m->w = usable_area; m->w = usable_area;
arrange(m, false); arrange(m, false, false);
} }
/* Arrange non-exlusive surfaces from top->bottom */ /* Arrange non-exlusive surfaces from top->bottom */
@@ -3217,7 +3216,7 @@ void focusclient(Client *c, int lift) {
(selmon->prevsel->tags & selmon->tagset[selmon->seltags]) && (selmon->prevsel->tags & selmon->tagset[selmon->seltags]) &&
(c->tags & selmon->tagset[selmon->seltags]) && !c->isfloating && (c->tags & selmon->tagset[selmon->seltags]) && !c->isfloating &&
is_scroller_layout(selmon)) { is_scroller_layout(selmon)) {
arrange(selmon, false); arrange(selmon, false, false);
} }
// change focus link position // change focus link position
@@ -3886,7 +3885,7 @@ void unminimize(Client *c) {
c->is_in_scratchpad = 0; c->is_in_scratchpad = 0;
c->isnamedscratchpad = 0; c->isnamedscratchpad = 0;
setborder_color(c); setborder_color(c);
arrange(c->mon, false); arrange(c->mon, false, false);
return; return;
} }
} }
@@ -3904,7 +3903,7 @@ void set_minimized(Client *c) {
c->is_in_scratchpad = 1; c->is_in_scratchpad = 1;
c->is_scratchpad_show = 0; c->is_scratchpad_show = 0;
focusclient(focustop(selmon), 1); focusclient(focustop(selmon), 1);
arrange(c->mon, false); arrange(c->mon, false, false);
wlr_foreign_toplevel_handle_v1_set_activated(c->foreign_toplevel, false); wlr_foreign_toplevel_handle_v1_set_activated(c->foreign_toplevel, false);
wlr_foreign_toplevel_handle_v1_set_minimized(c->foreign_toplevel, true); wlr_foreign_toplevel_handle_v1_set_minimized(c->foreign_toplevel, true);
wl_list_remove(&c->link); // 从原来位置移除 wl_list_remove(&c->link); // 从原来位置移除
@@ -4405,11 +4404,11 @@ void exchange_two_client(Client *c1, Client *c2) {
tmp_tags = c2->tags; tmp_tags = c2->tags;
setmon(c2, c1->mon, c1->tags, false); setmon(c2, c1->mon, c1->tags, false);
setmon(c1, tmp_mon, tmp_tags, false); setmon(c1, tmp_mon, tmp_tags, false);
arrange(c1->mon, false); arrange(c1->mon, false, false);
arrange(c2->mon, false); arrange(c2->mon, false, false);
focusclient(c1, 0); focusclient(c1, 0);
} else { } else {
arrange(c1->mon, false); arrange(c1->mon, false, false);
focusclient(c1, 0); focusclient(c1, 0);
} }
} }
@@ -4587,7 +4586,7 @@ setfloating(Client *c, int floating) {
if (!c->force_maximize) if (!c->force_maximize)
client_set_maximized(c, false); client_set_maximized(c, false);
arrange(c->mon, false); arrange(c->mon, false, false);
setborder_color(c); setborder_color(c);
printstatus(); printstatus();
} }
@@ -4645,7 +4644,7 @@ void setmaximizescreen(Client *c, int maximizescreen) {
client_set_maximized(c, true); client_set_maximized(c, true);
} }
arrange(c->mon, false); arrange(c->mon, false, false);
} }
void setfakefullscreen(Client *c, int fakefullscreen) { void setfakefullscreen(Client *c, int fakefullscreen) {
@@ -4705,7 +4704,7 @@ void setfullscreen(Client *c, int fullscreen) // 用自定义全屏代理自带
set_size_per(c->mon, c); set_size_per(c->mon, c);
} }
arrange(c->mon, false); arrange(c->mon, false, false);
} }
void setgaps(int oh, int ov, int ih, int iv) { void setgaps(int oh, int ov, int ih, int iv) {
@@ -4713,7 +4712,7 @@ void setgaps(int oh, int ov, int ih, int iv) {
selmon->gappov = MAX(ov, 0); selmon->gappov = MAX(ov, 0);
selmon->gappih = MAX(ih, 0); selmon->gappih = MAX(ih, 0);
selmon->gappiv = MAX(iv, 0); selmon->gappiv = MAX(iv, 0);
arrange(selmon, false); arrange(selmon, false, false);
} }
void reset_keyboard_layout(void) { void reset_keyboard_layout(void) {
@@ -4827,7 +4826,7 @@ void setmon(Client *c, Monitor *m, uint32_t newtags, bool focus) {
/* Scene graph sends surface leave/enter events on move and resize */ /* Scene graph sends surface leave/enter events on move and resize */
if (oldmon) if (oldmon)
arrange(oldmon, false); arrange(oldmon, false, false);
if (m) { if (m) {
/* Make sure window actually overlaps with the monitor */ /* Make sure window actually overlaps with the monitor */
resize(c, c->geom, 0); resize(c, c->geom, 0);
@@ -4888,7 +4887,7 @@ void show_hide_client(Client *c) {
tag_client(&(Arg){.ui = target}, c); tag_client(&(Arg){.ui = target}, c);
} else { } else {
c->tags = c->oldtags; c->tags = c->oldtags;
arrange(c->mon, false); arrange(c->mon, false, false);
} }
c->isminimized = 0; c->isminimized = 0;
wlr_foreign_toplevel_handle_v1_set_minimized(c->foreign_toplevel, false); wlr_foreign_toplevel_handle_v1_set_minimized(c->foreign_toplevel, false);
@@ -5573,7 +5572,7 @@ void updatemons(struct wl_listener *listener, void *data) {
/* Calculate the effective monitor geometry to use for clients */ /* Calculate the effective monitor geometry to use for clients */
arrangelayers(m); arrangelayers(m);
/* Don't move clients to the left output when plugging monitors */ /* Don't move clients to the left output when plugging monitors */
arrange(m, false); arrange(m, false, false);
/* make sure fullscreen clients have the right size */ /* make sure fullscreen clients have the right size */
if ((c = focustop(m)) && c->isfullscreen) if ((c = focustop(m)) && c->isfullscreen)
resize(c, m->m, 0); resize(c, m->m, 0);
@@ -5694,8 +5693,7 @@ toggleseltags:
if (changefocus) if (changefocus)
focusclient(focustop(m), 1); focusclient(focustop(m), 1);
reset_multi_tag_client_per(m); arrange(m, want_animation, true);
arrange(m, want_animation);
printstatus(); printstatus();
} }
@@ -5843,7 +5841,7 @@ void activatex11(struct wl_listener *listener, void *data) {
} }
if (need_arrange) { if (need_arrange) {
arrange(c->mon, false); arrange(c->mon, false, false);
} }
printstatus(); printstatus();
@@ -5872,7 +5870,7 @@ void configurex11(struct wl_listener *listener, void *data) {
.height = event->height + c->bw * 2}, .height = event->height + c->bw * 2},
0); 0);
} else { } else {
arrange(c->mon, false); arrange(c->mon, false, false);
} }
} }