mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-05-09 23:50:21 -04:00
opt: more simple drop area
This commit is contained in:
parent
37bd0acb95
commit
ec7d3f63c7
1 changed files with 61 additions and 25 deletions
|
|
@ -408,6 +408,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;
|
||||
}
|
||||
|
|
@ -432,22 +435,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) {
|
||||
|
|
@ -476,46 +478,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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue