placedir.c (1984B)
1 void 2 placedir(const Arg *arg) 3 { 4 Client *s = selmon->sel, *f = NULL, *c, *next, *fprior, *sprior; 5 6 if (!s || s->isfloating) 7 return; 8 9 unsigned int score = -1; 10 unsigned int client_score; 11 int dist; 12 int dirweight = 20; 13 14 next = s->next; 15 if (!next) 16 next = s->mon->clients; 17 for (c = next; c != s; c = next) { 18 19 next = c->next; 20 if (!next) 21 next = s->mon->clients; 22 23 if (!ISVISIBLE(c)) // || HIDDEN(c) 24 continue; 25 26 switch (arg->i) { 27 case 0: // left 28 dist = s->x - c->x - c->w; 29 client_score = 30 dirweight * MIN(abs(dist), abs(dist + s->mon->ww)) + 31 abs(s->y - c->y); 32 break; 33 case 1: // right 34 dist = c->x - s->x - s->w; 35 client_score = 36 dirweight * MIN(abs(dist), abs(dist + s->mon->ww)) + 37 abs(c->y - s->y); 38 break; 39 case 2: // up 40 dist = s->y - c->y - c->h; 41 client_score = 42 dirweight * MIN(abs(dist), abs(dist + s->mon->wh)) + 43 abs(s->x - c->x); 44 break; 45 default: 46 case 3: // down 47 dist = c->y - s->y - s->h; 48 client_score = 49 dirweight * MIN(abs(dist), abs(dist + s->mon->wh)) + 50 abs(c->x - s->x); 51 break; 52 } 53 54 if (((arg->i == 0 || arg->i == 2) && client_score <= score) || client_score < score) { 55 score = client_score; 56 f = c; 57 } 58 } 59 60 if (f && f != s) { 61 for (fprior = f->mon->clients; fprior && fprior->next != f; fprior = fprior->next); 62 for (sprior = s->mon->clients; sprior && sprior->next != s; sprior = sprior->next); 63 64 if (s == fprior) { 65 next = f->next; 66 if (sprior) 67 sprior->next = f; 68 else 69 f->mon->clients = f; 70 f->next = s; 71 s->next = next; 72 } else if (f == sprior) { 73 next = s->next; 74 if (fprior) 75 fprior->next = s; 76 else 77 s->mon->clients = s; 78 s->next = f; 79 f->next = next; 80 } else { // clients are not adjacent to each other 81 next = f->next; 82 f->next = s->next; 83 s->next = next; 84 if (fprior) 85 fprior->next = s; 86 else 87 s->mon->clients = s; 88 if (sprior) 89 sprior->next = f; 90 else 91 f->mon->clients = f; 92 } 93 94 arrange(f->mon); 95 } 96 }