diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 29fbb1e..84914a5 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -197,6 +197,7 @@ typedef struct { float default_smfact; unsigned int default_nmaster; int center_master_overspread; + int center_when_single_slave; unsigned int hotarea_size; unsigned int enable_hotarea; @@ -1201,6 +1202,8 @@ void parse_config_line(Config *config, const char *line) { config->default_nmaster = atoi(value); } else if (strcmp(key, "center_master_overspread") == 0) { config->center_master_overspread = atoi(value); + } else if (strcmp(key, "center_when_single_slave") == 0) { + config->center_when_single_slave = atoi(value); } else if (strcmp(key, "hotarea_size") == 0) { config->hotarea_size = atoi(value); } else if (strcmp(key, "enable_hotarea") == 0) { @@ -2354,6 +2357,7 @@ void override_config(void) { 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); + center_when_single_slave = CLAMP_INT(config.center_when_single_slave, 0, 1); new_is_master = CLAMP_INT(config.new_is_master, 0, 1); // 概述模式设置 @@ -2503,6 +2507,8 @@ void set_value_default() { config.default_nmaster = default_nmaster; // 默认master数量 config.center_master_overspread = center_master_overspread; // 中心master时是否铺满 + config.center_when_single_slave = + center_when_single_slave; // 单个slave时是否居中 config.numlockon = numlockon; // 是否打开右边小键盘 diff --git a/src/config/preset.h b/src/config/preset.h index 609d6aa..57ed80d 100644 --- a/src/config/preset.h +++ b/src/config/preset.h @@ -38,6 +38,7 @@ double default_mfact = 0.55f; // master 窗口比例 double default_smfact = 0.5f; // 第一个stack窗口比例 unsigned int default_nmaster = 1; // 默认master数量 int center_master_overspread = 0; // 中心master时是否铺满 +int center_when_single_slave = 1; // 单个slave时是否居中 /* logging */ int log_level = WLR_ERROR; unsigned int numlockon = 1; // 是否打开右边小键盘 diff --git a/src/layout/horizontal.h b/src/layout/horizontal.h index 941f034..f23f09d 100644 --- a/src/layout/horizontal.h +++ b/src/layout/horizontal.h @@ -472,9 +472,16 @@ void center_tile(Monitor *m) { tw = (m->w.width - mw - 2 * gappoh - gappih) / 2; mx = gappoh + tw + gappih; } else if (n - nmasters == 1) { - // 单个堆叠窗口:主区域居中,堆叠窗口在左,右边空着 - tw = (m->w.width - mw - 2 * gappoh - gappih) / 2; - mx = gappoh + tw + gappih; + // 单个堆叠窗口的处理 + if (center_when_single_slave) { + // 启用选项:主区域居中,堆叠窗口在左,右边空着 + tw = (m->w.width - mw - 2 * gappoh - gappih) / 2; + mx = gappoh + tw + gappih; + } else { + // 修改:slave在右边,master在左边 + tw = m->w.width - mw - 2 * gappoh - gappih; + mx = gappoh; // master在左边 + } } else { // 只有主区域窗口:居中显示 tw = (m->w.width - mw - 2 * gappoh - gappih) / 2; @@ -512,11 +519,19 @@ void center_tile(Monitor *m) { unsigned int stack_index = i - nmasters; if (n - nmasters == 1) { - // 单个堆叠窗口:放在左侧 + // 单个堆叠窗口 unsigned int r = n - i; h = (m->w.height - ety - gappov - gappiv * (r - 1)) / r; - int stack_x = m->w.x + gappoh; // 左侧位置 + int stack_x; + if (center_when_single_slave) { + // 启用选项:放在左侧 + stack_x = m->w.x + gappoh; + } else { + // 修改:放在右侧 + stack_x = m->w.x + mx + mw + gappih; + } + resize(c, (struct wlr_box){.x = stack_x, .y = m->w.y + ety, @@ -528,8 +543,8 @@ void center_tile(Monitor *m) { // 多个堆叠窗口:交替放在左右两侧 unsigned int r = (n - i + 1) / 2; - // 当n为奇数时翻转判断逻辑 - if ((stack_index % 2) ^ (n % 2 != 0)) { + // 当n为偶数时翻转判断逻辑 + if ((stack_index % 2) ^ (n % 2 == 0)) { // 右侧堆叠窗口 h = (m->w.height - ety - gappov - gappiv * (r - 1)) / r; int stack_x = m->w.x + mx + mw + gappih;