dwm-movestack-20211115-a786211.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-movestack-20211115-a786211.diff (3374B)
       ---
            1 From 9a4037dc0ef56f91c009317e78e9e3790dafbb58 Mon Sep 17 00:00:00 2001
            2 From: BrunoCooper17 <BrunoCooper17@outlook.com>
            3 Date: Mon, 15 Nov 2021 14:04:53 -0600
            4 Subject: [PATCH] MoveStack patch
            5 
            6 This plugin allows you to move clients around in the stack and swap them 
            7 with the master. It emulates the behavior off mod+shift+j and mod+shift+k 
            8 in Xmonad. movestack(+1) will swap the client with the current focus with 
            9 the next client. movestack(-1) will swap the client with the current focus 
           10 with the previous client.
           11 ---
           12  config.def.h |  3 +++
           13  movestack.c  | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
           14  2 files changed, 51 insertions(+)
           15  create mode 100644 movestack.c
           16 
           17 diff --git a/config.def.h b/config.def.h
           18 index a2ac963..33efa5b 100644
           19 --- a/config.def.h
           20 +++ b/config.def.h
           21 @@ -60,6 +60,7 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
           22  static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
           23  static const char *termcmd[]  = { "st", NULL };
           24  
           25 +#include "movestack.c"
           26  static Key keys[] = {
           27          /* modifier                     key        function        argument */
           28          { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
           29 @@ -71,6 +72,8 @@ static Key keys[] = {
           30          { MODKEY,                       XK_d,      incnmaster,     {.i = -1 } },
           31          { MODKEY,                       XK_h,      setmfact,       {.f = -0.05} },
           32          { MODKEY,                       XK_l,      setmfact,       {.f = +0.05} },
           33 +        { MODKEY|ShiftMask,             XK_j,      movestack,      {.i = +1 } },
           34 +        { MODKEY|ShiftMask,             XK_k,      movestack,      {.i = -1 } },
           35          { MODKEY,                       XK_Return, zoom,           {0} },
           36          { MODKEY,                       XK_Tab,    view,           {0} },
           37          { MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
           38 diff --git a/movestack.c b/movestack.c
           39 new file mode 100644
           40 index 0000000..520f4ae
           41 --- /dev/null
           42 +++ b/movestack.c
           43 @@ -0,0 +1,48 @@
           44 +void
           45 +movestack(const Arg *arg) {
           46 +        Client *c = NULL, *p = NULL, *pc = NULL, *i;
           47 +
           48 +        if(arg->i > 0) {
           49 +                /* find the client after selmon->sel */
           50 +                for(c = selmon->sel->next; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
           51 +                if(!c)
           52 +                        for(c = selmon->clients; c && (!ISVISIBLE(c) || c->isfloating); c = c->next);
           53 +
           54 +        }
           55 +        else {
           56 +                /* find the client before selmon->sel */
           57 +                for(i = selmon->clients; i != selmon->sel; i = i->next)
           58 +                        if(ISVISIBLE(i) && !i->isfloating)
           59 +                                c = i;
           60 +                if(!c)
           61 +                        for(; i; i = i->next)
           62 +                                if(ISVISIBLE(i) && !i->isfloating)
           63 +                                        c = i;
           64 +        }
           65 +        /* find the client before selmon->sel and c */
           66 +        for(i = selmon->clients; i && (!p || !pc); i = i->next) {
           67 +                if(i->next == selmon->sel)
           68 +                        p = i;
           69 +                if(i->next == c)
           70 +                        pc = i;
           71 +        }
           72 +
           73 +        /* swap c and selmon->sel selmon->clients in the selmon->clients list */
           74 +        if(c && c != selmon->sel) {
           75 +                Client *temp = selmon->sel->next==c?selmon->sel:selmon->sel->next;
           76 +                selmon->sel->next = c->next==selmon->sel?c:c->next;
           77 +                c->next = temp;
           78 +
           79 +                if(p && p != c)
           80 +                        p->next = c;
           81 +                if(pc && pc != selmon->sel)
           82 +                        pc->next = selmon->sel;
           83 +
           84 +                if(selmon->sel == selmon->clients)
           85 +                        selmon->clients = c;
           86 +                else if(c == selmon->clients)
           87 +                        selmon->clients = selmon->sel;
           88 +
           89 +                arrange(selmon);
           90 +        }
           91 +}
           92 \ No newline at end of file
           93 -- 
           94 2.33.1
           95