dwm-rotatestack-20161021-ab9571b.diff 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. diff --git a/config.def.h b/config.def.h
  2. index fd77a07..09737d7 100644
  3. --- a/config.def.h
  4. +++ b/config.def.h
  5. @@ -64,6 +64,8 @@ static Key keys[] = {
  6. { MODKEY, XK_p, spawn, {.v = dmenucmd } },
  7. { MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
  8. { MODKEY, XK_b, togglebar, {0} },
  9. + { MODKEY|ShiftMask, XK_j, rotatestack, {.i = +1 } },
  10. + { MODKEY|ShiftMask, XK_k, rotatestack, {.i = -1 } },
  11. { MODKEY, XK_j, focusstack, {.i = +1 } },
  12. { MODKEY, XK_k, focusstack, {.i = -1 } },
  13. { MODKEY, XK_i, incnmaster, {.i = +1 } },
  14. diff --git a/dwm.c b/dwm.c
  15. index 421bf27..1ec8b10 100644
  16. --- a/dwm.c
  17. +++ b/dwm.c
  18. @@ -165,6 +165,8 @@ static void detachstack(Client *c);
  19. static Monitor *dirtomon(int dir);
  20. static void drawbar(Monitor *m);
  21. static void drawbars(void);
  22. +static void enqueue(Client *c);
  23. +static void enqueuestack(Client *c);
  24. static void enternotify(XEvent *e);
  25. static void expose(XEvent *e);
  26. static void focus(Client *c);
  27. @@ -194,6 +196,7 @@ static void resize(Client *c, int x, int y, int w, int h, int interact);
  28. static void resizeclient(Client *c, int x, int y, int w, int h);
  29. static void resizemouse(const Arg *arg);
  30. static void restack(Monitor *m);
  31. +static void rotatestack(const Arg *arg);
  32. static void run(void);
  33. static void scan(void);
  34. static int sendevent(Client *c, Atom proto);
  35. @@ -765,6 +768,28 @@ drawbars(void)
  36. }
  37. void
  38. +enqueue(Client *c)
  39. +{
  40. + Client *l;
  41. + for (l = c->mon->clients; l && l->next; l = l->next);
  42. + if (l) {
  43. + l->next = c;
  44. + c->next = NULL;
  45. + }
  46. +}
  47. +
  48. +void
  49. +enqueuestack(Client *c)
  50. +{
  51. + Client *l;
  52. + for (l = c->mon->stack; l && l->snext; l = l->snext);
  53. + if (l) {
  54. + l->snext = c;
  55. + c->snext = NULL;
  56. + }
  57. +}
  58. +
  59. +void
  60. enternotify(XEvent *e)
  61. {
  62. Client *c;
  63. @@ -1390,6 +1415,38 @@ restack(Monitor *m)
  64. }
  65. void
  66. +rotatestack(const Arg *arg)
  67. +{
  68. + Client *c = NULL, *f;
  69. +
  70. + if (!selmon->sel)
  71. + return;
  72. + f = selmon->sel;
  73. + if (arg->i > 0) {
  74. + for (c = nexttiled(selmon->clients); c && nexttiled(c->next); c = nexttiled(c->next));
  75. + if (c){
  76. + detach(c);
  77. + attach(c);
  78. + detachstack(c);
  79. + attachstack(c);
  80. + }
  81. + } else {
  82. + if ((c = nexttiled(selmon->clients))){
  83. + detach(c);
  84. + enqueue(c);
  85. + detachstack(c);
  86. + enqueuestack(c);
  87. + }
  88. + }
  89. + if (c){
  90. + arrange(selmon);
  91. + //unfocus(f, 1);
  92. + focus(f);
  93. + restack(selmon);
  94. + }
  95. +}
  96. +
  97. +void
  98. run(void)
  99. {
  100. XEvent ev;