From de05b947f6137462d89f83c3a76eade27ffa86ee Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Thu, 4 Mar 2021 00:45:50 -0600 Subject: [PATCH] port dwm "push" patch to dwl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Leonardo Hernández Hernández --- dwl.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/dwl.c b/dwl.c index f703fa7..64f9130 100644 --- a/dwl.c +++ b/dwl.c @@ -389,6 +389,12 @@ static void zoom(const Arg *arg); static void bstack(Monitor *m); static void bstackhoriz(Monitor *m); +/* push */ +static Client *nexttiled(Client *sel); +static Client *prevtiled(Client *sel); +static void pushdown(const Arg *arg); +static void pushup(const Arg *arg); + /* variables */ static const char broken[] = "broken"; static pid_t child_pid = -1; @@ -3775,3 +3781,67 @@ bstackhoriz(Monitor *m) { i++; } } + +static Client * +nexttiled(Client *sel) { + Client *c; + wl_list_for_each(c, &sel->link, link) { + if (&c->link == &clients) + break; /* don't wrap */ + if (!c->isfloating && VISIBLEON(c, selmon)) + return c; + } + return NULL; +} + +static Client * +prevtiled(Client *sel) { + Client *c; + wl_list_for_each_reverse(c, &sel->link, link) { + if (&c->link == &clients) + break; /* don't wrap */ + if (!c->isfloating && VISIBLEON(c, selmon)) + return c; + } + return NULL; +} + +static void +pushup(const Arg *arg) { + Client *sel = focustop(selmon); + Client *c; + + if(!sel || sel->isfloating) + return; + if((c = prevtiled(sel))) { + /* attach before c */ + wl_list_remove(&sel->link); + wl_list_insert(c->link.prev, &sel->link); + } else { + /* move to the end */ + wl_list_remove(&sel->link); + wl_list_insert(clients.prev, &sel->link); + } + focusclient(sel, 1); + arrange(selmon); +} + +static void +pushdown(const Arg *arg) { + Client *sel = focustop(selmon); + Client *c; + + if(!sel || sel->isfloating) + return; + if((c = nexttiled(sel))) { + /* attach after c */ + wl_list_remove(&sel->link); + wl_list_insert(&c->link, &sel->link); + } else { + /* move to the front */ + wl_list_remove(&sel->link); + wl_list_insert(&clients, &sel->link); + } + focusclient(sel, 1); + arrange(selmon); +}