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.

108 lines
3.7 KiB

4 years ago
  1. From 75012a6ab9cc1b6c319af7f4ae7d682b16a66ce3 Mon Sep 17 00:00:00 2001
  2. From: Miles Alan <m@milesalan.com>
  3. Date: Sun, 26 Apr 2020 16:05:43 -0500
  4. Subject: [PATCH] Add inplacerotate fn to rotate all, master, or stacks clients
  5. inplace
  6. CW (+2) or CCW (-2) Rotates all windows.
  7. CW (+1) or CCW (-1) Rotates master xor stack windows (depending on focus).
  8. Focus position stays 'in-place' so the area of the screen you are focused
  9. on remains unchanged.
  10. ---
  11. config.def.h | 4 ++++
  12. dwm.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  13. 2 files changed, 63 insertions(+)
  14. diff --git a/config.def.h b/config.def.h
  15. index 1c0b587..9bcb792 100644
  16. --- a/config.def.h
  17. +++ b/config.def.h
  18. @@ -66,6 +66,10 @@ static Key keys[] = {
  19. { MODKEY, XK_b, togglebar, {0} },
  20. { MODKEY, XK_j, focusstack, {.i = +1 } },
  21. { MODKEY, XK_k, focusstack, {.i = -1 } },
  22. + { MODKEY|ShiftMask, XK_j, inplacerotate, {.i = +1} },
  23. + { MODKEY|ShiftMask, XK_k, inplacerotate, {.i = -1} },
  24. + { MODKEY|ShiftMask, XK_h, inplacerotate, {.i = +2} },
  25. + { MODKEY|ShiftMask, XK_l, inplacerotate, {.i = -2} },
  26. { MODKEY, XK_i, incnmaster, {.i = +1 } },
  27. { MODKEY, XK_d, incnmaster, {.i = -1 } },
  28. { MODKEY, XK_h, setmfact, {.f = -0.05} },
  29. diff --git a/dwm.c b/dwm.c
  30. index 4465af1..3930680 100644
  31. --- a/dwm.c
  32. +++ b/dwm.c
  33. @@ -175,6 +175,7 @@ static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
  34. static void grabbuttons(Client *c, int focused);
  35. static void grabkeys(void);
  36. static void incnmaster(const Arg *arg);
  37. +static void inplacerotate(const Arg *arg);
  38. static void keypress(XEvent *e);
  39. static void killclient(const Arg *arg);
  40. static void manage(Window w, XWindowAttributes *wa);
  41. @@ -2147,3 +2148,61 @@ main(int argc, char *argv[])
  42. XCloseDisplay(dpy);
  43. return EXIT_SUCCESS;
  44. }
  45. +
  46. +void
  47. +insertclient(Client *item, Client *insertItem, int after) {
  48. + Client *c;
  49. + if (item == NULL || insertItem == NULL || item == insertItem) return;
  50. + detach(insertItem);
  51. + if (!after && selmon->clients == item) {
  52. + attach(insertItem);
  53. + return;
  54. + }
  55. + if (after) {
  56. + c = item;
  57. + } else {
  58. + for (c = selmon->clients; c; c = c->next) { if (c->next == item) break; }
  59. + }
  60. + insertItem->next = c->next;
  61. + c->next = insertItem;
  62. +}
  63. +
  64. +void
  65. +inplacerotate(const Arg *arg)
  66. +{
  67. + if(!selmon->sel || (selmon->sel->isfloating && !arg->f)) return;
  68. +
  69. + unsigned int selidx = 0, i = 0;
  70. + Client *c = NULL, *stail = NULL, *mhead = NULL, *mtail = NULL, *shead = NULL;
  71. +
  72. + // Determine positionings for insertclient
  73. + for (c = selmon->clients; c; c = c->next) {
  74. + if (ISVISIBLE(c) && !(c->isfloating)) {
  75. + if (selmon->sel == c) { selidx = i; }
  76. + if (i == selmon->nmaster - 1) { mtail = c; }
  77. + if (i == selmon->nmaster) { shead = c; }
  78. + if (mhead == NULL) { mhead = c; }
  79. + stail = c;
  80. + i++;
  81. + }
  82. + }
  83. +
  84. + // All clients rotate
  85. + if (arg->i == 2) insertclient(selmon->clients, stail, 0);
  86. + if (arg->i == -2) insertclient(stail, selmon->clients, 1);
  87. + // Stack xor master rotate
  88. + if (arg->i == -1 && selidx >= selmon->nmaster) insertclient(stail, shead, 1);
  89. + if (arg->i == 1 && selidx >= selmon->nmaster) insertclient(shead, stail, 0);
  90. + if (arg->i == -1 && selidx < selmon->nmaster) insertclient(mtail, mhead, 1);
  91. + if (arg->i == 1 && selidx < selmon->nmaster) insertclient(mhead, mtail, 0);
  92. +
  93. + // Restore focus position
  94. + i = 0;
  95. + for (c = selmon->clients; c; c = c->next) {
  96. + if (!ISVISIBLE(c) || (c->isfloating)) continue;
  97. + if (i == selidx) { focus(c); break; }
  98. + i++;
  99. + }
  100. + arrange(selmon);
  101. + focus(c);
  102. +}
  103. --
  104. 2.23.1