mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-06-16 14:33:36 -04:00
opt: format code
This commit is contained in:
parent
71689f6ef4
commit
405e8dbc1a
3 changed files with 113 additions and 101 deletions
|
|
@ -131,12 +131,12 @@ int32_t exchange_stack_client(const Arg *arg) {
|
||||||
|
|
||||||
int32_t focusdir(const Arg *arg) {
|
int32_t focusdir(const Arg *arg) {
|
||||||
|
|
||||||
if(!selmon)
|
if (!selmon)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
Client *c = NULL;
|
Client *c = NULL;
|
||||||
c = direction_select(arg);
|
c = direction_select(arg);
|
||||||
if(!selmon->isoverview)
|
if (!selmon->isoverview)
|
||||||
c = get_focused_stack_client(c, arg->tc);
|
c = get_focused_stack_client(c, arg->tc);
|
||||||
if (c) {
|
if (c) {
|
||||||
focusclient(c, 1);
|
focusclient(c, 1);
|
||||||
|
|
|
||||||
|
|
@ -164,117 +164,129 @@ Client *center_tiled_select(Monitor *m) {
|
||||||
return target_c;
|
return target_c;
|
||||||
}
|
}
|
||||||
|
|
||||||
Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating) {
|
Client *find_client_by_direction(Client *tc, const Arg *arg,
|
||||||
Client *c = NULL;
|
bool findfloating) {
|
||||||
Client *tempFocusClients = NULL;
|
Client *c = NULL;
|
||||||
Client *tempSameMonitorFocusClients = NULL;
|
Client *tempFocusClients = NULL;
|
||||||
int64_t distance = LLONG_MAX;
|
Client *tempSameMonitorFocusClients = NULL;
|
||||||
int64_t same_monitor_distance = LLONG_MAX;
|
int64_t distance = LLONG_MAX;
|
||||||
|
int64_t same_monitor_distance = LLONG_MAX;
|
||||||
|
|
||||||
int32_t tc_l = tc->geom.x;
|
int32_t tc_l = tc->geom.x;
|
||||||
int32_t tc_r = tc->geom.x + tc->geom.width;
|
int32_t tc_r = tc->geom.x + tc->geom.width;
|
||||||
int32_t tc_t = tc->geom.y;
|
int32_t tc_t = tc->geom.y;
|
||||||
int32_t tc_b = tc->geom.y + tc->geom.height;
|
int32_t tc_b = tc->geom.y + tc->geom.height;
|
||||||
int32_t tc_cx = tc_l + tc->geom.width / 2;
|
int32_t tc_cx = tc_l + tc->geom.width / 2;
|
||||||
int32_t tc_cy = tc_t + tc->geom.height / 2;
|
int32_t tc_cy = tc_t + tc->geom.height / 2;
|
||||||
|
|
||||||
for (int32_t step = 0; step < 2; step++) {
|
for (int32_t step = 0; step < 2; step++) {
|
||||||
if (step == 1 && tempFocusClients)
|
if (step == 1 && tempFocusClients)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
wl_list_for_each(c, &clients, link) {
|
wl_list_for_each(c, &clients, link) {
|
||||||
if (!c || c == tc)
|
if (!c || c == tc)
|
||||||
continue;
|
continue;
|
||||||
if (!findfloating && c->isfloating)
|
if (!findfloating && c->isfloating)
|
||||||
continue;
|
continue;
|
||||||
if (c->isunglobal)
|
if (c->isunglobal)
|
||||||
continue;
|
continue;
|
||||||
if (!config.focus_cross_monitor && c->mon != tc->mon)
|
if (!config.focus_cross_monitor && c->mon != tc->mon)
|
||||||
continue;
|
continue;
|
||||||
if (!(c->tags & c->mon->tagset[c->mon->seltags]))
|
if (!(c->tags & c->mon->tagset[c->mon->seltags]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (step == 0 && ((!tc->mon->isoverview && !client_is_in_same_stack(tc, c, NULL)) || c->mon != tc->mon))
|
if (step == 0 && ((!tc->mon->isoverview &&
|
||||||
continue;
|
!client_is_in_same_stack(tc, c, NULL)) ||
|
||||||
|
c->mon != tc->mon))
|
||||||
|
continue;
|
||||||
|
|
||||||
int32_t c_l = c->geom.x;
|
int32_t c_l = c->geom.x;
|
||||||
int32_t c_r = c->geom.x + c->geom.width;
|
int32_t c_r = c->geom.x + c->geom.width;
|
||||||
int32_t c_t = c->geom.y;
|
int32_t c_t = c->geom.y;
|
||||||
int32_t c_b = c->geom.y + c->geom.height;
|
int32_t c_b = c->geom.y + c->geom.height;
|
||||||
int32_t c_cx = c_l + c->geom.width / 2;
|
int32_t c_cx = c_l + c->geom.width / 2;
|
||||||
int32_t c_cy = c_t + c->geom.height / 2;
|
int32_t c_cy = c_t + c->geom.height / 2;
|
||||||
|
|
||||||
int64_t main_dist = 0;
|
int64_t main_dist = 0;
|
||||||
int64_t orth_dist = 0;
|
int64_t orth_dist = 0;
|
||||||
bool match_dir = false;
|
bool match_dir = false;
|
||||||
|
|
||||||
switch (arg->i) {
|
switch (arg->i) {
|
||||||
case LEFT:
|
case LEFT:
|
||||||
if (c_cx < tc_cx || (c_cx == tc_cx && c_l < tc_l)) {
|
if (c_cx < tc_cx || (c_cx == tc_cx && c_l < tc_l)) {
|
||||||
match_dir = true;
|
match_dir = true;
|
||||||
main_dist = tc_l - c_r;
|
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);
|
orth_dist = (c_b < tc_t)
|
||||||
}
|
? (tc_t - c_b)
|
||||||
break;
|
: ((c_t > tc_b) ? (c_t - tc_b) : 0);
|
||||||
case RIGHT:
|
}
|
||||||
if (c_cx > tc_cx || (c_cx == tc_cx && c_l > tc_l)) {
|
break;
|
||||||
match_dir = true;
|
case RIGHT:
|
||||||
main_dist = c_l - tc_r;
|
if (c_cx > tc_cx || (c_cx == tc_cx && c_l > tc_l)) {
|
||||||
orth_dist = (c_b < tc_t) ? (tc_t - c_b) : ((c_t > tc_b) ? (c_t - tc_b) : 0);
|
match_dir = true;
|
||||||
}
|
main_dist = c_l - tc_r;
|
||||||
break;
|
orth_dist = (c_b < tc_t)
|
||||||
case UP:
|
? (tc_t - c_b)
|
||||||
if (c_cy < tc_cy || (c_cy == tc_cy && c_t < tc_t)) {
|
: ((c_t > tc_b) ? (c_t - tc_b) : 0);
|
||||||
match_dir = true;
|
}
|
||||||
main_dist = tc_t - c_b;
|
break;
|
||||||
orth_dist = (c_r < tc_l) ? (tc_l - c_r) : ((c_l > tc_r) ? (c_l - tc_r) : 0);
|
case UP:
|
||||||
}
|
if (c_cy < tc_cy || (c_cy == tc_cy && c_t < tc_t)) {
|
||||||
break;
|
match_dir = true;
|
||||||
case DOWN:
|
main_dist = tc_t - c_b;
|
||||||
if (c_cy > tc_cy || (c_cy == tc_cy && c_t > tc_t)) {
|
orth_dist = (c_r < tc_l)
|
||||||
match_dir = true;
|
? (tc_l - c_r)
|
||||||
main_dist = c_t - tc_b;
|
: ((c_l > tc_r) ? (c_l - tc_r) : 0);
|
||||||
orth_dist = (c_r < tc_l) ? (tc_l - c_r) : ((c_l > tc_r) ? (c_l - tc_r) : 0);
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case DOWN:
|
||||||
default:
|
if (c_cy > tc_cy || (c_cy == tc_cy && c_t > tc_t)) {
|
||||||
continue;
|
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)
|
if (!match_dir)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int64_t penalty = 0;
|
int64_t penalty = 0;
|
||||||
if (main_dist < 0) {
|
if (main_dist < 0) {
|
||||||
penalty = 10000000000LL; // 主方向重叠(反方向)的极大惩罚
|
penalty = 10000000000LL; // 主方向重叠(反方向)的极大惩罚
|
||||||
main_dist = -main_dist;
|
main_dist = -main_dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 正交方向无重叠惩罚,优先选择在同一行/列的窗口
|
// 正交方向无重叠惩罚,优先选择在同一行/列的窗口
|
||||||
int64_t no_overlap_penalty = 0;
|
int64_t no_overlap_penalty = 0;
|
||||||
if (orth_dist > 0) {
|
if (orth_dist > 0) {
|
||||||
// LEFT/RIGHT 时 orth_dist 是垂直间距,>0 表示垂直无重叠
|
// LEFT/RIGHT 时 orth_dist 是垂直间距,>0 表示垂直无重叠
|
||||||
// UP/DOWN 时 orth_dist 是水平间距,>0 表示水平无重叠
|
// UP/DOWN 时 orth_dist 是水平间距,>0 表示水平无重叠
|
||||||
no_overlap_penalty = 10000000LL;
|
no_overlap_penalty = 10000000LL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t tmp_distance = penalty + no_overlap_penalty
|
int64_t tmp_distance = penalty + no_overlap_penalty +
|
||||||
+ (main_dist * main_dist) + (orth_dist * orth_dist);
|
(main_dist * main_dist) +
|
||||||
|
(orth_dist * orth_dist);
|
||||||
|
|
||||||
if (tmp_distance < distance) {
|
if (tmp_distance < distance) {
|
||||||
distance = tmp_distance;
|
distance = tmp_distance;
|
||||||
tempFocusClients = c;
|
tempFocusClients = c;
|
||||||
}
|
}
|
||||||
if (c->mon == tc->mon && tmp_distance < same_monitor_distance) {
|
if (c->mon == tc->mon && tmp_distance < same_monitor_distance) {
|
||||||
same_monitor_distance = tmp_distance;
|
same_monitor_distance = tmp_distance;
|
||||||
tempSameMonitorFocusClients = c;
|
tempSameMonitorFocusClients = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tempSameMonitorFocusClients)
|
if (tempSameMonitorFocusClients)
|
||||||
return tempSameMonitorFocusClients;
|
return tempSameMonitorFocusClients;
|
||||||
return tempFocusClients;
|
return tempFocusClients;
|
||||||
}
|
}
|
||||||
|
|
||||||
Client *direction_select(const Arg *arg) {
|
Client *direction_select(const Arg *arg) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue