opt: more simple drop area

This commit is contained in:
DreamMaoMao 2026-05-09 22:16:00 +08:00
parent 637dc0a09a
commit b0f8d3f8a3

View file

@ -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;
}