mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-05-28 21:37:28 -04:00
opt: avoid useless caculate
This commit is contained in:
parent
3b9d59fb6b
commit
b543e3f803
1 changed files with 85 additions and 84 deletions
|
|
@ -81,6 +81,7 @@ static void dwindle_insert(DwindleNode **root, Client *new_c, Client *focused,
|
||||||
target = dwindle_first_leaf(*root);
|
target = dwindle_first_leaf(*root);
|
||||||
|
|
||||||
// ================= 保持其他窗口比例缩减逻辑 =================
|
// ================= 保持其他窗口比例缩减逻辑 =================
|
||||||
|
if (config.dwindle_manual_split) {
|
||||||
DwindleNode *path[512];
|
DwindleNode *path[512];
|
||||||
float p[512];
|
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);
|
||||||
|
|
@ -111,6 +112,7 @@ static void dwindle_insert(DwindleNode **root, Client *new_c, Client *focused,
|
||||||
if (S->ratio > 0.999f)
|
if (S->ratio > 0.999f)
|
||||||
S->ratio = 0.999f;
|
S->ratio = 0.999f;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|
||||||
DwindleNode *split = calloc(1, sizeof(DwindleNode));
|
DwindleNode *split = calloc(1, sizeof(DwindleNode));
|
||||||
|
|
@ -166,6 +168,7 @@ static void dwindle_remove(DwindleNode **root, Client *c) {
|
||||||
// 开始删除空间的比例回退逻辑
|
// 开始删除空间的比例回退逻辑
|
||||||
|
|
||||||
// 查找连续的同方向块路径
|
// 查找连续的同方向块路径
|
||||||
|
if (config.dwindle_manual_split) {
|
||||||
bool split_h = parent->split_h;
|
bool split_h = parent->split_h;
|
||||||
DwindleNode *path[512];
|
DwindleNode *path[512];
|
||||||
int path_len = 0;
|
int path_len = 0;
|
||||||
|
|
@ -189,8 +192,8 @@ static void dwindle_remove(DwindleNode **root, Client *c) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 计算即将被删除的叶子节点,在该方向块中所占的绝对面积比例 (P_del)
|
// 计算即将被删除的叶子节点,在该方向块中所占的绝对面积比例 (P_del)
|
||||||
float p_del =
|
float p_del = p[0] * (parent->first == leaf ? parent->ratio
|
||||||
p[0] * (parent->first == leaf ? parent->ratio : (1.0f - parent->ratio));
|
: (1.0f - parent->ratio));
|
||||||
if (p_del > 0.999f)
|
if (p_del > 0.999f)
|
||||||
p_del = 0.999f; // 兜底
|
p_del = 0.999f; // 兜底
|
||||||
|
|
||||||
|
|
@ -216,6 +219,7 @@ static void dwindle_remove(DwindleNode **root, Client *c) {
|
||||||
if (S->ratio > 0.999f)
|
if (S->ratio > 0.999f)
|
||||||
S->ratio = 0.999f;
|
S->ratio = 0.999f;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 比例重算结束
|
// 比例重算结束
|
||||||
|
|
||||||
|
|
@ -454,14 +458,15 @@ static void dwindle_insert_with_config(DwindleNode **root, Client *new_c,
|
||||||
double ny = (cursor->y - fcy) / (fg->height * 0.5);
|
double ny = (cursor->y - fcy) / (fg->height * 0.5);
|
||||||
|
|
||||||
if (fabs(ny) > fabs(nx)) {
|
if (fabs(ny) > fabs(nx)) {
|
||||||
split_h = false;
|
split_h = false; // vertical split
|
||||||
as_first = (ny < 0);
|
as_first = (ny < 0); // top → new window on top
|
||||||
} else {
|
} else {
|
||||||
split_h = true;
|
split_h = true; // horizontal split
|
||||||
as_first = (nx < 0);
|
as_first = (nx < 0); // left → new window on left
|
||||||
}
|
}
|
||||||
lock = true;
|
lock = true; // lock split direction
|
||||||
} else {
|
} else {
|
||||||
|
// normal mode, auto split
|
||||||
bool likely_h = (fg->width >= fg->height);
|
bool likely_h = (fg->width >= fg->height);
|
||||||
split_h = likely_h;
|
split_h = likely_h;
|
||||||
|
|
||||||
|
|
@ -479,11 +484,10 @@ static void dwindle_insert_with_config(DwindleNode **root, Client *new_c,
|
||||||
}
|
}
|
||||||
|
|
||||||
DwindleNode *target = focused ? dwindle_find_leaf(*root, focused) : NULL;
|
DwindleNode *target = focused ? dwindle_find_leaf(*root, focused) : NULL;
|
||||||
// 防止极端情况下找不到 target
|
|
||||||
if (!target && *root)
|
if (!target && *root)
|
||||||
target = dwindle_first_leaf(*root);
|
target = dwindle_first_leaf(*root);
|
||||||
|
|
||||||
// 计算 1/N 比例
|
// 当且仅当 manual_split=1 时,计算精确的 1/N 新节点比例
|
||||||
if (config.dwindle_manual_split && target) {
|
if (config.dwindle_manual_split && target) {
|
||||||
split_h = target->custom_leaf_split_h;
|
split_h = target->custom_leaf_split_h;
|
||||||
lock = true;
|
lock = true;
|
||||||
|
|
@ -501,17 +505,14 @@ static void dwindle_insert_with_config(DwindleNode **root, Client *new_c,
|
||||||
float N = (float)(n_old + 1);
|
float N = (float)(n_old + 1);
|
||||||
|
|
||||||
float p_target_old = p[0];
|
float p_target_old = p[0];
|
||||||
// 算出 split 节点在方向块里总共能分到的绝对面积比例
|
|
||||||
float p_split_new = p_target_old * (N - 1.0f) / N + 1.0f / N;
|
float p_split_new = p_target_old * (N - 1.0f) / N + 1.0f / N;
|
||||||
|
|
||||||
// 逆推传给 dwindle_insert 的局部 ratio
|
|
||||||
if (as_first) {
|
if (as_first) {
|
||||||
ratio = (1.0f / N) / p_split_new;
|
ratio = (1.0f / N) / p_split_new;
|
||||||
} else {
|
} else {
|
||||||
ratio = (p_target_old * (N - 1.0f) / N) / p_split_new;
|
ratio = (p_target_old * (N - 1.0f) / N) / p_split_new;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 安全兜底
|
|
||||||
if (ratio < 0.001f)
|
if (ratio < 0.001f)
|
||||||
ratio = 0.001f;
|
ratio = 0.001f;
|
||||||
if (ratio > 0.999f)
|
if (ratio > 0.999f)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue