feat: add global option center_master_overspread

This commit is contained in:
DreamMaoMao 2025-09-27 09:17:13 +08:00
parent 03eee2f4f1
commit d2b3e3a70b
3 changed files with 19 additions and 4 deletions

View file

@ -196,6 +196,7 @@ typedef struct {
float default_mfact;
float default_smfact;
unsigned int default_nmaster;
int center_master_overspread;
unsigned int hotarea_size;
unsigned int enable_hotarea;
@ -1198,6 +1199,8 @@ void parse_config_line(Config *config, const char *line) {
config->default_smfact = atof(value);
} else if (strcmp(key, "default_nmaster") == 0) {
config->default_nmaster = atoi(value);
} else if (strcmp(key, "center_master_overspread") == 0) {
config->center_master_overspread = atoi(value);
} else if (strcmp(key, "hotarea_size") == 0) {
config->hotarea_size = atoi(value);
} else if (strcmp(key, "enable_hotarea") == 0) {
@ -2350,6 +2353,7 @@ void override_config(void) {
default_mfact = CLAMP_FLOAT(config.default_mfact, 0.1f, 0.9f);
default_smfact = CLAMP_FLOAT(config.default_smfact, 0.1f, 0.9f);
default_nmaster = CLAMP_INT(config.default_nmaster, 1, 1000);
center_master_overspread = CLAMP_INT(config.center_master_overspread, 0, 1);
new_is_master = CLAMP_INT(config.new_is_master, 0, 1);
// 概述模式设置
@ -2497,6 +2501,8 @@ void set_value_default() {
config.default_mfact = default_mfact; // master 窗口比例
config.default_smfact = default_smfact; // 第一个stack比例
config.default_nmaster = default_nmaster; // 默认master数量
config.center_master_overspread =
center_master_overspread; // 中心master时是否铺满
config.numlockon = numlockon; // 是否打开右边小键盘

View file

@ -37,6 +37,7 @@ unsigned int new_is_master = 1; // 新窗口是否插在头部
double default_mfact = 0.55f; // master 窗口比例
double default_smfact = 0.5f; // 第一个stack窗口比例
unsigned int default_nmaster = 1; // 默认master数量
int center_master_overspread = 1; // 中心master时是否铺满
/* logging */
int log_level = WLR_ERROR;
unsigned int numlockon = 1; // 是否打开右边小键盘

View file

@ -460,23 +460,31 @@ void center_tile(Monitor *m) {
my = gappov;
tw = mw;
if (n > nmasters) {
// 计算主区域宽度
// 判断是否需要主区域铺满
int should_overspread = center_master_overspread && (n <= nmasters);
if (n > nmasters || !should_overspread) {
// 计算主区域宽度(居中模式)
mw = nmasters ? (m->w.width - 2 * gappoh - gappih) * mfact : 0;
if (n - nmasters > 1) {
// 多个堆叠窗口:主区域居中,左右两侧各有一个堆叠区域
tw = (m->w.width - mw - 2 * gappoh - gappih) / 2;
mx = gappoh + tw + gappih;
} else {
} else if (n - nmasters == 1) {
// 单个堆叠窗口:主区域居中,堆叠窗口在左,右边空着
tw = (m->w.width - mw - 2 * gappoh - gappih) / 2;
mx = gappoh + tw + gappih;
} else {
// 只有主区域窗口:居中显示
tw = (m->w.width - mw - 2 * gappoh - gappih) / 2;
mx = gappoh + tw + gappih;
}
} else {
// 所有窗口都在主区域
// 主区域铺满模式(只有主区域窗口时)
mw = m->w.width - 2 * gappoh;
mx = gappoh;
tw = 0; // 堆叠区域宽度为0
}
oty = gappov;