Adding focusfollowmouse patch ref. #364

This commit is contained in:
bakkeby 2023-06-27 16:07:13 +02:00
parent 1a1ce47917
commit 99f6f1b52c
17 changed files with 55 additions and 23 deletions

View File

@ -19,6 +19,8 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6
### Changelog: ### Changelog:
2023-06-27 - Added the focusfollowmouse patch
2023-06-25 - Added the toggletopbar patch 2023-06-25 - Added the toggletopbar patch
2023-01-18 - Added the view history patch 2023-01-18 - Added the view history patch
@ -433,6 +435,10 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/X9IiSSM6
- allows focusing on clients based on direction (up, down, left, right) instead of client - allows focusing on clients based on direction (up, down, left, right) instead of client
order order
- [focusfollowmouse](https://github.com/bakkeby/patches/wiki/focusfollowmouse)
- the window under the mouse cursor will receive focus when changing tags, closing windows or
moving client out of view (as opposed to the most recently focused client)
- [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

23
dwm.c
View File

@ -1489,8 +1489,8 @@ configurenotify(XEvent *e)
createpreview(m); createpreview(m);
#endif // BAR_TAGPREVIEW_PATCH #endif // BAR_TAGPREVIEW_PATCH
} }
focus(NULL);
arrange(NULL); arrange(NULL);
focus(NULL);
} }
} }
} }
@ -2037,6 +2037,10 @@ expose(XEvent *e)
void void
focus(Client *c) focus(Client *c)
{ {
#if FOCUSFOLLOWMOUSE_PATCH
if (!c || !ISVISIBLE(c))
c = getpointerclient();
#endif // FOCUSFOLLOWMOUSE_PATCH
if (!c || !ISVISIBLE(c)) if (!c || !ISVISIBLE(c))
for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext); for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
if (selmon->sel && selmon->sel != c) if (selmon->sel && selmon->sel != c)
@ -3347,11 +3351,12 @@ sendmon(Client *c, Monitor *m)
if (hadfocus) { if (hadfocus) {
focus(c); focus(c);
restack(m); restack(m);
} else } else {
focus(NULL); focus(NULL);
}
#else #else
focus(NULL);
arrange(NULL); arrange(NULL);
focus(NULL);
#endif // EXRESIZE_PATCH / SENDMON_KEEPFOCUS_PATCH #endif // EXRESIZE_PATCH / SENDMON_KEEPFOCUS_PATCH
#if SWITCHTAG_PATCH #if SWITCHTAG_PATCH
if (c->switchtag) if (c->switchtag)
@ -4074,6 +4079,7 @@ tag(const Arg *arg)
if (selmon->sel->switchtag) if (selmon->sel->switchtag)
selmon->sel->switchtag = 0; selmon->sel->switchtag = 0;
#endif // SWITCHTAG_PATCH #endif // SWITCHTAG_PATCH
arrange(selmon);
focus(NULL); focus(NULL);
#if SWAPFOCUS_PATCH && PERTAG_PATCH #if SWAPFOCUS_PATCH && PERTAG_PATCH
selmon->pertag->prevclient[selmon->pertag->curtag] = NULL; selmon->pertag->prevclient[selmon->pertag->curtag] = NULL;
@ -4081,7 +4087,6 @@ tag(const Arg *arg)
if (tagmask & 1) if (tagmask & 1)
selmon->pertag->prevclient[tagindex] = NULL; selmon->pertag->prevclient[tagindex] = NULL;
#endif // SWAPFOCUS_PATCH #endif // SWAPFOCUS_PATCH
arrange(selmon);
#if VIEWONTAG_PATCH #if VIEWONTAG_PATCH
if ((arg->ui & TAGMASK) != selmon->tagset[selmon->seltags]) if ((arg->ui & TAGMASK) != selmon->tagset[selmon->seltags])
view(arg); view(arg);
@ -4213,13 +4218,13 @@ toggletag(const Arg *arg)
newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
if (newtags) { if (newtags) {
selmon->sel->tags = newtags; selmon->sel->tags = newtags;
arrange(selmon);
focus(NULL); focus(NULL);
#if SWAPFOCUS_PATCH && PERTAG_PATCH #if SWAPFOCUS_PATCH && PERTAG_PATCH
for (tagmask = arg->ui & TAGMASK, tagindex = 1; tagmask!=0; tagmask >>= 1, tagindex++) for (tagmask = arg->ui & TAGMASK, tagindex = 1; tagmask!=0; tagmask >>= 1, tagindex++)
if (tagmask & 1) if (tagmask & 1)
selmon->pertag->prevclient[tagindex] = NULL; selmon->pertag->prevclient[tagindex] = NULL;
#endif // SWAPFOCUS_PATCH #endif // SWAPFOCUS_PATCH
arrange(selmon);
} }
#if BAR_EWMHTAGS_PATCH #if BAR_EWMHTAGS_PATCH
updatecurrentdesktop(); updatecurrentdesktop();
@ -4306,8 +4311,8 @@ toggleview(const Arg *arg)
#endif // PERTAGBAR_PATCH #endif // PERTAGBAR_PATCH
#endif // PERTAG_PATCH #endif // PERTAG_PATCH
#if !TAGSYNC_PATCH #if !TAGSYNC_PATCH
focus(NULL);
arrange(selmon); arrange(selmon);
focus(NULL);
#endif // TAGSYNC_PATCH #endif // TAGSYNC_PATCH
#if !EMPTYVIEW_PATCH #if !EMPTYVIEW_PATCH
} }
@ -4318,8 +4323,8 @@ toggleview(const Arg *arg)
#if !EMPTYVIEW_PATCH #if !EMPTYVIEW_PATCH
if (newtagset) { if (newtagset) {
#endif // EMPTYVIEW_PATCH #endif // EMPTYVIEW_PATCH
focus(NULL);
arrange(NULL); arrange(NULL);
focus(NULL);
#if !EMPTYVIEW_PATCH #if !EMPTYVIEW_PATCH
} }
#endif // EMPTYVIEW_PATCH #endif // EMPTYVIEW_PATCH
@ -4456,9 +4461,9 @@ unmanage(Client *c, int destroyed)
if (s) if (s)
return; return;
#endif // SWALLOW_PATCH #endif // SWALLOW_PATCH
arrange(m);
focus(NULL); focus(NULL);
updateclientlist(); updateclientlist();
arrange(m);
#if SWITCHTAG_PATCH #if SWITCHTAG_PATCH
if (switchtag && ((switchtag & TAGMASK) != selmon->tagset[selmon->seltags])) if (switchtag && ((switchtag & TAGMASK) != selmon->tagset[selmon->seltags]))
view(&((Arg) { .ui = switchtag })); view(&((Arg) { .ui = switchtag }));
@ -4953,12 +4958,12 @@ view(const Arg *arg)
} }
selmon = origselmon; selmon = origselmon;
#endif // TAGSYNC_PATCH #endif // TAGSYNC_PATCH
focus(NULL);
#if TAGSYNC_PATCH #if TAGSYNC_PATCH
arrange(NULL); arrange(NULL);
#else #else
arrange(selmon); arrange(selmon);
#endif // TAGSYNC_PATCH #endif // TAGSYNC_PATCH
focus(NULL);
#if BAR_EWMHTAGS_PATCH #if BAR_EWMHTAGS_PATCH
updatecurrentdesktop(); updatecurrentdesktop();
#endif // BAR_EWMHTAGS_PATCH #endif // BAR_EWMHTAGS_PATCH

