dwm

Kris's build of dwm
git clone git clone https://git.krisyotam.com/krisyotam/dwm.git
Log | Files | Refs | README | LICENSE

focusdir.c (1298B)


      1 void
      2 focusdir(const Arg *arg)
      3 {
      4 	Client *s = selmon->sel, *f = NULL, *c, *next;
      5 
      6 	if (!s)
      7 		return;
      8 
      9 	unsigned int score = -1;
     10 	unsigned int client_score;
     11 	int dist;
     12 	int dirweight = 20;
     13 	int isfloating = s->isfloating;
     14 
     15 	next = s->next;
     16 	if (!next)
     17 		next = s->mon->clients;
     18 	for (c = next; c != s; c = next) {
     19 
     20 		next = c->next;
     21 		if (!next)
     22 			next = s->mon->clients;
     23 
     24 		if (!ISVISIBLE(c) || c->isfloating != isfloating) // || HIDDEN(c)
     25 			continue;
     26 
     27 		switch (arg->i) {
     28 		case 0: // left
     29 			dist = s->x - c->x - c->w;
     30 			client_score =
     31 				dirweight * MIN(abs(dist), abs(dist + s->mon->ww)) +
     32 				abs(s->y - c->y);
     33 			break;
     34 		case 1: // right
     35 			dist = c->x - s->x - s->w;
     36 			client_score =
     37 				dirweight * MIN(abs(dist), abs(dist + s->mon->ww)) +
     38 				abs(c->y - s->y);
     39 			break;
     40 		case 2: // up
     41 			dist = s->y - c->y - c->h;
     42 			client_score =
     43 				dirweight * MIN(abs(dist), abs(dist + s->mon->wh)) +
     44 				abs(s->x - c->x);
     45 			break;
     46 		default:
     47 		case 3: // down
     48 			dist = c->y - s->y - s->h;
     49 			client_score =
     50 				dirweight * MIN(abs(dist), abs(dist + s->mon->wh)) +
     51 				abs(c->x - s->x);
     52 			break;
     53 		}
     54 
     55 		if (((arg->i == 0 || arg->i == 2) && client_score <= score) || client_score < score) {
     56 			score = client_score;
     57 			f = c;
     58 		}
     59 	}
     60 
     61 	if (f && f != s) {
     62 		focus(f);
     63 		restack(f->mon);
     64 	}
     65 }
     66