From b0f8d3f8a3f9655a63a6b4061889b85843d9cb4d Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Sat, 9 May 2026 22:16:00 +0800 Subject: [PATCH] opt: more simple drop area --- src/animation/client.h | 86 ++++++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 25 deletions(-) diff --git a/src/animation/client.h b/src/animation/client.h index ba48959d..8ce81cd2 100644 --- a/src/animation/client.h +++ b/src/animation/client.h @@ -514,6 +514,9 @@ void client_set_drop_area(Client *c) { bool first_draw = false; int32_t drop_direction = UNDIR; + if (!c || !c->mon) + return; + if (!c->enable_drop_area_draw && !c->droparea->node.enabled) { return; } @@ -538,22 +541,21 @@ 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_drop_simple_split; + const Layout *cur_layout = c->mon->pertag->ltidxs[c->mon->pertag->curtag]; + bool dwindle_familiar = + cur_layout->id == DWINDLE && config.dwindle_drop_simple_split; - // 中心区域: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) { - drop_box.x = bw + client_width * 0.3; - drop_box.y = bw + client_height * 0.3; - 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. + uint32_t nmaster = c->mon->pertag->nmasters[c->mon->pertag->curtag]; + + bool should_swap = + (cur_layout->id == DECK || cur_layout->id == VERTICAL_DECK || + cur_layout->id == MONOCLE || cur_layout->id == GRID || + cur_layout->id == VERTICAL_GRID) || + ((cur_layout->id == TILE || cur_layout->id == VERTICAL_TILE || + cur_layout->id == CENTER_TILE || cur_layout->id == RIGHT_TILE) && + nmaster == 1 && c->ismaster); + + if (dwindle_familiar) { bool split_h = c->geom.width >= c->geom.height; float ratio = config.dwindle_split_ratio; if (split_h) { @@ -582,46 +584,80 @@ void client_set_drop_area(Client *c) { 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); + drop_box.height = + client_height - (int32_t)(client_height * ratio); } } + } else if (should_swap) { + drop_box.x = bw; + drop_box.y = bw; + drop_box.width = client_width; + drop_box.height = client_height; + drop_direction = UNDIR; + } else if (cur_layout->id == TILE || cur_layout->id == DECK || + cur_layout->id == CENTER_TILE || cur_layout->id == RIGHT_TILE) { + 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 = client_height / 2; + } else { + drop_direction = DOWN; + drop_box.x = bw; + drop_box.y = bw + client_height / 2; + drop_box.width = client_width; + drop_box.height = client_height / 2; + } + } else if (cur_layout->id == VERTICAL_TILE || + cur_layout->id == VERTICAL_DECK) { + if (rel_x < client_width * 0.5) { + drop_direction = LEFT; + drop_box.x = bw; + drop_box.y = bw; + drop_box.width = client_width / 2; + drop_box.height = client_height; + } else { + drop_direction = RIGHT; + drop_box.x = bw + client_width / 2; + drop_box.y = bw; + drop_box.width = client_width / 2; + drop_box.height = client_height; + } } else { - // 否则根据到各边的距离决定方向 double dist_left = rel_x; double dist_right = client_width - rel_x; double dist_top = rel_y; double dist_bottom = client_height - rel_y; - // 找出最小距离的方向(相等时按左、右、上、下的优先级顺序) if (dist_left <= dist_right && dist_left <= dist_top && dist_left <= dist_bottom) { drop_direction = LEFT; drop_box.x = bw; drop_box.y = bw; - drop_box.width = client_width * 0.3; + drop_box.width = client_width / 2; drop_box.height = client_height; } else if (dist_right <= dist_top && dist_right <= dist_bottom) { drop_direction = RIGHT; - drop_box.x = bw + client_width * 0.7; + drop_box.x = bw + client_width / 2; drop_box.y = bw; - drop_box.width = client_width * 0.3; + drop_box.width = client_width / 2; drop_box.height = client_height; } else if (dist_top <= dist_bottom) { drop_direction = UP; drop_box.x = bw; drop_box.y = bw; drop_box.width = client_width; - drop_box.height = client_height * 0.3; + drop_box.height = client_height / 2; } else { drop_direction = DOWN; drop_box.x = bw; - drop_box.y = bw + client_height * 0.7; + drop_box.y = bw + client_height / 2; drop_box.width = client_width; - drop_box.height = client_height * 0.3; + drop_box.height = client_height / 2; } } - // 如果方向和上次相同且不是第一次绘制,则跳过更新 if (!first_draw && c->drop_direction == drop_direction) { return; }