My configuration of sxmo fork of suckless dwm.

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

commit 6dd451c10b1abb61aa7c325a8a2402faa402cefe
parent c443c249af578afc1fe31b0720f0208afc2d7a78
Author: Miles Alan <m@milesalan.com>
Date:   Sun, 26 Apr 2020 17:03:12 -0500

Use inplacerotate instead of rotatestack

Diffstat:
Mconfig.def.h | 6+++---
Mdwm.c | 105++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
2 files changed, 61 insertions(+), 50 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -90,7 +90,7 @@ static Key keys[] = { {2, 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("sxmo_appmenu.sh sys") }, {3, 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("sxmo_screenlock") }, {1, 0, XF86XK_AudioLowerVolume, cyclelayout , {.i = +1 } }, - {2, 0, XF86XK_AudioLowerVolume, rotatestack, {.i = +1} }, + {2, 0, XF86XK_AudioLowerVolume, inplacerotate, {.i = +2} }, {3, 0, XF86XK_AudioLowerVolume, killclient, {0} }, {1, 0, XF86XK_PowerOff, spawn, SHCMD("pkill -9 svkbd-sxmo || svkbd-sxmo") }, {2, 0, XF86XK_PowerOff, spawn, SHCMD("sxmo_blinkled.sh green & $TERM") }, @@ -108,8 +108,8 @@ static Key keys[] = { { 0, MODKEY, XK_b, togglebar, {0} }, { 0, MODKEY, XK_j, focusstack, {.i = +1 } }, { 0, MODKEY, XK_k, focusstack, {.i = -1 } }, - { 0, MODKEY|ShiftMask, XK_j, rotatestack, {.i = -1} }, - { 0, MODKEY|ShiftMask, XK_k, rotatestack, {.i = +1} }, + { 0, MODKEY|ShiftMask, XK_j, inplacerotate, {.i = +1} }, + { 0, MODKEY|ShiftMask, XK_k, inplacerotate, {.i = -1} }, { 0, MODKEY, XK_i, incnmaster, {.i = +1 } }, { 0, MODKEY, XK_o, incnmaster, {.i = -1 } }, { 0, MODKEY, XK_h, setmfact, {.f = -0.05} }, diff --git a/dwm.c b/dwm.c @@ -190,6 +190,7 @@ static int gettextprop(Window w, Atom atom, char *text, unsigned int size); static void grabbuttons(Client *c, int focused); static void grabkeys(void); static void incnmaster(const Arg *arg); +static void inplacerotate(const Arg *arg); static void keypress(XEvent *e); static void keyrelease(XEvent *e); static void killclient(const Arg *arg); @@ -208,7 +209,6 @@ 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); @@ -1773,52 +1773,6 @@ 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)) continue; - if (i == selidx) { focus(c); break; } - } - arrange(selmon); - //unfocus(f, 1); - restack(selmon); - } -} - -void run(void) { XEvent ev; @@ -2842,3 +2796,60 @@ unfloatvisible(const Arg *arg) arrange(selmon); } +void +insertclient(Client *item, Client *insertItem, int after) { + Client *c; + if (item == NULL || insertItem == NULL || item == insertItem) return; + detach(insertItem); + if (!after && selmon->clients == item) { + attach(insertItem); + return; + } + if (after) { + c = item; + } else { + for (c = selmon->clients; c; c = c->next) { if (c->next == item) break; } + } + insertItem->next = c->next; + c->next = insertItem; +} + +void +inplacerotate(const Arg *arg) +{ + if(!selmon->sel || (selmon->sel->isfloating && !arg->f)) return; + + unsigned int selidx = 0, i = 0; + Client *c = NULL, *stail = NULL, *mhead = NULL, *mtail = NULL, *shead = NULL; + + // Determine positionings for insertclient + for (c = selmon->clients; c; c = c->next) { + if (ISVISIBLE(c) && !(c->isfloating)) { + if (selmon->sel == c) { selidx = i; } + if (i == selmon->nmaster - 1) { mtail = c; } + if (i == selmon->nmaster) { shead = c; } + if (mhead == NULL) { mhead = c; } + stail = c; + i++; + } + } + + // All clients rotate + if (arg->i == 2) insertclient(selmon->clients, stail, 0); + if (arg->i == -2) insertclient(stail, selmon->clients, 1); + // Stack xor master rotate + if (arg->i == -1 && selidx >= selmon->nmaster) insertclient(stail, shead, 1); + if (arg->i == 1 && selidx >= selmon->nmaster) insertclient(shead, stail, 0); + if (arg->i == -1 && selidx < selmon->nmaster) insertclient(mtail, mhead, 1); + if (arg->i == 1 && selidx < selmon->nmaster) insertclient(mhead, mtail, 0); + + // Restore focus position + i = 0; + for (c = selmon->clients; c; c = c->next) { + if (!ISVISIBLE(c) || (c->isfloating)) continue; + if (i == selidx) { focus(c); break; } + i++; + } + arrange(selmon); + focus(c); +}