directionalmove.c (3081B)
1 void 2 movedir(const Arg *arg) 3 { 4 if (selmon->lt[selmon->sellt]->arrange != tile) return; 5 Client *s = selmon->sel, *f = NULL, *c, *next; 6 if (!s) 7 return; 8 unsigned int score = -1; 9 unsigned int client_score; 10 int dist; 11 int dirweight = 20; 12 int isfloating = s->isfloating; 13 next = s->next; 14 if (!next) 15 next = s->mon->clients; 16 for (c = next; c != s; c = next) { 17 next = c->next; 18 if (!next) 19 next = s->mon->clients; 20 if (!ISVISIBLE(c) || c->isfloating != isfloating) 21 continue; 22 switch (arg->i) { 23 case 0: // left 24 dist = s->x - c->x - c->w; 25 client_score = 26 dirweight * MIN(abs(dist), abs(dist + s->mon->ww)) + 27 abs(s->y - c->y); 28 break; 29 case 1: // right 30 dist = c->x - s->x - s->w; 31 client_score = 32 dirweight * MIN(abs(dist), abs(dist + s->mon->ww)) + 33 abs(c->y - s->y); 34 break; 35 case 2: // up 36 dist = s->y - c->y - c->h; 37 client_score = 38 dirweight * MIN(abs(dist), abs(dist + s->mon->wh)) + 39 abs(s->x - c->x); 40 break; 41 default: 42 case 3: // down 43 dist = c->y - s->y - s->h; 44 client_score = 45 dirweight * MIN(abs(dist), abs(dist + s->mon->wh)) + 46 abs(c->x - s->x); 47 break; 48 } 49 if (((arg->i == 0 || arg->i == 2) && client_score <= score) || client_score < score) { 50 score = client_score; 51 f = c; 52 } 53 } 54 if (!f || f == s) 55 return; 56 57 Client *ps = NULL, *pf = NULL, *p; 58 for (p = s->mon->clients; p; p = p->next) { 59 if (p->next == s) ps = p; 60 if (p->next == f) pf = p; 61 } 62 63 if (s->next == f) { 64 if (ps) ps->next = f; else s->mon->clients = f; 65 s->next = f->next; 66 f->next = s; 67 } else if (f->next == s) { 68 if (pf) pf->next = s; else s->mon->clients = s; 69 f->next = s->next; 70 s->next = f; 71 } else { 72 if (ps) ps->next = f; else s->mon->clients = f; 73 if (pf) pf->next = s; else s->mon->clients = s; 74 Client *tmp = s->next; 75 s->next = f->next; 76 f->next = tmp; 77 } 78 79 focus(s); 80 #if WARP_TO_CLIENT && WARP_TO_CENTER_OF_WINDOW_AFFECTED_BY_FOCUSSTACK 81 warptoclient(f); 82 #endif 83 arrange(s->mon); 84 }