View File

@ -22,8 +22,8 @@ combotag(const Arg *arg)
combo = 1; combo = 1;
selmon->sel->tags = arg->ui & TAGMASK; selmon->sel->tags = arg->ui & TAGMASK;
} }
focus(NULL);
arrange(selmon); arrange(selmon);
focus(NULL);
} }
} }

View File

@ -22,10 +22,10 @@ distributetags(const Arg *arg)
#if TAGSYNC_PATCH #if TAGSYNC_PATCH
} }
selmon = origselmon; selmon = origselmon;
focus(NULL);
arrange(NULL); arrange(NULL);
#else
focus(NULL); focus(NULL);
#else
arrange(selmon); arrange(selmon);
focus(NULL);
#endif // TAGSYNC_PATCH #endif // TAGSYNC_PATCH
} }

View File

@ -6,8 +6,8 @@ tagtoleft(const Arg *arg)
&& __builtin_popcount(selmon->tagset[selmon->seltags] & MASK) == 1 && __builtin_popcount(selmon->tagset[selmon->seltags] & MASK) == 1
&& selmon->tagset[selmon->seltags] > 1) { && selmon->tagset[selmon->seltags] > 1) {
selmon->sel->tags >>= 1; selmon->sel->tags >>= 1;
focus(NULL);
arrange(selmon); arrange(selmon);
focus(NULL);
} }
} }
@ -19,8 +19,8 @@ tagtoright(const Arg *arg)
&& __builtin_popcount(selmon->tagset[selmon->seltags] & MASK) == 1 && __builtin_popcount(selmon->tagset[selmon->seltags] & MASK) == 1
&& selmon->tagset[selmon->seltags] & (MASK >> 1)) { && selmon->tagset[selmon->seltags] & (MASK >> 1)) {
selmon->sel->tags <<= 1; selmon->sel->tags <<= 1;
focus(NULL);
arrange(selmon); arrange(selmon);
focus(NULL);
} }
} }

9
patch/focusfollowmouse.c Normal file
View File

