From 36c4e246ad47333f2b8a82610ba2adebeb2043b2 Mon Sep 17 00:00:00 2001 From: Jack Bird Date: Thu, 29 Jul 2021 21:39:33 +0100 Subject: [PATCH] Able to switch to master from anywhere in the stack and can also return to the previously selected client from the master --- dwm.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/dwm.c b/dwm.c index 5e4d494..eab8d57 100644 --- a/dwm.c +++ b/dwm.c @@ -127,6 +127,7 @@ struct Monitor { Client *clients; Client *sel; Client *stack; + Client *stackfocused; Monitor *next; Window barwin; const Layout *lt[2]; @@ -167,6 +168,7 @@ static void enternotify(XEvent *e); static void expose(XEvent *e); static void focus(Client *c); static void focusin(XEvent *e); +static void focusmaster(const Arg *arg); static void focusmon(const Arg *arg); static void focusstack(const Arg *arg); static Atom getatomprop(Client *c, Atom prop); @@ -660,6 +662,9 @@ detach(Client *c) { Client **tc; + if (c == c->mon->stackfocused) + c->mon->stackfocused = NULL; + for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next); *tc = c->next; } @@ -816,6 +821,28 @@ focusin(XEvent *e) setfocus(selmon->sel); } +void +focusmaster(const Arg *arg) +{ + Client *master; + + if (selmon->nmaster > 1) + return; + + master = nexttiled(selmon->clients); + + if (!master) + return; + + if (selmon->sel == master) { + if (master->mon->stackfocused) + focus(master->mon->stackfocused); + } else { + master->mon->stackfocused = master->mon->sel; + focus(master); + } +} + void focusmon(const Arg *arg) { @@ -1203,6 +1230,7 @@ nexttiled(Client *c) void pop(Client *c) { + c->mon->stackfocused = nexttiled(c->mon->clients); detach(c); attach(c); focus(c); -- 2.32.0