commit fef22c9ff1400b6b494e3fbd1ce0ca0ec2ef40fc
Author: Max Schillinger <[email protected]>
Date:   Sun Dec 27 16:49:49 2020 +0100

    [dwm][patch][goback]: New patch for focussing the prev. tagset on any 
monitor

diff --git a/dwm.suckless.org/patches/goback/dwm-goback-20201227-61bb8b2.diff 
b/dwm.suckless.org/patches/goback/dwm-goback-20201227-61bb8b2.diff
new file mode 100644
index 00000000..64443e14
--- /dev/null
+++ b/dwm.suckless.org/patches/goback/dwm-goback-20201227-61bb8b2.diff
@@ -0,0 +1,145 @@
+From ad9b42dd9f9cc984f6d7bf6351b1101b594899b4 Mon Sep 17 00:00:00 2001
+From: Max Schillinger <[email protected]>
+Date: Sun, 27 Dec 2020 15:04:08 +0100
+Subject: [PATCH] add patch/function 'goback'
+
+---
+ config.def.h |  1 +
+ dwm.c        | 31 +++++++++++++++++++++++++++++--
+ 2 files changed, 30 insertions(+), 2 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 1c0b587..c217a27 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -72,6 +72,7 @@ static Key keys[] = {
+       { MODKEY,                       XK_l,      setmfact,       {.f = +0.05} 
},
+       { MODKEY,                       XK_Return, zoom,           {0} },
+       { MODKEY,                       XK_Tab,    view,           {0} },
++      { MODKEY,                       XK_g,      goback,         {0} },
+       { MODKEY|ShiftMask,             XK_c,      killclient,     {0} },
+       { MODKEY,                       XK_t,      setlayout,      {.v = 
&layouts[0]} },
+       { MODKEY,                       XK_f,      setlayout,      {.v = 
&layouts[1]} },
+diff --git a/dwm.c b/dwm.c
+index 664c527..3d40bac 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -173,6 +173,7 @@ static Atom getatomprop(Client *c, Atom prop);
+ static int getrootptr(int *x, int *y);
+ static long getstate(Window w);
+ static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
++static void goback(const Arg *arg);
+ static void grabbuttons(Client *c, int focused);
+ static void grabkeys(void);
+ static void incnmaster(const Arg *arg);
+@@ -266,7 +267,7 @@ static Cur *cursor[CurLast];
+ static Clr **scheme;
+ static Display *dpy;
+ static Drw *drw;
+-static Monitor *mons, *selmon;
++static Monitor *mons, *selmon, *prevmon;
+ static Window root, wmcheckwin;
+ 
+ /* configuration, allows nested code to access above variables */
+@@ -427,6 +428,7 @@ buttonpress(XEvent *e)
+       /* focus monitor if necessary */
+       if ((m = wintomon(ev->window)) && m != selmon) {
+               unfocus(selmon->sel, 1);
++              prevmon = selmon;
+               selmon = m;
+               focus(NULL);
+       }
+@@ -765,6 +767,7 @@ enternotify(XEvent *e)
+       m = c ? c->mon : wintomon(ev->window);
+       if (m != selmon) {
+               unfocus(selmon->sel, 1);
++              prevmon = selmon;
+               selmon = m;
+       } else if (!c || c == selmon->sel)
+               return;
+@@ -789,8 +792,10 @@ focus(Client *c)
+       if (selmon->sel && selmon->sel != c)
+               unfocus(selmon->sel, 0);
+       if (c) {
+-              if (c->mon != selmon)
++              if (c->mon != selmon) {
++                      prevmon = selmon;
+                       selmon = c->mon;
++              }
+               if (c->isurgent)
+                       seturgent(c, 0);
+               detachstack(c);
+@@ -826,6 +831,7 @@ focusmon(const Arg *arg)
+       if ((m = dirtomon(arg->i)) == selmon)
+               return;
+       unfocus(selmon->sel, 0);
++      prevmon = selmon;
+       selmon = m;
+       focus(NULL);
+ }
+@@ -925,6 +931,21 @@ gettextprop(Window w, Atom atom, char *text, unsigned int 
size)
+       return 1;
+ }
+ 
++void
++goback(const Arg *arg)
++{
++      if (prevmon == NULL) {
++              Arg a = {0};
++              view(&a);
++      } else if (prevmon != selmon) {
++              unfocus(selmon->sel, 0);
++              Monitor *p = selmon;
++              selmon = prevmon;
++              focus(NULL);
++              prevmon = p;
++      }
++}
++
+ void
+ grabbuttons(Client *c, int focused)
+ {
+@@ -1127,6 +1148,8 @@ motionnotify(XEvent *e)
+               return;
+       if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
+               unfocus(selmon->sel, 1);
++              if (m != selmon)
++                      prevmon = selmon;
+               selmon = m;
+               focus(NULL);
+       }
+@@ -1188,6 +1211,7 @@ movemouse(const Arg *arg)
+       XUngrabPointer(dpy, CurrentTime);
+       if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
+               sendmon(c, m);
++              prevmon = selmon;
+               selmon = m;
+               focus(NULL);
+       }
+@@ -1340,6 +1364,7 @@ resizemouse(const Arg *arg)
+       while (XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+       if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
+               sendmon(c, m);
++              prevmon = selmon;
+               selmon = m;
+               focus(NULL);
+       }
+@@ -1743,6 +1768,7 @@ toggleview(const Arg *arg)
+       unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & 
TAGMASK);
+ 
+       if (newtagset) {
++              prevmon = NULL;
+               selmon->tagset[selmon->seltags] = newtagset;
+               focus(NULL);
+               arrange(selmon);
+@@ -2040,6 +2066,7 @@ view(const Arg *arg)
+ {
+       if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
+               return;
++      prevmon = NULL;
+       selmon->seltags ^= 1; /* toggle sel tagset */
+       if (arg->ui & TAGMASK)
+               selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
+-- 
+2.25.1
+
diff --git a/dwm.suckless.org/patches/goback/index.md 
b/dwm.suckless.org/patches/goback/index.md
new file mode 100644
index 00000000..531a2007
--- /dev/null
+++ b/dwm.suckless.org/patches/goback/index.md
@@ -0,0 +1,21 @@
+goback
+======
+
+Description
+-----------
+This patch adds a function named `goback` which allows activating the 
previously active tagset and binds it to *MODKEY+g*. Unlike dwm's `view` 
function (bound to *MODKEY+Tab* by default), `goback` registers when you focus 
another monitor.
+
+Examples
+--------
+* You are on your first monitor and switch from tag 1 to tag 2. Then `goback` 
(*MODKEY+g*) brings you back to tag 1 (like *MODEYK+Tab*).
+* Next, you focus your third monitor (which is showing tags 3 and 4), no 
matter if your use your mouse or a shortcut like *MODEY+comma*. Then `goback` 
(*MODKEY+g*) brings the focus back to your first monitor (tag 1). Pressing 
*MODKEY+g* again brings you back to the third monitor (tags 3 and 4).
+
+Download
+--------
+* [dwm-goback-20201227-61bb8b2.diff](dwm-goback-20201227-61bb8b2.diff)
+
+(Also available at [GitHub](https://github.com/MaxGyver83/dwm-goback))
+
+Author
+------
+* Max Schillinger - <[email protected]>


Reply via email to