@ -0,0 +1,9 @@
Client *
getpointerclient(void)
{
Window dummy, win;
int di;
unsigned int dui;
XQueryPointer(dpy, root, &dummy, &win, &di, &di, &di, &di, &dui);
return wintoclient(win);
}

1
patch/focusfollowmouse.h Normal file
View File

@ -0,0 +1 @@
static Client *getpointerclient(void);

View File

@ -151,6 +151,9 @@
#if FOCUSDIR_PATCH #if FOCUSDIR_PATCH
#include "focusdir.c" #include "focusdir.c"
#endif #endif
#if FOCUSFOLLOWMOUSE_PATCH
#include "focusfollowmouse.c"
#endif
#if FOCUSMASTER_PATCH #if FOCUSMASTER_PATCH
#include "focusmaster.c" #include "focusmaster.c"
#endif #endif

View File

@ -154,6 +154,9 @@
#if FOCUSADJACENTTAG_PATCH #if FOCUSADJACENTTAG_PATCH
#include "focusadjacenttag.h" #include "focusadjacenttag.h"
#endif #endif
#if FOCUSFOLLOWMOUSE_PATCH
#include "focusfollowmouse.h"
#endif
#if FOCUSMASTER_PATCH #if FOCUSMASTER_PATCH
#include "focusmaster.h" #include "focusmaster.h"
#endif #endif

View File

@ -62,8 +62,8 @@ togglescratch(const Arg *arg)
if (found) { if (found) {
if (newtagset) { if (newtagset) {
selmon->tagset[selmon->seltags] = newtagset; selmon->tagset[selmon->seltags] = newtagset;
focus(NULL);
arrange(selmon); arrange(selmon);
focus(NULL);
} }
if (ISVISIBLE(found)) { if (ISVISIBLE(found)) {
focus(found); focus(found);

View File

@ -6,8 +6,8 @@ scratchpad_hide()
if (selmon->sel) { if (selmon->sel) {
selmon->sel->tags = SCRATCHPAD_MASK; selmon->sel->tags = SCRATCHPAD_MASK;
selmon->sel->isfloating = 1; selmon->sel->isfloating = 1;
focus(NULL);
arrange(selmon); arrange(selmon);
focus(NULL);
} }
} }
@ -36,8 +36,8 @@ scratchpad_show()
if (scratchpad_last_showed->tags != SCRATCHPAD_MASK) { if (scratchpad_last_showed->tags != SCRATCHPAD_MASK) {
scratchpad_last_showed->tags = SCRATCHPAD_MASK; scratchpad_last_showed->tags = SCRATCHPAD_MASK;
focus(NULL);
arrange(selmon); arrange(selmon);
focus(NULL);
return; return;
} }

View File

@ -91,8 +91,8 @@ unswallow(Client *c)
setfloatinghint(c); setfloatinghint(c);
#endif // BAR_EWMHTAGS_PATCH #endif // BAR_EWMHTAGS_PATCH
setclientstate(c, NormalState); setclientstate(c, NormalState);
focus(NULL);
arrange(c->mon); arrange(c->mon);
focus(NULL);
} }
pid_t pid_t

View File

@ -43,7 +43,7 @@ tagallmon(const Arg *arg)
} }
} }
focus(NULL);
arrange(NULL); arrange(NULL);
focus(NULL);
} }

View File

@ -37,8 +37,8 @@ tagothermon(const Arg *arg, int dir)
sendmon(sel, newmon); sendmon(sel, newmon);
if (arg->ui & TAGMASK) { if (arg->ui & TAGMASK) {
sel->tags = arg->ui & TAGMASK; sel->tags = arg->ui & TAGMASK;
focus(NULL);
arrange(newmon); arrange(newmon);
focus(NULL);
} }
} }

View File

@ -69,7 +69,7 @@ tagswapmon(const Arg *arg)
} }
} }
focus(NULL);
arrange(NULL); arrange(NULL);
focus(NULL);
} }

View File

@ -132,7 +132,6 @@ xrdb(const Arg *arg)
#endif // BAR_ALPHA_PATCH #endif // BAR_ALPHA_PATCH
ColCount ColCount
); );
focus(NULL);
arrange(NULL); arrange(NULL);
focus(NULL);
} }

View File

@ -646,6 +646,12 @@
*/ */
#define FOCUSDIR_PATCH 0 #define FOCUSDIR_PATCH 0
/* When changing tags, closing windows or moving clients out of view then focus will revert to the
* client window that remains under the mouse cursor rather than the most recently focused window.
* https://github.com/bakkeby/patches/wiki/focusfollowmouse
*/
#define FOCUSFOLLOWMOUSE_PATCH 0
/* A simple patch that just puts focus back to the master client. /* A simple patch that just puts focus back to the master client.
* https://dwm.suckless.org/patches/focusmaster/ * https://dwm.suckless.org/patches/focusmaster/
*/ */