From f535332ee8e416ca711742e14366c3211974394e Mon Sep 17 00:00:00 2001 From: ernestoCruz05 Date: Sat, 9 May 2026 12:14:57 +0100 Subject: [PATCH] feat: opt-in config field to have typical dwindle tiling --- src/animation/client.h | 39 +++++++++++++++++++++++++++++++++++++++ src/config/parse_config.h | 5 +++++ src/mango.c | 2 +- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/animation/client.h b/src/animation/client.h index 9108c98c..97f0d6cd 100644 --- a/src/animation/client.h +++ b/src/animation/client.h @@ -538,6 +538,11 @@ void client_set_drop_area(Client *c) { struct wlr_box drop_box; + const Layout *cur_layout = + c->mon ? c->mon->pertag->ltidxs[c->mon->pertag->curtag] : NULL; + bool dwindle_familiar = + cur_layout && cur_layout->id == DWINDLE && !config.dwindle_smart_drop; + // 中心区域:x和y都在30%~70%之间 → 无方向 if (rel_x > client_width * 0.3 && rel_x < client_width * 0.7 && rel_y > client_height * 0.3 && rel_y < client_height * 0.7) { @@ -546,6 +551,40 @@ void client_set_drop_area(Client *c) { drop_box.width = client_width * 0.4; drop_box.height = client_height * 0.4; drop_direction = UNDIR; + } else if (dwindle_familiar) { + // Mirror dwindle_assign's split_h = (aw >= ah) rule so the preview + // matches the auto-rotated split that dwindle will produce. + bool split_h = c->geom.width >= c->geom.height; + float ratio = config.dwindle_split_ratio; + if (split_h) { + if (rel_x < client_width * 0.5) { + drop_direction = LEFT; + drop_box.x = bw; + drop_box.y = bw; + drop_box.width = (int32_t)(client_width * ratio); + drop_box.height = client_height; + } else { + drop_direction = RIGHT; + drop_box.x = bw + (int32_t)(client_width * ratio); + drop_box.y = bw; + drop_box.width = client_width - (int32_t)(client_width * ratio); + drop_box.height = client_height; + } + } else { + if (rel_y < client_height * 0.5) { + drop_direction = UP; + drop_box.x = bw; + drop_box.y = bw; + drop_box.width = client_width; + drop_box.height = (int32_t)(client_height * ratio); + } else { + drop_direction = DOWN; + drop_box.x = bw; + drop_box.y = bw + (int32_t)(client_height * ratio); + drop_box.width = client_width; + drop_box.height = client_height - (int32_t)(client_height * ratio); + } + } } else { // 否则根据到各边的距离决定方向 double dist_left = rel_x; diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 207d06f7..8d4300b6 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -248,6 +248,7 @@ typedef struct { int32_t dwindle_preserve_split; int32_t dwindle_smart_split; int32_t dwindle_smart_resize; + int32_t dwindle_smart_drop; float dwindle_split_ratio; uint32_t hotarea_size; @@ -1633,6 +1634,8 @@ bool parse_option(Config *config, char *key, char *value) { config->dwindle_smart_split = atoi(value); } else if (strcmp(key, "dwindle_smart_resize") == 0) { config->dwindle_smart_resize = atoi(value); + } else if (strcmp(key, "dwindle_smart_drop") == 0) { + config->dwindle_smart_drop = atoi(value); } else if (strcmp(key, "dwindle_split_ratio") == 0) { config->dwindle_split_ratio = atof(value); } else if (strcmp(key, "hotarea_size") == 0) { @@ -3205,6 +3208,7 @@ void override_config(void) { CLAMP_INT(config.dwindle_preserve_split, 0, 1); config.dwindle_smart_split = CLAMP_INT(config.dwindle_smart_split, 0, 1); config.dwindle_smart_resize = CLAMP_INT(config.dwindle_smart_resize, 0, 1); + config.dwindle_smart_drop = CLAMP_INT(config.dwindle_smart_drop, 0, 1); config.dwindle_split_ratio = CLAMP_FLOAT(config.dwindle_split_ratio, 0.05f, 0.95f); config.hotarea_size = CLAMP_INT(config.hotarea_size, 1, 1000); @@ -3351,6 +3355,7 @@ void set_value_default() { config.dwindle_preserve_split = 0; config.dwindle_smart_split = 0; config.dwindle_smart_resize = 0; + config.dwindle_smart_drop = 1; config.dwindle_split_ratio = 0.5f; config.log_level = WLR_ERROR; diff --git a/src/mango.c b/src/mango.c index 17b99dca..d518fbbf 100644 --- a/src/mango.c +++ b/src/mango.c @@ -2229,7 +2229,7 @@ void place_drag_tile_client(Client *c) { closest->drop_direction == RIGHT); dwindle_insert(&c->mon->pertag->dwindle_root[tag], c, closest, config.dwindle_split_ratio, insert_before, split_h, - true); + config.dwindle_smart_drop); setfloating(c, 0); return; }