Hello, This function sends the currently focused client to the top of the stack area. If the focused client is not already in the stack area, or if it is already at the top of the stack area, the first two clients in the stack area are swapped instead. If arg->i == 1 the focus is always moved to the client at the top of the stack area. If arg->i == 0 this only happens if the previously focused client was already in the stack area.
This function can simply be added to config.h instead of patching dwm.c. Best, Sebastiano --- >From a20a03e14072b498a72b0ae7e954e9dd0b7aa76b Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto <[email protected]> Date: Sun, 6 Dec 2020 18:06:26 +0100 Subject: [dwm][PATCH] Send client to top of stack area --- config.def.h | 2 ++ dwm.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/config.def.h b/config.def.h index 1c0b587..6804773 100644 --- a/config.def.h +++ b/config.def.h @@ -94,6 +94,8 @@ static Key keys[] = { TAGKEYS( XK_8, 7) TAGKEYS( XK_9, 8) { MODKEY|ShiftMask, XK_q, quit, {0} }, + /* Send client to top of stack; .i = 1 means always focus. */ + { MODKEY, XK_backslash, zoomstack, {.i = 0} }, }; /* button definitions */ diff --git a/dwm.c b/dwm.c index 664c527..8ec30e9 100644 --- a/dwm.c +++ b/dwm.c @@ -234,6 +234,7 @@ static int xerror(Display *dpy, XErrorEvent *ee); static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); +static void zoomstack(const Arg *arg); /* variables */ static const char broken[] = "broken"; @@ -2127,6 +2128,42 @@ zoom(const Arg *arg) pop(c); } +void +zoomstack(const Arg *arg) +{ + int s = 0; + unsigned int j; + Monitor *m = selmon; + Client *c = selmon->sel, *f, **p; + + if (!m->lt[m->sellt]->arrange) + return; + + if (!c || (c && c->isfloating)) { + c = nexttiled(m->clients); + s = 1; + } + + for (j = 0, f = nexttiled(m->clients); f && j < m->nmaster; + f = nexttiled(f->next), j++) { + if (f == c) { + c = nexttiled(c->next); + s = 1; + } + } + if (c && f == c) + c = nexttiled(c->next); + for (p = &m->clients; *p && (*p)->next != f; p = &(*p)->next); + if (!*p || !c) + return; + detach(c); + c->next = (*p)->next; + (*p)->next = c; + arrange(m); + if (!s || arg->i) + focus(c); +} + int main(int argc, char *argv[]) { -- 2.29.2
