My configuration of sxmo fork of suckless dwm.

git clone git://watertao.xyz/programs/sxmo-dwm.git

commit 2aa9872341411509dfba58a0f72edec88d8a2294
parent 4fe37f902a3f8a15f2815c3d37a93bfcb7f9d58d
Author: Miles Alan <m@milesalan.com>
Date:   Sun,  8 Mar 2020 10:53:15 -0500

Rotatestack and retain index while rotating

Diffstat:
Mconfig.def.h | 2+-
Mdwm.c | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/config.def.h b/config.def.h @@ -68,7 +68,7 @@ static Key keys[] = { {2, 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("sxmo_appmenu.sh sys") }, {1, 0, XF86XK_AudioLowerVolume, cyclelayout , {.i = +1 } }, - {2, 0, XF86XK_AudioLowerVolume, zoom, {0} }, + {2, 0, XF86XK_AudioLowerVolume, rotatestack, {.i = +1} }, {3, 0, XF86XK_AudioLowerVolume, killclient, {0} }, {1, 0, XF86XK_PowerOff, spawn, SHCMD("sxmo_keyboard.sh") }, diff --git a/dwm.c b/dwm.c @@ -166,6 +166,8 @@ static void detachstack(Client *c); static Monitor *dirtomon(int dir); static void drawbar(Monitor *m); static void drawbars(void); +static void enqueue(Client *c); +static void enqueuestack(Client *c); static void enternotify(XEvent *e); static void expose(XEvent *e); static void focus(Client *c); @@ -196,6 +198,7 @@ static void resize(Client *c, int x, int y, int w, int h, int interact); static void resizeclient(Client *c, int x, int y, int w, int h); static void resizemouse(const Arg *arg); static void restack(Monitor *m); +static void rotatestack(const Arg *arg); static void run(void); static void scan(void); static int sendevent(Client *c, Atom proto); @@ -784,6 +787,28 @@ drawbars(void) } void +enqueue(Client *c) +{ + Client *l; + for (l = c->mon->clients; l && l->next; l = l->next); + if (l) { + l->next = c; + c->next = NULL; + } +} + +void +enqueuestack(Client *c) +{ + Client *l; + for (l = c->mon->stack; l && l->snext; l = l->snext); + if (l) { + l->snext = c; + c->snext = NULL; + } +} + +void enternotify(XEvent *e) { Client *c; @@ -1490,6 +1515,52 @@ restack(Monitor *m) } void +rotatestack(const Arg *arg) +{ + Client *c = NULL, *f; + int i; + + if (!selmon->sel) + return; + + unsigned int selidx = 0; + for (c = selmon->clients; c; c = c->next) { + if (ISVISIBLE(c) && !(c->isfloating)) { + if (selmon->sel == c) { selidx = i; } + i++; + } + } + + f = selmon->sel; + if (arg->i > 0) { + for (c = nexttiled(selmon->clients); c && nexttiled(c->next); c = nexttiled(c->next)); + if (c){ + detach(c); + attach(c); + detachstack(c); + attachstack(c); + } + } else { + if ((c = nexttiled(selmon->clients))){ + detach(c); + enqueue(c); + detachstack(c); + enqueuestack(c); + } + } + if (c) { + i = 0; + for (c = selmon->clients; c; c = c->next) { + if (!ISVISIBLE(c) || (c->isfloating) || c->isdock) continue; + if (i == selidx) { focus(c); break; } + } + arrange(selmon); + //unfocus(f, 1); + restack(selmon); + } +} + +void run(void) { XEvent ev;