Adding focusmaster-return patch variant ref. #398

This commit is contained in:
bakkeby 2023-11-12 09:41:31 +01:00
parent d86ea2de25
commit 817db8c3ca
7 changed files with 73 additions and 10 deletions

View File

@ -19,6 +19,8 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6
### Changelog: ### Changelog:
2023-11-12 - Added the focusmaster-return patch variant
2023-06-27 - Added the focusfollowmouse and unmanaged patches 2023-06-27 - Added the focusfollowmouse and unmanaged patches
2023-06-25 - Added the toggletopbar patch 2023-06-25 - Added the toggletopbar patch
@ -442,6 +444,10 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6
- [focusmaster](https://dwm.suckless.org/patches/focusmaster/) - [focusmaster](https://dwm.suckless.org/patches/focusmaster/)
- a simple patch that just puts focus back to the master client - a simple patch that just puts focus back to the master client
- [focusmaster-return](https://dwm.suckless.org/patches/focusmaster/)
- a simple patch that just puts focus back to the master client
- additionally allows focus to be switched back to the previous client
- [focusonclick](https://dwm.suckless.org/patches/focusonclick/) - [focusonclick](https://dwm.suckless.org/patches/focusonclick/)
- this patch makes you switch focus only by mouse click and not sloppy (focus follows mouse - this patch makes you switch focus only by mouse click and not sloppy (focus follows mouse
pointer) pointer)

View File

@ -914,9 +914,9 @@ static const Key keys[] = {
#if TAB_PATCH #if TAB_PATCH
{ MODKEY|ControlMask, XK_b, tabmode, {-1} }, { MODKEY|ControlMask, XK_b, tabmode, {-1} },
#endif // TAB_PATCH #endif // TAB_PATCH
#if FOCUSMASTER_PATCH #if FOCUSMASTER_PATCH || FOCUSMASTER_RETURN_PATCH
{ MODKEY|ControlMask, XK_space, focusmaster, {0} }, { MODKEY|ControlMask, XK_space, focusmaster, {0} },
#endif // FOCUSMASTER_PATCH #endif // FOCUSMASTER_PATCH / FOCUSMASTER_RETURN_PATCH
#if STACKER_PATCH #if STACKER_PATCH
STACKKEYS(MODKEY, focus) STACKKEYS(MODKEY, focus)
STACKKEYS(MODKEY|ShiftMask, push) STACKKEYS(MODKEY|ShiftMask, push)

24
dwm.c
View File

@ -504,6 +504,9 @@ struct Monitor {
Client *clients; Client *clients;
Client *sel; Client *sel;
Client *stack; Client *stack;
#if FOCUSMASTER_RETURN_PATCH
Client *tagmarked[32];
#endif // FOCUSMASTER_RETURN_PATCH
Monitor *next; Monitor *next;
Bar *bar; Bar *bar;
const Layout *lt[2]; const Layout *lt[2];
@ -1818,6 +1821,11 @@ detach(Client *c)
#if SEAMLESS_RESTART_PATCH #if SEAMLESS_RESTART_PATCH
c->idx = 0; c->idx = 0;
#endif // SEAMLESS_RESTART_PATCH #endif // SEAMLESS_RESTART_PATCH
#if FOCUSMASTER_RETURN_PATCH
for (int i = 1; i < NUMTAGS; i++)
if (c == c->mon->tagmarked[i])
c->mon->tagmarked[i] = NULL;
#endif // FOCUSMASTER_RETURN_PATCH
for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next); for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next);
*tc = c->next; *tc = c->next;
@ -2846,6 +2854,13 @@ nexttiled(Client *c)
void void
pop(Client *c) pop(Client *c)
{ {
#if FOCUSMASTER_RETURN_PATCH
int i;
for (i = 0; !(selmon->tagset[selmon->seltags] & 1 << i); i++);
i++;
c->mon->tagmarked[i] = nexttiled(c->mon->clients);
#endif // FOCUSMASTER_RETURN_PATCH
detach(c); detach(c);
attach(c); attach(c);
focus(c); focus(c);
@ -5086,6 +5101,9 @@ void
zoom(const Arg *arg) zoom(const Arg *arg)
{ {
Client *c = selmon->sel; Client *c = selmon->sel;
#if FOCUSMASTER_RETURN_PATCH && ZOOMSWAP_PATCH
int i;
#endif // FOCUSMASTER_RETURN_PATCH
if (arg && arg->v) if (arg && arg->v)
c = (Client*)arg->v; c = (Client*)arg->v;
if (!c) if (!c)
@ -5139,6 +5157,12 @@ zoom(const Arg *arg)
cold = nexttiled(c->mon->clients); cold = nexttiled(c->mon->clients);
if (c != cold && !at) if (c != cold && !at)
at = findbefore(c); at = findbefore(c);
#if FOCUSMASTER_RETURN_PATCH
for (i = 0; !(selmon->tagset[selmon->seltags] & 1 << i); i++);
i++;
c->mon->tagmarked[i] = cold;
#endif // FOCUSMASTER_RETURN_PATCH
detach(c); detach(c);
attach(c); attach(c);
/* swap windows instead of pushing the previous one down */ /* swap windows instead of pushing the previous one down */

View File

@ -1,14 +1,41 @@
void void
focusmaster(const Arg *arg) focusmaster(const Arg *arg)
{ {
Client *c; Client *master;
Monitor *m = selmon;
#if FOCUSMASTER_RETURN_PATCH
int i;
#endif // FOCUSMASTER_RETURN_PATCH
if (selmon->nmaster < 1) if (m->nmaster < 1)
return;
#if !FAKEFULLSCREEN_PATCH
#if FAKEFULLSCREEN_CLIENT_PATCH
if (!m->sel || (m->sel->isfullscreen && m->sel->fakefullscreen != 1 && lockfullscreen))
return;
#else
if (!m->sel || (m->sel->isfullscreen && lockfullscreen))
return;
#endif // FAKEFULLSCREEN_CLIENT_PATCH
#endif // FAKEFULLSCREEN_PATCH
master = nexttiled(m->clients);
if (!master)
return; return;
c = nexttiled(selmon->clients); #if FOCUSMASTER_RETURN_PATCH
for (i = 0; !(m->tagset[m->seltags] & 1 << i); i++);
i++;
if (c) if (m->sel == master) {
focus(c); if (m->tagmarked[i] && ISVISIBLE(m->tagmarked[i]))
focus(m->tagmarked[i]);
} else {
m->tagmarked[i] = m->sel;
focus(master);
}
#else
focus(master);
#endif // FOCUSMASTER_RETURN_PATCH
} }

View File

@ -154,7 +154,7 @@
#if FOCUSFOLLOWMOUSE_PATCH #if FOCUSFOLLOWMOUSE_PATCH
#include "focusfollowmouse.c" #include "focusfollowmouse.c"
#endif #endif
#if FOCUSMASTER_PATCH #if FOCUSMASTER_PATCH || FOCUSMASTER_RETURN_PATCH
#include "focusmaster.c" #include "focusmaster.c"
#endif #endif
#if FOCUSURGENT_PATCH #if FOCUSURGENT_PATCH

View File

@ -157,7 +157,7 @@
#if FOCUSFOLLOWMOUSE_PATCH #if FOCUSFOLLOWMOUSE_PATCH
#include "focusfollowmouse.h" #include "focusfollowmouse.h"
#endif #endif
#if FOCUSMASTER_PATCH #if FOCUSMASTER_PATCH || FOCUSMASTER_RETURN_PATCH
#include "focusmaster.h" #include "focusmaster.h"
#endif #endif
#if FOCUSURGENT_PATCH #if FOCUSURGENT_PATCH

View File

@ -657,6 +657,12 @@
*/ */
#define FOCUSMASTER_PATCH 0 #define FOCUSMASTER_PATCH 0
/* A variant of the focusmaster patch that additionally allows the focus to be returned to the
* previously focused client
* https://dwm.suckless.org/patches/focusmaster/
*/
#define FOCUSMASTER_RETURN_PATCH 0
/* Switch focus only by mouse click and not sloppy (focus follows mouse pointer). /* Switch focus only by mouse click and not sloppy (focus follows mouse pointer).
* https://dwm.suckless.org/patches/focusonclick/ * https://dwm.suckless.org/patches/focusonclick/
*/ */