$ diff dwm-5.6.1-movestack.diff dwm-5.8-movestack.diff
76c76
< + arrange();
---
> + arrange(selmon);
diff --git a/config.h b/config.h
index cca37df..ff1f3a9 100644
--- a/config.h
+++ b/config.h
@@ -48,6 +48,7 @@ static const Layout layouts[] = {
static const char *dmenucmd[] = { "dmenu_run", "-fn", font, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL };
static const char *termcmd[] = { "uxterm", NULL };
+#include "movestack.c"
static Key keys[] = {
/* modifier key function argument */
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
@@ -57,6 +58,8 @@ static Key keys[] = {
{ MODKEY, XK_k, focusstack, {.i = -1 } },
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
+ { MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } },
+ { MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } },
{ MODKEY, XK_Return, zoom, {0} },
{ MODKEY, XK_Tab, view, {0} },
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
diff --git a/movestack.c b/movestack.c
new file mode 100644
index 0000000..90c1e08
--- /dev/null
+++ b/movestack.c
@@ -0,0 +1,52 @@
+void
+movestack(const Arg *arg) {
+ Client *c = NULL, *p = NULL, *pc = NULL, *i;
+ Client *sel, *clients;
+ sel = selmon->sel;
+ clients = selmon->clients;
+
+ if(arg->i > 0) {
+ /* find the client after sel */
+ for(c = sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
+ if(!c)
+ for(c = clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
+
+ }
+ else {
+ /* find the client before sel */
+ for(i = clients; i != sel; i = i->next)
+ if(ISVISIBLE(i) && !i->isfloating)
+ c = i;
+ if(!c)
+ for(; i; i = i->next)
+ if(ISVISIBLE(i) && !i->isfloating)
+ c = i;
+ }
+ /* find the client before sel and c */
+ for(i = clients; i && (!p || !pc); i = i->next) {
+ if(i->next == sel)
+ p = i;
+ if(i->next == c)
+ pc = i;
+ }
+
+ /* swap c and sel clients in the clients list */
+ if(c && c != sel) {
+ Client *temp = sel->next==c?sel:sel->next;
+ sel->next = c->next==sel?c:c->next;
+ c->next = temp;
+
+ if(p && p != c)
+ p->next = c;
+ if(pc && pc != sel)
+ pc->next = sel;
+
+ if(sel == clients)
+ clients = c;
+ else if(c == clients)
+ clients = sel;
+
+ arrange(selmon);
+ }
+}
+