[wiki] [sites] [dwm][patches] update swapfocus to 6.2 and add pertag feature || Aaron Duxler

From: <git_AT_suckless.org>
Date: Sun, 21 Jul 2019 22:48:03 +0200

commit 8aec20ded43b022e84f8f910342f1235e393f560
Author: Aaron Duxler <aaron.duxler_AT_gmail.com>
Date: Sun Jul 21 22:47:58 2019 +0200

    [dwm][patches] update swapfocus to 6.2 and add pertag feature

diff --git a/dwm.suckless.org/patches/swapfocus/dwm-swapfocus-6.2.diff b/dwm.suckless.org/patches/swapfocus/dwm-swapfocus-6.2.diff
new file mode 100644
index 00000000..934456d2
--- /dev/null
+++ b/dwm.suckless.org/patches/swapfocus/dwm-swapfocus-6.2.diff
_AT_@ -0,0 +1,174 @@
+diff -up a/config.def.h b/config.def.h
+--- a/config.def.h 2019-06-26 22:55:48.406595279 +0200
++++ b/config.def.h 2019-07-21 21:50:32.649343232 +0200
+_AT_@ -66,6 +66,7 @@ static Key keys[] = {
+ { MODKEY, XK_b, togglebar, {0} },
+ { MODKEY, XK_j, focusstack, {.i = +1 } },
+ { MODKEY, XK_k, focusstack, {.i = -1 } },
++ { MODKEY, XK_s, swapfocus, {.i = -1 } },
+ { MODKEY, XK_i, incnmaster, {.i = +1 } },
+ { MODKEY, XK_d, incnmaster, {.i = -1 } },
+ { MODKEY, XK_h, setmfact, {.f = -0.05} },
+diff -up a/dwm.c b/dwm.c
+--- a/dwm.c 2019-06-26 22:55:48.409928612 +0200
++++ b/dwm.c 2019-07-21 22:29:17.400607398 +0200
+_AT_@ -111,6 +111,7 @@ typedef struct {
+ void (*arrange)(Monitor *);
+ } Layout;
+
++typedef struct Pertag Pertag;
+ struct Monitor {
+ char ltsymbol[16];
+ float mfact;
+_AT_@ -130,6 +131,7 @@ struct Monitor {
+ Monitor *next;
+ Window barwin;
+ const Layout *lt[2];
++ Pertag *pertag;
+ };
+
+ typedef struct {
+_AT_@ -206,6 +208,7 @@ static void seturgent(Client *c, int urg
+ static void showhide(Client *c);
+ static void sigchld(int unused);
+ static void spawn(const Arg *arg);
++static void swapfocus(const Arg *arg);
+ static void tag(const Arg *arg);
+ static void tagmon(const Arg *arg);
+ static void tile(Monitor *);
+_AT_@ -271,6 +274,11 @@ static Window root, wmcheckwin;
+ /* configuration, allows nested code to access above variables */
+ #include "config.h"
+
++struct Pertag {
++ unsigned int curtag, prevtag; /* current and previous tag */
++ Client *prevclient[LENGTH(tags) + 1];
++};
++
+ /* compile-time check if all tags fit into an unsigned int bit array. */
+ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
+
+_AT_@ -641,6 +649,8 @@ createmon(void)
+ m->lt[0] = &layouts[0];
+ m->lt[1] = &layouts[1 % LENGTH(layouts)];
+ strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
++ m->pertag = ecalloc(1, sizeof(Pertag));
++ m->pertag->curtag = m->pertag->prevtag = 1;
+ return m;
+ }
+
+_AT_@ -1012,6 +1022,7 @@ killclient(const Arg *arg)
+ XSetErrorHandler(xerror);
+ XUngrabServer(dpy);
+ }
++ selmon->pertag->prevclient[selmon->pertag->curtag] = NULL;
+ }
+
+ void
+_AT_@ -1653,6 +1664,28 @@ spawn(const Arg *arg)
+ }
+
+ void
++swapfocus(const Arg *arg)
++{
++ if (!selmon->sel)
++ return;
++ if(selmon->pertag->prevclient[selmon->pertag->curtag] != NULL
++ && ISVISIBLE(selmon->pertag->prevclient[selmon->pertag->curtag])){
++ focus(selmon->pertag->prevclient[selmon->pertag->curtag]);
++ restack(selmon->pertag->prevclient[selmon->pertag->curtag]->mon);
++ }
++ else{
++ Client *c = NULL;
++ for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next);
++ if (!c)
++ for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next);
++ if (c) {
++ focus(c);
++ restack(selmon);
++ }
++ }
++}
++
++void
+ tag(const Arg *arg)
+ {
+ if (selmon->sel && arg->ui & TAGMASK) {
+_AT_@ -1738,9 +1771,22 @@ void
+ toggleview(const Arg *arg)
+ {
+ unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
++ int i;
+
+ if (newtagset) {
+ selmon->tagset[selmon->seltags] = newtagset;
++
++ if (newtagset == ~0) {
++ selmon->pertag->prevtag = selmon->pertag->curtag;
++ selmon->pertag->curtag = 0;
++ }
++
++ /* test if the user did not select the same tag */
++ if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
++ selmon->pertag->prevtag = selmon->pertag->curtag;
++ for (i = 0; !(newtagset & 1 << i); i++) ;
++ selmon->pertag->curtag = i + 1;
++ }
+ focus(NULL);
+ arrange(selmon);
+ }
+_AT_@ -1751,6 +1797,7 @@ unfocus(Client *c, int setfocus)
+ {
+ if (!c)
+ return;
++ selmon->pertag->prevclient[selmon->pertag->curtag] = c;
+ grabbuttons(c, 0);
+ XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel);
+ if (setfocus) {
+_AT_@ -2035,12 +2082,30 @@ updatewmhints(Client *c)
+ void
+ view(const Arg *arg)
+ {
++ int i;
++ unsigned int tmptag;
++
+ if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
+ return;
+ selmon->seltags ^= 1; /* toggle sel tagset */
+- if (arg->ui & TAGMASK)
++ if (arg->ui & TAGMASK){
+ selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
++ selmon->pertag->prevtag = selmon->pertag->curtag;
++
++ if (arg->ui == ~0)
++ selmon->pertag->curtag = 0;
++ else {
++ for (i = 0; !(arg->ui & 1 << i); i++) ;
++ selmon->pertag->curtag = i + 1;
++ }
++ } else {
++ tmptag = selmon->pertag->prevtag;
++ selmon->pertag->prevtag = selmon->pertag->curtag;
++ selmon->pertag->curtag = tmptag;
++ }
++ Client *unmodified = selmon->pertag->prevclient[selmon->pertag->curtag];
+ focus(NULL);
++ selmon->pertag->prevclient[selmon->pertag->curtag] = unmodified;
+ arrange(selmon);
+ }
+
+_AT_@ -2114,12 +2179,13 @@ void
+ zoom(const Arg *arg)
+ {
+ Client *c = selmon->sel;
++ selmon->pertag->prevclient[selmon->pertag->curtag] = nexttiled(selmon->clients);
+
+ if (!selmon->lt[selmon->sellt]->arrange
+ || (selmon->sel && selmon->sel->isfloating))
+ return;
+ if (c == nexttiled(selmon->clients))
+- if (!c || !(c = nexttiled(c->next)))
++ if (!c || !(c = selmon->pertag->prevclient[selmon->pertag->curtag] = nexttiled(c->next)))
+ return;
+ pop(c);
+ }
diff --git a/dwm.suckless.org/patches/swapfocus/index.md b/dwm.suckless.org/patches/swapfocus/index.md
index 87a1867d..97e81e70 100644
--- a/dwm.suckless.org/patches/swapfocus/index.md
+++ b/dwm.suckless.org/patches/swapfocus/index.md
_AT_@ -7,8 +7,15 @@ This patch makes it possible to switch focus with one single shortcut (alt-s)
 instead of having to think if you should use alt-j or alt-k for reaching the
 last used window.
 
+Changes in 6.2
+----------------
+* Remember the previous tag and previous clients on each tag.
+* If there is no previous client on the current tag (because it was moved or killed),
+ the next client on the current tag is focused.
+
 Download
 --------
+* [dwm-swapfocus-6.2.diff](dwm-swapfocus-6.2.diff)
 * [dwm-swapfocus-20160731-56a31dc.diff](dwm-swapfocus-20160731-56a31dc.diff)
 * [dwm-6.1-swapfocus.diff](dwm-6.1-swapfocus.diff) (1807b) (20140209)
 * [dwm-swapfocus-6.0.diff](dwm-swapfocus-6.0.diff) (1482b) (20120406)
_AT_@ -18,3 +25,4 @@ Author
 ------
 * Lasse Engblom
 * Jan Christoph Ebersbach - <jceb_AT_e-jc.de>
+* Aaron Duxler - <aaron.duxler_AT_gmail.com> (6.2 port)
Received on Sun Jul 21 2019 - 22:48:03 CEST

This archive was generated by hypermail 2.3.0 : Sun Jul 21 2019 - 22:48:37 CEST