dwm-movestack-20211115-a786211.diff 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. From 9a4037dc0ef56f91c009317e78e9e3790dafbb58 Mon Sep 17 00:00:00 2001
  2. From: BrunoCooper17 <BrunoCooper17@outlook.com>
  3. Date: Mon, 15 Nov 2021 14:04:53 -0600
  4. Subject: [PATCH] MoveStack patch
  5. This plugin allows you to move clients around in the stack and swap them
  6. with the master. It emulates the behavior off mod+shift+j and mod+shift+k
  7. in Xmonad. movestack(+1) will swap the client with the current focus with
  8. the next client. movestack(-1) will swap the client with the current focus
  9. with the previous client.
  10. ---
  11. config.def.h | 3 +++
  12. movestack.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
  13. 2 files changed, 51 insertions(+)
  14. create mode 100644 movestack.c
  15. diff --git a/config.def.h b/config.def.h
  16. index a2ac963..33efa5b 100644
  17. --- a/config.def.h
  18. +++ b/config.def.h
  19. @@ -60,6 +60,7 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
  20. static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
  21. static const char *termcmd[] = { "st", NULL };
  22. +#include "movestack.c"
  23. static Key keys[] = {
  24. /* modifier key function argument */
  25. { MODKEY, XK_p, spawn, {.v = dmenucmd } },
  26. @@ -71,6 +72,8 @@ static Key keys[] = {
  27. { MODKEY, XK_d, incnmaster, {.i = -1 } },
  28. { MODKEY, XK_h, setmfact, {.f = -0.05} },
  29. { MODKEY, XK_l, setmfact, {.f = +0.05} },
  30. + { MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } },
  31. + { MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } },
  32. { MODKEY, XK_Return, zoom, {0} },
  33. { MODKEY, XK_Tab, view, {0} },
  34. { MODKEY|ShiftMask, XK_c, killclient, {0} },
  35. diff --git a/movestack.c b/movestack.c
  36. new file mode 100644
  37. index 0000000..520f4ae
  38. --- /dev/null
  39. +++ b/movestack.c
  40. @@ -0,0 +1,48 @@
  41. +void
  42. +movestack(const Arg *arg) {
  43. + Client *c = NULL, *p = NULL, *pc = NULL, *i;
  44. +
  45. + if(arg->i > 0) {
  46. + /* find the client after selmon->sel */
  47. + for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
  48. + if(!c)
  49. + for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
  50. +
  51. + }
  52. + else {
  53. + /* find the client before selmon->sel */
  54. + for(i = selmon->clients; i != selmon->sel; i = i->next)
  55. + if(ISVISIBLE(i) && !i->isfloating)
  56. + c = i;
  57. + if(!c)
  58. + for(; i; i = i->next)
  59. + if(ISVISIBLE(i) && !i->isfloating)
  60. + c = i;
  61. + }
  62. + /* find the client before selmon->sel and c */
  63. + for(i = selmon->clients; i && (!p || !pc); i = i->next) {
  64. + if(i->next == selmon->sel)
  65. + p = i;
  66. + if(i->next == c)
  67. + pc = i;
  68. + }
  69. +
  70. + /* swap c and selmon->sel selmon->clients in the selmon->clients list */
  71. + if(c && c != selmon->sel) {
  72. + Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next;
  73. + selmon->sel->next = c->next==selmon->sel?c:c->next;
  74. + c->next = temp;
  75. +
  76. + if(p && p != c)
  77. + p->next = c;
  78. + if(pc && pc != selmon->sel)
  79. + pc->next = selmon->sel;
  80. +
  81. + if(selmon->sel == selmon->clients)
  82. + selmon->clients = c;
  83. + else if(c == selmon->clients)
  84. + selmon->clients = selmon->sel;
  85. +
  86. + arrange(selmon);
  87. + }
  88. +}
  89. \ No newline at end of file
  90. --
  91. 2.33.1