From 89e0805d54d2cd9c92196e61c48c6ba9dc9facd7 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Thu, 1 Jan 2026 12:26:19 +0800 Subject: [PATCH] opt: optimize code struct --- src/config/parse_config.h | 2 +- src/dispatch/bind_define.h | 34 ++++++++++----------- src/ext-protocol/dwl-ipc.h | 4 +-- src/ext-protocol/foreign-toplevel.h | 4 +-- src/layout/arrange.h | 39 ++++++++++-------------- src/mango.c | 46 ++++++++++++++--------------- 6 files changed, 59 insertions(+), 70 deletions(-) diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 074b522..460d997 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -3347,7 +3347,7 @@ void reset_option(void) { reapply_tagrule(); reapply_monitor_rules(); - arrange(selmon, false); + arrange(selmon, false, false); } int reload_config(const Arg *arg) { diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index 80512d7..96609dd 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -244,7 +244,7 @@ int incnmaster(const Arg *arg) { return 0; selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->pertag->nmasters[selmon->pertag->curtag] + arg->i, 0); - arrange(selmon, false); + arrange(selmon, false, false); return 0; } @@ -308,7 +308,7 @@ int setmfact(const Arg *arg) { c->master_mfact_per = f; } } - arrange(selmon, false); + arrange(selmon, false, false); return 0; } @@ -491,7 +491,7 @@ int restore_minimized(const Arg *arg) { c->isnamedscratchpad = 0; show_hide_client(c); setborder_color(c); - arrange(c->mon, false); + arrange(c->mon, false, false); focusclient(c, 0); warp_cursor(c); return 0; @@ -507,7 +507,7 @@ int setlayout(const Arg *arg) { if (strcmp(layouts[jk].name, arg->v) == 0) { selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[jk]; clear_fullscreen_and_maximized_state(selmon); - arrange(selmon, false); + arrange(selmon, false, false); printstatus(); return 0; } @@ -541,7 +541,7 @@ int set_proportion(const Arg *arg) { selmon->sel->scroller_proportion = arg->f; selmon->sel->geom.width = max_client_width * arg->f; // resize(selmon->sel, selmon->sel->geom, 0); - arrange(selmon, false); + arrange(selmon, false, false); } return 0; } @@ -740,7 +740,7 @@ int centerwin(const Arg *arg) { c->geom.y = selmon->w.y + (selmon->w.height - c->geom.height) / 2; } - arrange(selmon, false); + arrange(selmon, false, false); return 0; } @@ -923,7 +923,7 @@ int switch_layout(const Arg *arg) { } } clear_fullscreen_and_maximized_state(selmon); - arrange(selmon, false); + arrange(selmon, false, false); printstatus(); return 0; } @@ -934,7 +934,7 @@ int switch_layout(const Arg *arg) { selmon->pertag->ltidxs[selmon->pertag->curtag] = jk == LENGTH(layouts) - 1 ? &layouts[0] : &layouts[jk + 1]; clear_fullscreen_and_maximized_state(selmon); - arrange(selmon, false); + arrange(selmon, false, false); printstatus(); return 0; } @@ -981,7 +981,7 @@ int switch_proportion_preset(const Arg *arg) { selmon->sel->scroller_proportion = target_proportion; selmon->sel->geom.width = max_client_width * target_proportion; // resize(selmon->sel, selmon->sel->geom, 0); - arrange(selmon, false); + arrange(selmon, false, false); } return 0; } @@ -1055,7 +1055,7 @@ int tagmon(const Arg *arg) { target = get_tags_first_tag(c->tags); view(&(Arg){.ui = target}, true); focusclient(c, 1); - arrange(selmon, false); + arrange(selmon, false, false); } if (warpcursor) { warp_cursor_to_selmon(c->mon); @@ -1079,7 +1079,7 @@ int tagsilent(const Arg *arg) { } } focusclient(focustop(selmon), 1); - arrange(target_client->mon, false); + arrange(target_client->mon, false, false); return 0; } @@ -1122,7 +1122,7 @@ int toggle_named_scratchpad(const Arg *arg) { int toggle_render_border(const Arg *arg) { render_border = !render_border; - arrange(selmon, false); + arrange(selmon, false, false); return 0; } @@ -1215,7 +1215,7 @@ int toggleglobal(const Arg *arg) { int togglegaps(const Arg *arg) { enablegaps ^= 1; - arrange(selmon, false); + arrange(selmon, false, false); return 0; } @@ -1275,7 +1275,7 @@ int toggletag(const Arg *arg) { if (newtags) { sel->tags = newtags; focusclient(focustop(selmon), 1); - arrange(selmon, false); + arrange(selmon, false, false); } printstatus(); return 0; @@ -1293,7 +1293,7 @@ int toggleview(const Arg *arg) { if (newtagset) { selmon->tagset[selmon->seltags] = newtagset; focusclient(focustop(selmon), 1); - arrange(selmon, false); + arrange(selmon, false, false); } printstatus(); return 0; @@ -1407,7 +1407,7 @@ int comboview(const Arg *arg) { if (tag_combo) { selmon->tagset[selmon->seltags] |= newtags; focusclient(focustop(selmon), 1); - arrange(selmon, false); + arrange(selmon, false, false); } else { tag_combo = true; view(&(Arg){.ui = newtags}, false); @@ -1446,7 +1446,7 @@ int zoom(const Arg *arg) { wl_list_insert(&clients, &sel->link); focusclient(sel, 1); - arrange(selmon, false); + arrange(selmon, false, false); return 0; } diff --git a/src/ext-protocol/dwl-ipc.h b/src/ext-protocol/dwl-ipc.h index eda3f49..0ce5206 100644 --- a/src/ext-protocol/dwl-ipc.h +++ b/src/ext-protocol/dwl-ipc.h @@ -238,7 +238,7 @@ void dwl_ipc_output_set_client_tags(struct wl_client *client, selected_client->tags = newtags; if (selmon == monitor) focusclient(focustop(monitor), 1); - arrange(selmon, false); + arrange(selmon, false, false); printstatus(); } @@ -257,7 +257,7 @@ void dwl_ipc_output_set_layout(struct wl_client *client, monitor->pertag->ltidxs[monitor->pertag->curtag] = &layouts[index]; clear_fullscreen_and_maximized_state(monitor); - arrange(monitor, false); + arrange(monitor, false, false); printstatus(); } diff --git a/src/ext-protocol/foreign-toplevel.h b/src/ext-protocol/foreign-toplevel.h index 01c384f..89f3839 100644 --- a/src/ext-protocol/foreign-toplevel.h +++ b/src/ext-protocol/foreign-toplevel.h @@ -15,7 +15,7 @@ void handle_foreign_activate_request(struct wl_listener *listener, void *data) { c->is_scratchpad_show = 0; setborder_color(c); show_hide_client(c); - arrange(c->mon, true); + arrange(c->mon, true, false); return; } @@ -60,7 +60,7 @@ void handle_foreign_minimize_request(struct wl_listener *listener, void *data) { c->is_scratchpad_show = 0; setborder_color(c); show_hide_client(c); - arrange(c->mon, true); + arrange(c->mon, true, false); return; } } diff --git a/src/layout/arrange.h b/src/layout/arrange.h index dc8b47e..25a057b 100644 --- a/src/layout/arrange.h +++ b/src/layout/arrange.h @@ -200,13 +200,13 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int offsetx, grabc->stack_inner_per = new_stack_inner_per; if (!isdrag) { - arrange(grabc->mon, false); + arrange(grabc->mon, false, false); return; } if (last_apply_drap_time == 0 || time - last_apply_drap_time > drag_refresh_interval) { - arrange(grabc->mon, false); + arrange(grabc->mon, false, false); 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; if (!isdrag) { - arrange(grabc->mon, false); + arrange(grabc->mon, false, false); return; } if (last_apply_drap_time == 0 || time - last_apply_drap_time > drag_refresh_interval) { - arrange(grabc->mon, false); + arrange(grabc->mon, false, false); 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; if (!isdrag) { - arrange(grabc->mon, false); + arrange(grabc->mon, false, false); return; } if (last_apply_drap_time == 0 || time - last_apply_drap_time > drag_refresh_interval) { - arrange(grabc->mon, false); + arrange(grabc->mon, false, false); 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 -arrange(Monitor *m, bool want_animation) { +arrange(Monitor *m, bool want_animation, bool from_view) { Client *c = NULL; double total_stack_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) { + if (from_view && (c->isglobal || c->isunglobal)) { + set_size_per(m, c); + } + if (c->mon == m && (c->isglobal || c->isunglobal)) { c->tags = m->tagset[m->seltags]; if (c->mon->sel == NULL) @@ -624,6 +611,10 @@ arrange(Monitor *m, bool want_animation) { } if (VISIBLEON(c, m)) { + if (from_view && !client_only_in_one_tag(c)) { + set_size_per(m, c); + } + if (!c->isunglobal) m->visible_clients++; diff --git a/src/mango.c b/src/mango.c index ef138a0..2e70acf 100644 --- a/src/mango.c +++ b/src/mango.c @@ -534,9 +534,8 @@ static void applybounds( Client *c, struct wlr_box *bbox); // 设置边界规则,能让一些窗口拥有比较适合的大小 static void applyrules(Client *c); // 窗口规则应用,应用config.h中定义的窗口规则 -static void -arrange(Monitor *m, - bool want_animation); // 布局函数,让窗口俺平铺规则移动和重置大小 +static void arrange(Monitor *m, bool want_animation, + bool from_view); // 布局函数,让窗口俺平铺规则移动和重置大小 static void arrangelayer(Monitor *m, struct wl_list *list, struct wlr_box *usable_area, int exclusive); static void arrangelayers(Monitor *m); @@ -1093,7 +1092,7 @@ bool switch_scratchpad_client_state(Client *c) { if (c->is_scratchpad_show) { c->tags = get_tags_first_tag(selmon->tagset[selmon->seltags]); resize(c, c->float_geom, 0); - arrange(selmon, false); + arrange(selmon, false, false); focusclient(c, true); c->scratchpad_switching_mon = false; return true; @@ -1106,7 +1105,7 @@ bool switch_scratchpad_client_state(Client *c) { if (c->is_in_scratchpad && c->is_scratchpad_show && (c->mon->tagset[c->mon->seltags] & c->tags) == 0) { c->tags = c->mon->tagset[c->mon->seltags]; - arrange(c->mon, false); + arrange(c->mon, false, false); focusclient(c, true); return true; } else if (c->is_in_scratchpad && c->is_scratchpad_show && @@ -1415,7 +1414,7 @@ void applyrules(Client *c) { VISIBLEON(fc, c->mon) && ISFULLSCREEN(fc) && !c->isfloating) { clear_fullscreen_flag(fc); - arrange(c->mon, false); + arrange(c->mon, false, false); } if (c->isfloating && !hit_rule_pos && !c->isnamedscratchpad) { @@ -1614,7 +1613,7 @@ void arrangelayers(Monitor *m) { if (!wlr_box_equal(&usable_area, &m->w)) { m->w = usable_area; - arrange(m, false); + arrange(m, false, false); } /* Arrange non-exlusive surfaces from top->bottom */ @@ -3217,7 +3216,7 @@ void focusclient(Client *c, int lift) { (selmon->prevsel->tags & selmon->tagset[selmon->seltags]) && (c->tags & selmon->tagset[selmon->seltags]) && !c->isfloating && is_scroller_layout(selmon)) { - arrange(selmon, false); + arrange(selmon, false, false); } // change focus link position @@ -3886,7 +3885,7 @@ void unminimize(Client *c) { c->is_in_scratchpad = 0; c->isnamedscratchpad = 0; setborder_color(c); - arrange(c->mon, false); + arrange(c->mon, false, false); return; } } @@ -3904,7 +3903,7 @@ void set_minimized(Client *c) { c->is_in_scratchpad = 1; c->is_scratchpad_show = 0; 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_minimized(c->foreign_toplevel, true); wl_list_remove(&c->link); // 从原来位置移除 @@ -4405,11 +4404,11 @@ void exchange_two_client(Client *c1, Client *c2) { tmp_tags = c2->tags; setmon(c2, c1->mon, c1->tags, false); setmon(c1, tmp_mon, tmp_tags, false); - arrange(c1->mon, false); - arrange(c2->mon, false); + arrange(c1->mon, false, false); + arrange(c2->mon, false, false); focusclient(c1, 0); } else { - arrange(c1->mon, false); + arrange(c1->mon, false, false); focusclient(c1, 0); } } @@ -4587,7 +4586,7 @@ setfloating(Client *c, int floating) { if (!c->force_maximize) client_set_maximized(c, false); - arrange(c->mon, false); + arrange(c->mon, false, false); setborder_color(c); printstatus(); } @@ -4645,7 +4644,7 @@ void setmaximizescreen(Client *c, int maximizescreen) { client_set_maximized(c, true); } - arrange(c->mon, false); + arrange(c->mon, false, false); } void setfakefullscreen(Client *c, int fakefullscreen) { @@ -4705,7 +4704,7 @@ void setfullscreen(Client *c, int fullscreen) // 用自定义全屏代理自带 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) { @@ -4713,7 +4712,7 @@ void setgaps(int oh, int ov, int ih, int iv) { selmon->gappov = MAX(ov, 0); selmon->gappih = MAX(ih, 0); selmon->gappiv = MAX(iv, 0); - arrange(selmon, false); + arrange(selmon, false, false); } 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 */ if (oldmon) - arrange(oldmon, false); + arrange(oldmon, false, false); if (m) { /* Make sure window actually overlaps with the monitor */ resize(c, c->geom, 0); @@ -4888,7 +4887,7 @@ void show_hide_client(Client *c) { tag_client(&(Arg){.ui = target}, c); } else { c->tags = c->oldtags; - arrange(c->mon, false); + arrange(c->mon, false, false); } c->isminimized = 0; 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 */ arrangelayers(m); /* 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 */ if ((c = focustop(m)) && c->isfullscreen) resize(c, m->m, 0); @@ -5694,8 +5693,7 @@ toggleseltags: if (changefocus) focusclient(focustop(m), 1); - reset_multi_tag_client_per(m); - arrange(m, want_animation); + arrange(m, want_animation, true); printstatus(); } @@ -5843,7 +5841,7 @@ void activatex11(struct wl_listener *listener, void *data) { } if (need_arrange) { - arrange(c->mon, false); + arrange(c->mon, false, false); } printstatus(); @@ -5872,7 +5870,7 @@ void configurex11(struct wl_listener *listener, void *data) { .height = event->height + c->bw * 2}, 0); } else { - arrange(c->mon, false); + arrange(c->mon, false, false); } }