Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.3 KiB

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