opt: support restore size per when master change

This commit is contained in:
DreamMaoMao 2026-03-05 11:47:17 +08:00
parent bf10fabfc2
commit 0f68187cd0
2 changed files with 74 additions and 20 deletions

View file

@ -1,11 +1,31 @@
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;
}
}
}
void restore_size_per(Monitor *m, Client *c) { void restore_size_per(Monitor *m, Client *c) {
Client *fc = NULL; Client *fc = NULL;
double total_master_inner_per = 0;
double total_stack_inner_per = 0;
if (!m || !c) if (!m || !c)
return; 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]; const Layout *current_layout = m->pertag->ltidxs[m->pertag->curtag];
if (current_layout->id == SCROLLER || if (current_layout->id == SCROLLER ||
@ -15,7 +35,7 @@ void restore_size_per(Monitor *m, Client *c) {
return; return;
} }
if (current_layout->id == CENTER_TILE || c->ismaster) { if (current_layout->id == CENTER_TILE) {
wl_list_for_each(fc, &clients, link) { wl_list_for_each(fc, &clients, link) {
if (VISIBLEON(fc, m) && ISTILED(fc) && !c->ismaster) { if (VISIBLEON(fc, m) && ISTILED(fc) && !c->ismaster) {
set_size_per(m, fc); set_size_per(m, fc);
@ -24,19 +44,28 @@ void restore_size_per(Monitor *m, Client *c) {
return; return;
} }
wl_list_for_each(fc, &clients, link) { if (!c->ismaster && c->old_stack_inner_per < 1.0 &&
if (VISIBLEON(fc, m) && ISTILED(fc) && fc != c) { c->stack_inner_per < 1.0) {
if (fc->ismaster) { c->stack_inner_per = (1.0 - c->stack_inner_per) *
total_master_inner_per += fc->master_inner_per; c->old_stack_inner_per /
} else { (1.0 - c->old_stack_inner_per);
total_stack_inner_per += fc->stack_inner_per;
}
}
} }
if (!c->ismaster && total_stack_inner_per) { if (c->ismaster && c->old_master_inner_per < 1.0 &&
c->stack_inner_per = total_stack_inner_per * c->stack_inner_per / c->master_inner_per < 1.0) {
(1 - c->stack_inner_per); 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->stack_inner_per < 1.0) {
fc->stack_inner_per = (1.0 - fc->stack_inner_per) *
fc->old_stack_inner_per /
(1.0 - fc->old_stack_inner_per);
}
} }
} }
@ -705,8 +734,8 @@ void reset_size_per_mon(Monitor *m, int32_t tile_cilent_num,
} }
} }
void // 17 void pre_caculate_before_arrange(Monitor *m, bool want_animation,
arrange(Monitor *m, bool want_animation, bool from_view) { bool from_view, bool only_caculate) {
Client *c = NULL; Client *c = NULL;
double total_stack_inner_percent = 0; double total_stack_inner_percent = 0;
double total_master_inner_percent = 0; double total_master_inner_percent = 0;
@ -795,14 +824,17 @@ arrange(Monitor *m, bool want_animation, bool from_view) {
i++; i++;
} }
set_arrange_visible(m, c, want_animation); if (!only_caculate)
set_arrange_visible(m, c, want_animation);
} else { } else {
set_arrange_hidden(m, c, want_animation); if (!only_caculate)
set_arrange_hidden(m, c, want_animation);
} }
} }
if (c->mon == m && c->ismaximizescreen && !c->animation.tagouted && if (!only_caculate && c->mon == m && c->ismaximizescreen &&
!c->animation.tagouting && VISIBLEON(c, m)) { !c->animation.tagouted && !c->animation.tagouting &&
VISIBLEON(c, m)) {
reset_maximizescreen_size(c); reset_maximizescreen_size(c);
} }
} }
@ -811,6 +843,12 @@ arrange(Monitor *m, bool want_animation, bool from_view) {
m, m->visible_tiling_clients, total_left_stack_hight_percent, m, m->visible_tiling_clients, total_left_stack_hight_percent,
total_right_stack_hight_percent, total_stack_inner_percent, total_right_stack_hight_percent, total_stack_inner_percent,
total_master_inner_percent, master_num, stack_num); total_master_inner_percent, master_num, stack_num);
}
void // 17
arrange(Monitor *m, bool want_animation, bool from_view) {
pre_caculate_before_arrange(m, want_animation, from_view, false);
if (m->isoverview) { if (m->isoverview) {
overviewlayout.arrange(m); overviewlayout.arrange(m);

View file

@ -412,6 +412,7 @@ struct Client {
double old_master_mfact_per, old_master_inner_per, old_stack_inner_per; double old_master_mfact_per, old_master_inner_per, old_stack_inner_per;
double old_scroller_pproportion; double old_scroller_pproportion;
bool ismaster; bool ismaster;
bool old_ismaster;
bool cursor_in_upper_half, cursor_in_left_half; bool cursor_in_upper_half, cursor_in_left_half;
bool isleftstack; bool isleftstack;
int32_t tearing_hint; int32_t tearing_hint;
@ -803,6 +804,8 @@ static void last_cursor_surface_destroy(struct wl_listener *listener,
void *data); void *data);
static int32_t keep_idle_inhibit(void *data); static int32_t keep_idle_inhibit(void *data);
static void check_keep_idle_inhibit(Client *c); static void check_keep_idle_inhibit(Client *c);
static void pre_caculate_before_arrange(Monitor *m, bool want_animation,
bool from_view, bool only_caculate);
#include "data/static_keymap.h" #include "data/static_keymap.h"
#include "dispatch/bind_declare.h" #include "dispatch/bind_declare.h"
@ -3981,6 +3984,7 @@ void init_client_properties(Client *c) {
c->swallowing = NULL; c->swallowing = NULL;
c->swallowedby = NULL; c->swallowedby = NULL;
c->ismaster = 0; c->ismaster = 0;
c->old_ismaster = 0;
c->isleftstack = 0; c->isleftstack = 0;
c->ismaximizescreen = 0; c->ismaximizescreen = 0;
c->isfullscreen = 0; c->isfullscreen = 0;
@ -5047,6 +5051,10 @@ setfloating(Client *c, int32_t floating) {
restore_size_per(c->mon, c); restore_size_per(c->mon, c);
} }
if (c->isfloating && !old_floating_state) {
save_old_size_per(c->mon);
}
if (!c->force_maximize) if (!c->force_maximize)
client_set_maximized(c, false); client_set_maximized(c, false);
@ -5133,6 +5141,10 @@ void setmaximizescreen(Client *c, int32_t maximizescreen) {
restore_size_per(c->mon, c); restore_size_per(c->mon, c);
} }
if (c->ismaximizescreen && !old_maximizescreen_state) {
save_old_size_per(c->mon);
}
if (!c->force_maximize && !c->ismaximizescreen) { if (!c->force_maximize && !c->ismaximizescreen) {
client_set_maximized(c, false); client_set_maximized(c, false);
} else if (!c->force_maximize && c->ismaximizescreen) { } else if (!c->force_maximize && c->ismaximizescreen) {
@ -5204,6 +5216,10 @@ void setfullscreen(Client *c, int32_t fullscreen) // 用自定义全屏代理自
restore_size_per(c->mon, c); restore_size_per(c->mon, c);
} }
if (c->isfullscreen && !old_fullscreen_state) {
save_old_size_per(c->mon);
}
arrange(c->mon, false, false); arrange(c->mon, false, false);
} }