opt: avoid useless caculate

This commit is contained in:
DreamMaoMao 2026-05-14 16:21:16 +08:00
parent 6f2657a73b
commit b78151cca9
3 changed files with 66 additions and 44 deletions

View file

@ -248,7 +248,7 @@ void apply_shield(Client *c, struct wlr_box clip_box) {
void apply_split_border(Client *c, bool hit_no_border) { void apply_split_border(Client *c, bool hit_no_border) {
if (c->iskilling || !client_surface(c)->mapped) if (c->iskilling || !c->mon || !client_surface(c)->mapped)
return; return;
const Layout *layout = c->mon->pertag->ltidxs[c->mon->pertag->curtag]; const Layout *layout = c->mon->pertag->ltidxs[c->mon->pertag->curtag];

View file

@ -81,8 +81,8 @@ static void dwindle_insert(DwindleNode **root, Client *new_c, Client *focused,
target = dwindle_first_leaf(*root); target = dwindle_first_leaf(*root);
// ================= 保持其他窗口比例缩减逻辑 ================= // ================= 保持其他窗口比例缩减逻辑 =================
DwindleNode *path[128]; DwindleNode *path[512];
float p[128]; float p[512];
int path_len = get_block_path_and_ratios(target, split_h, path, p); int path_len = get_block_path_and_ratios(target, split_h, path, p);
int n_old = 1; int n_old = 1;
@ -161,7 +161,7 @@ static void dwindle_remove(DwindleNode **root, Client *c) {
// 查找连续的同方向块路径 // 查找连续的同方向块路径
bool split_h = parent->split_h; bool split_h = parent->split_h;
DwindleNode *path[128]; DwindleNode *path[512];
int path_len = 0; int path_len = 0;
path[path_len++] = parent; path[path_len++] = parent;
DwindleNode *curr = parent->parent; DwindleNode *curr = parent->parent;
@ -171,7 +171,7 @@ static void dwindle_remove(DwindleNode **root, Client *c) {
} }
// 计算各祖先的旧绝对占比 // 计算各祖先的旧绝对占比
float p[128]; float p[512];
p[path_len - 1] = 1.0f; p[path_len - 1] = 1.0f;
for (int i = path_len - 1; i > 0; i--) { for (int i = path_len - 1; i > 0; i--) {
DwindleNode *S = path[i]; DwindleNode *S = path[i];
@ -457,6 +457,8 @@ static void dwindle_insert_with_config(DwindleNode **root, Client *new_c,
lock = true; lock = true;
} else { } else {
bool likely_h = (fg->width >= fg->height); bool likely_h = (fg->width >= fg->height);
split_h = likely_h;
if (likely_h) { if (likely_h) {
if (config.dwindle_hsplit == 0) if (config.dwindle_hsplit == 0)
as_first = (cursor->x < fcx); as_first = (cursor->x < fcx);
@ -482,8 +484,8 @@ static void dwindle_insert_with_config(DwindleNode **root, Client *new_c,
as_first = false; as_first = false;
// ================= 计算新节点的 1/N 比例 ================= // ================= 计算新节点的 1/N 比例 =================
DwindleNode *path[128]; DwindleNode *path[512];
float p[128]; float p[512];
int path_len = get_block_path_and_ratios(target, split_h, path, p); int path_len = get_block_path_and_ratios(target, split_h, path, p);
int n_old = 1; int n_old = 1;
@ -585,3 +587,8 @@ void dwindle(Monitor *m) {
m->w.width - 2 * gap_oh, m->w.height - 2 * gap_ov, gap_ih, m->w.width - 2 * gap_oh, m->w.height - 2 * gap_ov, gap_ih,
gap_iv); gap_iv);
} }
void cleanup_monitor_dwindle(Monitor *m) {
for (uint32_t t = 0; t < LENGTH(tags) + 1; t++)
dwindle_free_tree(m->pertag->dwindle_root[t]);
}

View file

@ -1252,38 +1252,47 @@ void swallow(Client *c, Client *w) {
client_pending_maximized_state(c, w->ismaximizescreen); client_pending_maximized_state(c, w->ismaximizescreen);
client_pending_minimized_state(c, w->isminimized); client_pending_minimized_state(c, w->isminimized);
/* ---------- 跨 tag 同步dwindle 与 scroller ---------- */ if (!w->mon)
Monitor *m; return;
wl_list_for_each(m, &mons, link) {
const Layout *layout = w->mon->pertag->ltidxs[w->mon->pertag->curtag];
if (layout->id == DWINDLE || layout->id == SCROLLER ||
layout->id == VERTICAL_SCROLLER) {
for (uint32_t t = 0; t < LENGTH(tags) + 1; t++) { for (uint32_t t = 0; t < LENGTH(tags) + 1; t++) {
/* dwindle */ /* dwindle */
DwindleNode **root = &m->pertag->dwindle_root[t];
dwindle_remove(root, c);
DwindleNode *dnode = dwindle_find_leaf(*root, w);
if (dnode)
dnode->client = c;
/* scroller */ if (layout->id == DWINDLE) {
struct TagScrollerState *st = m->pertag->scroller_state[t];
if (!st)
continue;
/* 先移除 c 在任意 tag 中的旧节点 */ DwindleNode **root = &w->mon->pertag->dwindle_root[t];
struct ScrollerStackNode *cn = find_scroller_node(st, c); dwindle_remove(root, c);
if (cn) DwindleNode *dnode = dwindle_find_leaf(*root, w);
scroller_node_remove(st, cn); if (dnode)
dnode->client = c;
}
/* 将 w 的节点(如果存在)转给 c */ // scroller
struct ScrollerStackNode *wn = find_scroller_node(st, w); if (layout->id == SCROLLER || layout->id == VERTICAL_SCROLLER) {
if (wn) struct TagScrollerState *st = w->mon->pertag->scroller_state[t];
wn->client = c; if (!st)
continue;
/* 先移除 c 在任意 tag 中的旧节点 */
struct ScrollerStackNode *cn = find_scroller_node(st, c);
if (cn)
scroller_node_remove(st, cn);
/* 将 w 的节点(如果存在)转给 c */
struct ScrollerStackNode *wn = find_scroller_node(st, w);
if (wn)
wn->client = c;
}
} }
} }
/* 同步当前活动 tag 的全局客户端字段 */ /* 同步当前活动 tag 的全局客户端字段 */
if (c->mon) { if (layout->id == SCROLLER || layout->id == VERTICAL_SCROLLER) {
uint32_t curtag = c->mon->pertag->curtag; sync_scroller_state_to_clients(w->mon, w->mon->pertag->curtag);
sync_scroller_state_to_clients(c->mon, curtag);
} }
} }
@ -2540,9 +2549,7 @@ void cleanupmon(struct wl_listener *listener, void *data) {
m->wlr_output->data = NULL; m->wlr_output->data = NULL;
for (uint32_t t = 0; t < LENGTH(tags) + 1; t++) cleanup_monitor_dwindle(m);
dwindle_free_tree(m->pertag->dwindle_root[t]);
cleanup_monitor_scroller(m); cleanup_monitor_scroller(m);
free(m->pertag); free(m->pertag);
@ -5197,18 +5204,27 @@ exchange_common:
tmp2_next->prev = &c1->link; tmp2_next->prev = &c1->link;
} }
if (config.exchange_cross_monitor && c1->mon != c2->mon) { const Layout *layout1 = c1->mon->pertag->ltidxs[c1->mon->pertag->curtag];
DwindleNode **c1_root = &m1->pertag->dwindle_root[m1->pertag->curtag];
DwindleNode *c1node = dwindle_find_leaf(*c1_root, c1);
DwindleNode **c2_root = &m2->pertag->dwindle_root[m2->pertag->curtag]; const Layout *layout2 = c2->mon->pertag->ltidxs[c2->mon->pertag->curtag];
DwindleNode *c2node = dwindle_find_leaf(*c2_root, c2);
if (c1node) if (c1->mon != c2->mon) {
c1node->client = c2;
if (c2node) if (layout1->id == DWINDLE && layout2->id == DWINDLE) {
c2node->client = c1; DwindleNode **c1_root =
&m1->pertag->dwindle_root[m1->pertag->curtag];
DwindleNode *c1node = dwindle_find_leaf(*c1_root, c1);
DwindleNode **c2_root =
&m2->pertag->dwindle_root[m2->pertag->curtag];
DwindleNode *c2node = dwindle_find_leaf(*c2_root, c2);
if (c1node)
c1node->client = c2;
if (c2node)
c2node->client = c1;
}
tmp_mon = c2->mon; tmp_mon = c2->mon;
tmp_tags = c2->tags; tmp_tags = c2->tags;
@ -5220,8 +5236,7 @@ exchange_common:
arrange(c1->mon, false, false); arrange(c1->mon, false, false);
arrange(c2->mon, false, false); arrange(c2->mon, false, false);
} else { } else {
if (c1->mon && if (layout1->id == DWINDLE && layout2->id == DWINDLE) {
c1->mon->pertag->ltidxs[c1->mon->pertag->curtag]->id == DWINDLE) {
dwindle_swap_clients( dwindle_swap_clients(
&c1->mon->pertag->dwindle_root[c1->mon->pertag->curtag], c1, &c1->mon->pertag->dwindle_root[c1->mon->pertag->curtag], c1,
c2); c2);