opt: eliminate the positional deviation in master layout

This commit is contained in:
DreamMaoMao
2025-12-09 20:35:21 +08:00
parent dfb59d12c2
commit 318dc85b22
2 changed files with 78 additions and 27 deletions

View File

@@ -413,6 +413,21 @@ void center_tile(Monitor *m) {
// 判断是否需要主区域铺满
int should_overspread = center_master_overspread && (n <= nmasters);
uint32_t master_surplus_height =
(m->w.height - 2 * cur_gappov -
cur_gappiv * ie * (master_num - 1));
float master_surplus_ratio = 1.0;
uint32_t slave_left_surplus_height =
(m->w.height - 2 * cur_gappov -
cur_gappiv * ie * (stack_num / 2 - 1));
float slave_left_surplus_ratio = 1.0;
uint32_t slave_right_surplus_height =
(m->w.height - 2 * cur_gappov -
cur_gappiv * ie * ((stack_num + 1) / 2 - 1));
float slave_right_surplus_ratio = 1.0;
if (n > nmasters || !should_overspread) {
// 计算主区域宽度(居中模式)
mw = nmasters ? (m->w.width - 2 * cur_gappoh - cur_gappih * ie) * mfact
@@ -457,9 +472,9 @@ void center_tile(Monitor *m) {
// 主区域窗口
r = MIN(n, nmasters) - i;
if (c->master_inner_per > 0.0f) {
h = (m->w.height - 2 * cur_gappov -
cur_gappiv * ie * (master_num - 1)) *
c->master_inner_per;
h = master_surplus_height * c->master_inner_per / master_surplus_ratio;
master_surplus_height = master_surplus_height - h;
master_surplus_ratio = master_surplus_ratio - c->master_inner_per;
c->master_mfact_per = mfact;
} else {
h = (m->w.height - my - cur_gappov -
@@ -521,9 +536,9 @@ void center_tile(Monitor *m) {
if ((stack_index % 2) ^ (n % 2 == 0)) {
// 右侧堆叠窗口
if (c->stack_innder_per > 0.0f) {
h = (m->w.height - 2 * cur_gappov -
cur_gappiv * ie * ((stack_num + 1) / 2 - 1)) *
c->stack_innder_per;
h = slave_right_surplus_height * c->stack_innder_per / slave_right_surplus_ratio;
slave_right_surplus_height = slave_right_surplus_height - h;
slave_right_surplus_ratio = slave_right_surplus_ratio - c->stack_innder_per;
c->master_mfact_per = mfact;
} else {
h = (m->w.height - ety - cur_gappov -
@@ -547,9 +562,9 @@ void center_tile(Monitor *m) {
} else {
// 左侧堆叠窗口
if (c->stack_innder_per > 0.0f) {
h = (m->w.height - 2 * cur_gappov -
cur_gappiv * ie * (stack_num / 2 - 1)) *
c->stack_innder_per;
h = slave_left_surplus_height * c->stack_innder_per / slave_left_surplus_ratio;
slave_left_surplus_height = slave_left_surplus_height - h;
slave_left_surplus_ratio = slave_left_surplus_ratio - c->stack_innder_per;
c->master_mfact_per = mfact;
} else {
h = (m->w.height - oty - cur_gappov -
@@ -619,15 +634,26 @@ void tile(Monitor *m) {
mw = m->w.width - 2 * cur_gappoh + cur_gappih * ie;
i = 0;
my = ty = cur_gappov;
uint32_t master_surplus_height =
(m->w.height - 2 * cur_gappov - cur_gappiv * ie * (master_num - 1));
float master_surplus_ratio = 1.0;
uint32_t slave_surplus_height =
(m->w.height - 2 * cur_gappov - cur_gappiv * ie * (stack_num - 1));
float slave_surplus_ratio = 1.0;
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || !ISTILED(c))
continue;
if (i < m->pertag->nmasters[m->pertag->curtag]) {
r = MIN(n, m->pertag->nmasters[m->pertag->curtag]) - i;
if (c->master_inner_per > 0.0f) {
h = (m->w.height - 2 * cur_gappov -
cur_gappiv * ie * (master_num - 1)) *
c->master_inner_per;
h = master_surplus_height * c->master_inner_per /
master_surplus_ratio;
master_surplus_height = master_surplus_height - h;
master_surplus_ratio =
master_surplus_ratio - c->master_inner_per;
c->master_mfact_per = mfact;
} else {
h = (m->w.height - my - cur_gappov -
@@ -647,9 +673,10 @@ void tile(Monitor *m) {
} else {
r = n - i;
if (c->stack_innder_per > 0.0f) {
h = (m->w.height - 2 * cur_gappov -
cur_gappiv * ie * (stack_num - 1)) *
c->stack_innder_per;
h = slave_surplus_height * c->stack_innder_per /
slave_surplus_ratio;
slave_surplus_height = slave_surplus_height - h;
slave_surplus_ratio = slave_surplus_ratio - c->stack_innder_per;
c->master_mfact_per = mfact;
} else {
h = (m->w.height - ty - cur_gappov -
@@ -717,15 +744,26 @@ void right_tile(Monitor *m) {
mw = m->w.width - 2 * cur_gappoh + cur_gappih * ie;
i = 0;
my = ty = cur_gappov;
uint32_t master_surplus_height =
(m->w.height - 2 * cur_gappov - cur_gappiv * ie * (master_num - 1));
float master_surplus_ratio = 1.0;
uint32_t slave_surplus_height =
(m->w.height - 2 * cur_gappov - cur_gappiv * ie * (stack_num - 1));
float slave_surplus_ratio = 1.0;
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || !ISTILED(c))
continue;
if (i < m->pertag->nmasters[m->pertag->curtag]) {
r = MIN(n, m->pertag->nmasters[m->pertag->curtag]) - i;
if (c->master_inner_per > 0.0f) {
h = (m->w.height - 2 * cur_gappov -
cur_gappiv * ie * (master_num - 1)) *
c->master_inner_per;
h = master_surplus_height * c->master_inner_per /
master_surplus_ratio;
master_surplus_height = master_surplus_height - h;
master_surplus_ratio =
master_surplus_ratio - c->master_inner_per;
c->master_mfact_per = mfact;
} else {
h = (m->w.height - my - cur_gappov -
@@ -746,9 +784,10 @@ void right_tile(Monitor *m) {
} else {
r = n - i;
if (c->stack_innder_per > 0.0f) {
h = (m->w.height - 2 * cur_gappov -
cur_gappiv * ie * (stack_num - 1)) *
c->stack_innder_per;
h = slave_surplus_height * c->stack_innder_per /
slave_surplus_ratio;
slave_surplus_height = slave_surplus_height - h;
slave_surplus_ratio = slave_surplus_ratio - c->stack_innder_per;
c->master_mfact_per = mfact;
} else {
h = (m->w.height - ty - cur_gappov -

View File

@@ -41,15 +41,26 @@ void vertical_tile(Monitor *m) {
i = 0;
mx = tx = cur_gapih;
uint32_t master_surplus_width =
(m->w.width - 2 * cur_gapih - cur_gapih * ie * (master_num - 1));
float master_surplus_ratio = 1.0;
uint32_t slave_surplus_width =
(m->w.width - 2 * cur_gapih - cur_gapih * ie * (stack_num - 1));
float slave_surplus_ratio = 1.0;
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || !ISTILED(c))
continue;
if (i < m->pertag->nmasters[m->pertag->curtag]) {
r = MIN(n, m->pertag->nmasters[m->pertag->curtag]) - i;
if (c->master_inner_per > 0.0f) {
w = (m->w.width - 2 * cur_gapih -
cur_gapih * ie * (master_num - 1)) *
c->master_inner_per;
w = master_surplus_width * c->master_inner_per /
master_surplus_ratio;
master_surplus_width = master_surplus_width - w;
master_surplus_ratio =
master_surplus_ratio - c->master_inner_per;
c->master_mfact_per = mfact;
} else {
w = (m->w.width - mx - cur_gapih - cur_gapih * ie * (r - 1)) /
@@ -68,9 +79,10 @@ void vertical_tile(Monitor *m) {
} else {
r = n - i;
if (c->stack_innder_per > 0.0f) {
w = (m->w.width - 2 * cur_gapih -
cur_gapih * ie * (stack_num - 1)) *
c->stack_innder_per;
w = slave_surplus_width * c->stack_innder_per /
slave_surplus_ratio;
slave_surplus_width = slave_surplus_width - w;
slave_surplus_ratio = slave_surplus_ratio - c->stack_innder_per;
c->master_mfact_per = mfact;
} else {
w = (m->w.width - tx - cur_gapih - cur_gapih * ie * (r - 1)) /