push.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. Client *
  2. nextc(Client *c, float f) {
  3. if(!f)
  4. return nexttiled(c);
  5. for(; c && !ISVISIBLE(c); c = c->next);
  6. return c;
  7. }
  8. static Client *
  9. prevc(Client *c, float f) {
  10. Client *p, *r;
  11. for(p = selmon->clients, r = NULL; c && p && p != c; p = p->next)
  12. if((f || !p->isfloating) && ISVISIBLE(p))
  13. r = p;
  14. return r;
  15. }
  16. static void
  17. pushup(const Arg *arg) {
  18. Client *sel = selmon->sel;
  19. Client *c;
  20. if(!sel || (sel->isfloating && !arg->f))
  21. return;
  22. if((c = prevc(sel, arg->f))) {
  23. /* attach before c */
  24. detach(sel);
  25. sel->next = c;
  26. if(selmon->clients == c)
  27. selmon->clients = sel;
  28. else {
  29. for(c = selmon->clients; c->next != sel->next; c = c->next);
  30. c->next = sel;
  31. }
  32. } else {
  33. /* move to the end */
  34. for(c = sel; c->next; c = c->next);
  35. detach(sel);
  36. sel->next = NULL;
  37. c->next = sel;
  38. }
  39. focus(sel);
  40. arrange(selmon);
  41. }
  42. static void
  43. pushdown(const Arg *arg) {
  44. Client *sel = selmon->sel;
  45. Client *c;
  46. if(!sel || (sel->isfloating && !arg->f))
  47. return;
  48. if((c = nextc(sel->next, arg->f))) {
  49. /* attach after c */
  50. detach(sel);
  51. sel->next = c->next;
  52. c->next = sel;
  53. } else {
  54. /* move to the front */
  55. detach(sel);
  56. attach(sel);
  57. }
  58. focus(sel);
  59. arrange(selmon);
  60. }