From 39e161e54519c8c28d479d69f5a1be88b59e3dac Mon Sep 17 00:00:00 2001 From: bakkeby Date: Sat, 14 Sep 2019 00:36:18 +0200 Subject: [PATCH] Adding push patch --- README.md | 5 +++- config.def.h | 4 +++ patch/include.c | 4 +++ patch/include.h | 4 +++ patch/push.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ patch/push.h | 4 +++ patches.h | 5 ++++ 7 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 patch/push.c create mode 100644 patch/push.h diff --git a/README.md b/README.md index 4492603..ccc8c7c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t ### Changelog: -2019-09-13 - Added titlecolor patch +2019-09-13 - Added titlecolor and push patches 2019-09-12 - Added activetagindicatorbar, alwaysfullscreen and autoresize patches @@ -103,6 +103,9 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t - [pertag](https://dwm.suckless.org/patches/pertag/) - adds nmaster, mfact, layouts and more per tag rather than per monitor + - [push](https://dwm.suckless.org/patches/push/) + - this patch provides a way to move clients up and down inside the client list + - [resizecorners](https://dwm.suckless.org/patches/resizecorners/) - by default, windows only resize from the bottom right corner - with this patch the mouse is warped to the nearest corner and you resize from there diff --git a/config.def.h b/config.def.h index da197be..c8cb196 100644 --- a/config.def.h +++ b/config.def.h @@ -235,6 +235,10 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_j, rotatestack, {.i = +1 } }, { MODKEY|ShiftMask, XK_k, rotatestack, {.i = -1 } }, #endif // ROTATESTACK_PATCH + #if PUSH_PATCH + { MODKEY|ControlMask, XK_j, pushdown, {0} }, + { MODKEY|ControlMask, XK_k, pushup, {0} }, + #endif // PUSH_PATCH { MODKEY, XK_i, incnmaster, {.i = +1 } }, { MODKEY, XK_d, incnmaster, {.i = -1 } }, { MODKEY, XK_h, setmfact, {.f = -0.05} }, diff --git a/patch/include.c b/patch/include.c index 809a792..982fcfe 100644 --- a/patch/include.c +++ b/patch/include.c @@ -40,6 +40,10 @@ #include "pertag.c" #endif +#if PUSH_PATCH +#include "push.c" +#endif + #if ROTATESTACK_PATCH #include "rotatestack.c" #endif diff --git a/patch/include.h b/patch/include.h index 9226f4d..ae948cd 100644 --- a/patch/include.h +++ b/patch/include.h @@ -36,6 +36,10 @@ #include "ewmhtags.h" #endif +#if PUSH_PATCH +#include "push.h" +#endif + #if ROTATESTACK_PATCH #include "rotatestack.h" #endif diff --git a/patch/push.c b/patch/push.c new file mode 100644 index 0000000..6ac156f --- /dev/null +++ b/patch/push.c @@ -0,0 +1,71 @@ +Client * +nextc(Client *c, float f) +{ + if (!f) + return nexttiled(c); + + for (; c && !ISVISIBLE(c); c = c->next); + return c; +} + +static Client * +prevc(Client *c, float f) +{ + Client *p, *r; + + for (p = selmon->clients, r = NULL; c && p && p != c; p = p->next) + if ((f || !p->isfloating) && ISVISIBLE(p)) + r = p; + return r; +} + +static void +pushup(const Arg *arg) +{ + Client *sel = selmon->sel; + Client *c; + + if (!sel || (sel->isfloating && !arg->f)) + return; + if ((c = prevc(sel, arg->f))) { + /* attach before c */ + detach(sel); + sel->next = c; + if (selmon->clients == c) + selmon->clients = sel; + else { + for (c = selmon->clients; c->next != sel->next; c = c->next); + c->next = sel; + } + } else { + /* move to the end */ + for (c = sel; c->next; c = c->next); + detach(sel); + sel->next = NULL; + c->next = sel; + } + focus(sel); + arrange(selmon); +} + +static void +pushdown(const Arg *arg) +{ + Client *sel = selmon->sel; + Client *c; + + if (!sel || (sel->isfloating && !arg->f)) + return; + if ((c = nextc(sel->next, arg->f))) { + /* attach after c */ + detach(sel); + sel->next = c->next; + c->next = sel; + } else { + /* move to the front */ + detach(sel); + attach(sel); + } + focus(sel); + arrange(selmon); +} \ No newline at end of file diff --git a/patch/push.h b/patch/push.h new file mode 100644 index 0000000..9cad8b3 --- /dev/null +++ b/patch/push.h @@ -0,0 +1,4 @@ +static Client * nextc(Client *c, float f); +static Client * prevc(Client *c, float f); +static void pushup(const Arg *arg); +static void pushdown(const Arg *arg); \ No newline at end of file diff --git a/patches.h b/patches.h index 83b8141..108a25e 100644 --- a/patches.h +++ b/patches.h @@ -164,6 +164,11 @@ */ #define PERTAGBAR_PATCH 0 +/* This patch provides a way to move clients up and down inside the client list. + * https://dwm.suckless.org/patches/push/ + */ +#define PUSH_PATCH 0 + /* By default, windows only resize from the bottom right corner. With this * patch the mouse is warped to the nearest corner and you resize from there. * https://dwm.suckless.org/patches/resizecorners/