diff -ruN dwm/config.def.h movestack/config.def.h --- dwm/config.def.h 2008-10-04 15:57:46.000000000 -0400 +++ movestack/config.def.h 2008-10-05 17:13:15.000000000 -0400 @@ -50,6 +50,7 @@ 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 } }, @@ -59,6 +60,8 @@ { 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 -ruN dwm/movestack.c movestack/movestack.c --- dwm/movestack.c 1969-12-31 19:00:00.000000000 -0500 +++ movestack/movestack.c 2008-10-10 00:01:52.000000000 -0400 @@ -0,0 +1,49 @@ +void +movestack(const Arg *arg) { + Client *c = NULL, *p = NULL, *pc = NULL, *i; + + 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(); + } +} +