opt: format code

This commit is contained in:
DreamMaoMao 2026-06-16 08:20:55 +08:00
parent 71689f6ef4
commit 405e8dbc1a
3 changed files with 113 additions and 101 deletions

View file

@ -49,7 +49,7 @@ static void finish_exchange_arrange_and_focus(Client *c1, Client *c2,
wl_list_remove(&c2->flink);
wl_list_insert(&c1->flink, &c2->flink);
if (config.warpcursor)
if (config.warpcursor)
warp_cursor(c1);
}

View file

@ -131,12 +131,12 @@ int32_t exchange_stack_client(const Arg *arg) {
int32_t focusdir(const Arg *arg) {
if(!selmon)
if (!selmon)
return 0;
Client *c = NULL;
c = direction_select(arg);
if(!selmon->isoverview)
if (!selmon->isoverview)
c = get_focused_stack_client(c, arg->tc);
if (c) {
focusclient(c, 1);

View file

@ -164,117 +164,129 @@ Client *center_tiled_select(Monitor *m) {
return target_c;
}
Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating) {
Client *c = NULL;
Client *tempFocusClients = NULL;
Client *tempSameMonitorFocusClients = NULL;
int64_t distance = LLONG_MAX;
int64_t same_monitor_distance = LLONG_MAX;
Client *find_client_by_direction(Client *tc, const Arg *arg,
bool findfloating) {
Client *c = NULL;
Client *tempFocusClients = NULL;
Client *tempSameMonitorFocusClients = NULL;
int64_t distance = LLONG_MAX;
int64_t same_monitor_distance = LLONG_MAX;
int32_t tc_l = tc->geom.x;
int32_t tc_r = tc->geom.x + tc->geom.width;
int32_t tc_t = tc->geom.y;
int32_t tc_b = tc->geom.y + tc->geom.height;
int32_t tc_cx = tc_l + tc->geom.width / 2;
int32_t tc_cy = tc_t + tc->geom.height / 2;
int32_t tc_l = tc->geom.x;
int32_t tc_r = tc->geom.x + tc->geom.width;
int32_t tc_t = tc->geom.y;
int32_t tc_b = tc->geom.y + tc->geom.height;
int32_t tc_cx = tc_l + tc->geom.width / 2;
int32_t tc_cy = tc_t + tc->geom.height / 2;
for (int32_t step = 0; step < 2; step++) {
if (step == 1 && tempFocusClients)
break;
for (int32_t step = 0; step < 2; step++) {
if (step == 1 && tempFocusClients)
break;
wl_list_for_each(c, &clients, link) {
if (!c || c == tc)
continue;
if (!findfloating && c->isfloating)
continue;
if (c->isunglobal)
continue;
if (!config.focus_cross_monitor && c->mon != tc->mon)
continue;
if (!(c->tags & c->mon->tagset[c->mon->seltags]))
continue;
wl_list_for_each(c, &clients, link) {
if (!c || c == tc)
continue;
if (!findfloating && c->isfloating)
continue;
if (c->isunglobal)
continue;
if (!config.focus_cross_monitor && c->mon != tc->mon)
continue;
if (!(c->tags & c->mon->tagset[c->mon->seltags]))
continue;
if (step == 0 && ((!tc->mon->isoverview && !client_is_in_same_stack(tc, c, NULL)) || c->mon != tc->mon))
continue;
if (step == 0 && ((!tc->mon->isoverview &&
!client_is_in_same_stack(tc, c, NULL)) ||
c->mon != tc->mon))
continue;
int32_t c_l = c->geom.x;
int32_t c_r = c->geom.x + c->geom.width;
int32_t c_t = c->geom.y;
int32_t c_b = c->geom.y + c->geom.height;
int32_t c_cx = c_l + c->geom.width / 2;
int32_t c_cy = c_t + c->geom.height / 2;
int32_t c_l = c->geom.x;
int32_t c_r = c->geom.x + c->geom.width;
int32_t c_t = c->geom.y;
int32_t c_b = c->geom.y + c->geom.height;
int32_t c_cx = c_l + c->geom.width / 2;
int32_t c_cy = c_t + c->geom.height / 2;
int64_t main_dist = 0;
int64_t orth_dist = 0;
bool match_dir = false;
int64_t main_dist = 0;
int64_t orth_dist = 0;
bool match_dir = false;
switch (arg->i) {
case LEFT:
if (c_cx < tc_cx || (c_cx == tc_cx && c_l < tc_l)) {
match_dir = true;
main_dist = tc_l - c_r;
orth_dist = (c_b < tc_t) ? (tc_t - c_b) : ((c_t > tc_b) ? (c_t - tc_b) : 0);
}
break;
case RIGHT:
if (c_cx > tc_cx || (c_cx == tc_cx && c_l > tc_l)) {
match_dir = true;
main_dist = c_l - tc_r;
orth_dist = (c_b < tc_t) ? (tc_t - c_b) : ((c_t > tc_b) ? (c_t - tc_b) : 0);
}
break;
case UP:
if (c_cy < tc_cy || (c_cy == tc_cy && c_t < tc_t)) {
match_dir = true;
main_dist = tc_t - c_b;
orth_dist = (c_r < tc_l) ? (tc_l - c_r) : ((c_l > tc_r) ? (c_l - tc_r) : 0);
}
break;
case DOWN:
if (c_cy > tc_cy || (c_cy == tc_cy && c_t > tc_t)) {
match_dir = true;
main_dist = c_t - tc_b;
orth_dist = (c_r < tc_l) ? (tc_l - c_r) : ((c_l > tc_r) ? (c_l - tc_r) : 0);
}
break;
default:
continue;
}
switch (arg->i) {
case LEFT:
if (c_cx < tc_cx || (c_cx == tc_cx && c_l < tc_l)) {
match_dir = true;
main_dist = tc_l - c_r;
orth_dist = (c_b < tc_t)
? (tc_t - c_b)
: ((c_t > tc_b) ? (c_t - tc_b) : 0);
}
break;
case RIGHT:
if (c_cx > tc_cx || (c_cx == tc_cx && c_l > tc_l)) {
match_dir = true;
main_dist = c_l - tc_r;
orth_dist = (c_b < tc_t)
? (tc_t - c_b)
: ((c_t > tc_b) ? (c_t - tc_b) : 0);
}
break;
case UP:
if (c_cy < tc_cy || (c_cy == tc_cy && c_t < tc_t)) {
match_dir = true;
main_dist = tc_t - c_b;
orth_dist = (c_r < tc_l)
? (tc_l - c_r)
: ((c_l > tc_r) ? (c_l - tc_r) : 0);
}
break;
case DOWN:
if (c_cy > tc_cy || (c_cy == tc_cy && c_t > tc_t)) {
match_dir = true;
main_dist = c_t - tc_b;
orth_dist = (c_r < tc_l)
? (tc_l - c_r)
: ((c_l > tc_r) ? (c_l - tc_r) : 0);
}
break;
default:
continue;
}
if (!match_dir)
continue;
if (!match_dir)
continue;
int64_t penalty = 0;
if (main_dist < 0) {
penalty = 10000000000LL; // 主方向重叠(反方向)的极大惩罚
main_dist = -main_dist;
}
int64_t penalty = 0;
if (main_dist < 0) {
penalty = 10000000000LL; // 主方向重叠(反方向)的极大惩罚
main_dist = -main_dist;
}
// 正交方向无重叠惩罚,优先选择在同一行/列的窗口
int64_t no_overlap_penalty = 0;
if (orth_dist > 0) {
// LEFT/RIGHT 时 orth_dist 是垂直间距,>0 表示垂直无重叠
// UP/DOWN 时 orth_dist 是水平间距,>0 表示水平无重叠
no_overlap_penalty = 10000000LL;
}
// 正交方向无重叠惩罚,优先选择在同一行/列的窗口
int64_t no_overlap_penalty = 0;
if (orth_dist > 0) {
// LEFT/RIGHT 时 orth_dist 是垂直间距,>0 表示垂直无重叠
// UP/DOWN 时 orth_dist 是水平间距,>0 表示水平无重叠
no_overlap_penalty = 10000000LL;
}
int64_t tmp_distance = penalty + no_overlap_penalty
+ (main_dist * main_dist) + (orth_dist * orth_dist);
int64_t tmp_distance = penalty + no_overlap_penalty +
(main_dist * main_dist) +
(orth_dist * orth_dist);
if (tmp_distance < distance) {
distance = tmp_distance;
tempFocusClients = c;
}
if (c->mon == tc->mon && tmp_distance < same_monitor_distance) {
same_monitor_distance = tmp_distance;
tempSameMonitorFocusClients = c;
}
}
}
if (tmp_distance < distance) {
distance = tmp_distance;
tempFocusClients = c;
}
if (c->mon == tc->mon && tmp_distance < same_monitor_distance) {
same_monitor_distance = tmp_distance;
tempSameMonitorFocusClients = c;
}
}
}
if (tempSameMonitorFocusClients)
return tempSameMonitorFocusClients;
return tempFocusClients;
if (tempSameMonitorFocusClients)
return tempSameMonitorFocusClients;
return tempFocusClients;
}
Client *direction_select(const Arg *arg) {