opt: more simple size percent keep logic

This commit is contained in:
DreamMaoMao 2026-05-24 12:13:30 +08:00
parent 373bbf90a0
commit e6ae14ec25
5 changed files with 232 additions and 305 deletions

View file

@ -1,98 +1,3 @@
void save_old_size_per(Monitor *m) {
Client *c = NULL;
wl_list_for_each(c, &clients, link) {
if (VISIBLEON(c, m) && ISTILED(c)) {
c->old_master_inner_per = c->master_inner_per;
c->old_stack_inner_per = c->stack_inner_per;
c->old_grid_col_per = c->grid_col_per;
c->old_grid_row_per = c->grid_row_per;
}
}
}
void restore_size_per(Monitor *m, Client *c) {
Client *fc = NULL;
if (!m || !c)
return;
if (!m->wlr_output->enabled)
return;
wl_list_for_each(fc, &clients, link) {
if (VISIBLEON(fc, m) && ISTILED(fc)) {
fc->old_ismaster = fc->ismaster;
}
}
c->old_master_inner_per = c->master_inner_per;
c->old_stack_inner_per = c->stack_inner_per;
pre_caculate_before_arrange(m, false, false, true);
const Layout *current_layout = m->pertag->ltidxs[m->pertag->curtag];
if (current_layout->id == SCROLLER ||
current_layout->id == VERTICAL_SCROLLER || current_layout->id == DECK ||
current_layout->id == VERTICAL_DECK || current_layout->id == MONOCLE) {
return;
}
if (current_layout->id == GRID || current_layout->id == VERTICAL_GRID ||
current_layout->id == FAIR || current_layout->id == VERTICAL_FAIR) {
wl_list_for_each(fc, &clients, link) {
if (VISIBLEON(fc, m) && ISTILED(fc)) {
if (fc->old_grid_col_per > 0.0f)
fc->grid_col_per = fc->old_grid_col_per;
if (fc->old_grid_row_per > 0.0f)
fc->grid_row_per = fc->old_grid_row_per;
}
}
return;
}
if (current_layout->id == CENTER_TILE) {
wl_list_for_each(fc, &clients, link) {
if (VISIBLEON(fc, m) && ISTILED(fc) && !c->ismaster) {
set_size_per(m, fc);
}
}
return;
}
// it is possible that the current floating window is moved to another tag,
// but the tag has not executed save_old_size_per
// so it must be judged whether their old size values are initial values
if (!c->ismaster && c->old_stack_inner_per < 1.0 &&
c->old_stack_inner_per > 0.0f && c->stack_inner_per < 1.0 &&
c->stack_inner_per > 0.0f) {
c->stack_inner_per = (1.0 - c->stack_inner_per) *
c->old_stack_inner_per /
(1.0 - c->old_stack_inner_per);
}
if (c->ismaster && c->old_master_inner_per < 1.0 &&
c->old_master_inner_per > 0.0f && c->master_inner_per < 1.0 &&
c->master_inner_per > 0.0f) {
c->master_inner_per = (1.0 - c->master_inner_per) *
c->old_master_inner_per /
(1.0 - c->old_master_inner_per);
}
wl_list_for_each(fc, &clients, link) {
if (VISIBLEON(fc, m) && ISTILED(fc) && fc != c && !fc->ismaster &&
fc->old_ismaster && fc->old_stack_inner_per < 1.0 &&
fc->old_stack_inner_per > 0.0f && fc->stack_inner_per < 1.0 &&
fc->stack_inner_per > 0.0f) {
fc->stack_inner_per = (1.0 - fc->stack_inner_per) *
fc->old_stack_inner_per /
(1.0 - fc->old_stack_inner_per);
fc->old_ismaster = false;
}
}
}
void set_size_per(Monitor *m, Client *c) {
Client *fc = NULL;
bool found = false;
@ -1114,7 +1019,7 @@ void reset_size_per_mon(Monitor *m, int32_t tile_cilent_num,
if (m->pertag->ltidxs[m->pertag->curtag]->id != CENTER_TILE) {
wl_list_for_each(c, &clients, link) {
if (VISIBLEON(c, m) && ISTILED(c)) {
if (VISIBLEON(c, m) && ISFAKETILED(c)) {
if (total_master_inner_percent > 0.0 && i < nmasters) {
c->ismaster = true;
@ -1137,7 +1042,7 @@ void reset_size_per_mon(Monitor *m, int32_t tile_cilent_num,
}
} else {
wl_list_for_each(c, &clients, link) {
if (VISIBLEON(c, m) && ISTILED(c)) {
if (VISIBLEON(c, m) && ISFAKETILED(c)) {
if (total_master_inner_percent > 0.0 && i < nmasters) {
c->ismaster = true;
@ -1196,6 +1101,7 @@ void pre_caculate_before_arrange(Monitor *m, bool want_animation,
m->visible_clients = 0;
m->visible_tiling_clients = 0;
m->visible_scroll_tiling_clients = 0;
m->visible_fake_tiling_clients = 0;
uint32_t tag = m->pertag->curtag;
struct TagScrollerState *st = m->pertag->scroller_state[tag];
@ -1239,6 +1145,10 @@ void pre_caculate_before_arrange(Monitor *m, bool want_animation,
m->visible_scroll_tiling_clients++;
}
}
if (ISFAKETILED(c)) {
m->visible_fake_tiling_clients++;
}
}
}
@ -1250,7 +1160,7 @@ void pre_caculate_before_arrange(Monitor *m, bool want_animation,
if (c->mon == m) {
if (VISIBLEON(c, m)) {
if (ISTILED(c)) {
if (ISFAKETILED(c)) {
if (i < nmasters) {
master_num++;
total_master_inner_percent += c->master_inner_per;