Apply MoveStack patch - dwm - My fork of dwm (frankenstein's monster)
 (HTM) git clone git://git.drkhsh.at/dwm.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 34d77a7ae381f72c804712126538e2f1a6b4aa1f
 (DIR) parent 0f47f2508e5d8c80df44df5e3e9cc0cc001abd9a
 (HTM) Author: drkhsh <me@drkhsh.at>
       Date:   Mon, 15 Nov 2021 14:04:53 -0600
       
       Apply MoveStack patch
       
       This plugin allows you to move clients around in the stack and swap them
       with the master. It emulates the behavior off mod+shift+j and mod+shift+k
       in Xmonad. movestack(+1) will swap the client with the current focus with
       the next client. movestack(-1) will swap the client with the current focus
       with the previous client.
       
       https://dwm.suckless.org/patches/movestack/
       
       Diffstat:
         M config.def.h                        |       3 +++
         A movestack.c                         |      49 +++++++++++++++++++++++++++++++
       
       2 files changed, 52 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/config.def.h b/config.def.h
       @@ -89,6 +89,7 @@ static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont,
        static const char *termcmd[]  = { "st", NULL };
        
        #include "tagallmon.c"
       +#include "movestack.c"
        static const Key keys[] = {
                /* modifier                     key        function        argument */
                { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
       @@ -103,6 +104,8 @@ static const Key keys[] = {
                { MODKEY|ShiftMask,             XK_h,      setcfact,       {.f = +0.25} },
                { MODKEY|ShiftMask,             XK_l,      setcfact,       {.f = -0.25} },
                { MODKEY|ShiftMask,             XK_o,      setcfact,       {.f =  0.00} },
       +        { MODKEY|ShiftMask,             XK_j,      movestack,      {.i = +1 } },
       +        { MODKEY|ShiftMask,             XK_k,      movestack,      {.i = -1 } },
                { MODKEY,                       XK_Return, zoom,           {0} },
                { MODKEY|Mod4Mask,              XK_u,      incrgaps,       {.i = +1 } },
                { MODKEY|Mod4Mask|ShiftMask,    XK_u,      incrgaps,       {.i = -1 } },
 (DIR) diff --git a/movestack.c b/movestack.c
       @@ -0,0 +1,48 @@
       +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);
       +        }
       +}
       +\ No newline at end of file