From 642f07b19e402390c6a59e78ed9d1a5ab1c806f1 Mon Sep 17 00:00:00 2001 From: nirav Date: Tue, 11 Feb 2020 16:00:43 +0000 Subject: Add movestack --- README | 1 + config.h | 2 ++ dwm.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/README b/README index b6eec2f..45a7646 100644 --- a/README +++ b/README @@ -54,3 +54,4 @@ noborder - https://dwm.suckless.org/patches/noborder/ pertag - https://dwm.suckless.org/patches/pertag/ attachaside - https://dwm.suckless.org/patches/attachaside/ scratchpad - https://dwm.suckless.org/patches/scratchpad/ +movestack - https://dwm.suckless.org/patches/movestack/ diff --git a/config.h b/config.h index 6395644..ce83335 100644 --- a/config.h +++ b/config.h @@ -99,6 +99,8 @@ static Key keys[] = { { MODKEY, XK_a, shiftview, {.i = -1} }, { MODKEY, XK_d, shiftview, {.i = +1} }, { MODKEY, XK_minus, togglescratch, {.v = scratchpadcmd } }, + { MODKEY|ShiftMask, XK_j, movestack, {.i = +1 } }, + { MODKEY|ShiftMask, XK_k, movestack, {.i = -1 } }, }; /* button definitions */ diff --git a/dwm.c b/dwm.c index 2a0ef46..f5de1b0 100644 --- a/dwm.c +++ b/dwm.c @@ -240,6 +240,7 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); static void shiftview(const Arg *arg); +static void movestack(const Arg *arg); /* variables */ static const char broken[] = "broken"; @@ -2281,6 +2282,56 @@ shiftview(const Arg *arg) { view(&shifted); } +void +movestack(const Arg *arg) { + Client *c = NULL, *p = NULL, *pc = NULL, *i; + + if(arg->i > 0) { + /* find the client after selmon->sel */ + for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); + if(!c) + for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next); + + } + else { + /* find the client before selmon->sel */ + for(i = selmon->clients; i != selmon->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 selmon->sel and c */ + for(i = selmon->clients; i && (!p || !pc); i = i->next) { + if(i->next == selmon->sel) + p = i; + if(i->next == c) + pc = i; + } + + /* swap c and selmon->sel selmon->clients in the selmon->clients list */ + if(c && c != selmon->sel) { + Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next; + selmon->sel->next = c->next==selmon->sel?c:c->next; + c->next = temp; + + if(p && p != c) + p->next = c; + if(pc && pc != selmon->sel) + pc->next = selmon->sel; + + if(selmon->sel == selmon->clients) + selmon->clients = c; + else if(c == selmon->clients) + selmon->clients = selmon->sel; + + arrange(selmon); + } +} + + int main(int argc, char *argv[]) { -- cgit v1.2.3