diff options
author | Benjamin Chausse <benjamin@chausse.xyz> | 2024-01-26 17:39:52 -0500 |
---|---|---|
committer | Benjamin Chausse <benjamin@chausse.xyz> | 2024-01-26 17:39:52 -0500 |
commit | 12ae9ee25290f985f2d17119247137b5a1de3340 (patch) | |
tree | afecce07b32363999142efde75e895000e9a0a07 | |
parent | 155416bcf5db0644313fcabca91b700a8622b35c (diff) |
Implement movestack
-rw-r--r-- | config.def.h | 2 | ||||
-rw-r--r-- | dwm.c | 2 | ||||
-rw-r--r-- | movestack.c | 48 |
3 files changed, 52 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h index 851f95f..b2579bd 100644 --- a/config.def.h +++ b/config.def.h @@ -82,6 +82,8 @@ static const Key keys[] = { { MODKEY, XK_d, incnmaster, {.i = -1 } }, { MODKEY, XK_h, setmfact, {.f = -0.05} }, { MODKEY, XK_l, setmfact, {.f = +0.05} }, + { MODKEY|ShiftMask, XK_l, movestack, {.i = +1 } }, + { MODKEY|ShiftMask, XK_h, movestack, {.i = -1 } }, { MODKEY, XK_Return, zoom, {0} }, { MODKEY, XK_Tab, view, {0} }, { MODKEY|ShiftMask, XK_c, killclient, {0} }, @@ -283,6 +283,8 @@ static Visual *visual; static int depth; static Colormap cmap; +#include "movestack.c" + /* configuration, allows nested code to access above variables */ #include "config.h" diff --git a/movestack.c b/movestack.c new file mode 100644 index 0000000..520f4ae --- /dev/null +++ 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 |