stackctl.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "dwm.h"
  2. #include "stackctl.h"
  3. // From http://dwm.suckless.org/patches/movestack
  4. // Copyright:
  5. // - Niki Yoshiuchi <aplusbi@gmail.com>
  6. // - Moritz Wilhelmy <moritz+suckless@wzff.de>
  7. void movestack(const Arg *arg) {
  8. Client *c = NULL, *p = NULL, *pc = NULL, *i;
  9. if(selmon->sel == NULL) return;
  10. if(arg->i > 0) {
  11. /* find the client after selmon->sel */
  12. for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
  13. if(!c)
  14. for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
  15. }
  16. else {
  17. /* find the client before selmon->sel */
  18. for(i = selmon->clients; i != selmon->sel; i = i->next)
  19. if(ISVISIBLE(i) && !i->isfloating)
  20. c = i;
  21. if(!c)
  22. for(; i; i = i->next)
  23. if(ISVISIBLE(i) && !i->isfloating)
  24. c = i;
  25. }
  26. /* find the client before selmon->sel and c */
  27. for(i = selmon->clients; i && (!p || !pc); i = i->next) {
  28. if(i->next == selmon->sel)
  29. p = i;
  30. if(i->next == c)
  31. pc = i;
  32. }
  33. /* swap c and selmon->sel selmon->clients in the selmon->clients list */
  34. if(c && c != selmon->sel) {
  35. Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next;
  36. selmon->sel->next = c->next==selmon->sel?c:c->next;
  37. c->next = temp;
  38. if(p && p != c)
  39. p->next = c;
  40. if(pc && pc != selmon->sel)
  41. pc->next = selmon->sel;
  42. if(selmon->sel == selmon->clients)
  43. selmon->clients = c;
  44. else if(c == selmon->clients)
  45. selmon->clients = selmon->sel;
  46. arrange(selmon);
  47. }
  48. }
  49. void first_client() {
  50. Client *c = NULL;
  51. for(c = selmon->clients; c; c = c->next) {
  52. if(ISVISIBLE(c) && !c->isfloating) {
  53. break;
  54. }
  55. }
  56. if(c != NULL) {
  57. focus(c);
  58. }
  59. arrange(selmon);
  60. }
  61. void last_client() {
  62. Client *c = NULL;
  63. Client *i;
  64. for(i = selmon->sel; i; i = i->next) {
  65. if(ISVISIBLE(i) && !i->isfloating) {
  66. c = i;
  67. }
  68. }
  69. focus(c);
  70. arrange(selmon);
  71. }