[wiki] [sites] dwm: add locktagsfor patch || v4hn
commit 4969c3d7fdb99b5d1e437ecefc2c4a9f0bdb22df
Author: v4hn <me_AT_v4hn.de>
Date: Tue Sep 28 21:59:00 2021 +0200
dwm: add locktagsfor patch
diff --git a/dwm.suckless.org/patches/locktagsfor/dwm-locktagsfor-20210928-3465be.diff b/dwm.suckless.org/patches/locktagsfor/dwm-locktagsfor-20210928-3465be.diff
new file mode 100644
index 00000000..1afc3a1c
--- /dev/null
+++ b/dwm.suckless.org/patches/locktagsfor/dwm-locktagsfor-20210928-3465be.diff
_AT_@ -0,0 +1,138 @@
+From f86f23588bd96803137e65a0ef7a8dcc285e4583 Mon Sep 17 00:00:00 2001
+From: v4hn <me_AT_v4hn.de>
+Date: Thu, 4 Feb 2021 14:12:34 +0100
+Subject: [PATCH 1/2] introduce locktagsfor functionality
+
+To reduce procrastination and focus on individual tasks in workflows
+where multiple projects are open in disjoint tag sets, this patch
+enables users to lock their currently selected tags for some duration
+and force them to focus on what is currently shown on their screen.
+
+The patch retains all WM functionality that does not change tags,
+especially multi-monitor setups and layout changes.
+
+Of course the patch does not support you at all if you procrastinate
+away from your computer or just open new unrelated windows.
+Forbidding the latter would be much harder and too restrictive
+from the perspective of the patch author.
+
+To use this patch add a shortcut to your config.h.
+E.g., to lock tags for 300 seconds via MOD+F1, add
+
++ { MODKEY, XK_F1, locktagsfor, {.ui = 300 } },
+---
+ dwm.c | 38 ++++++++++++++++++++++++++++++++++++--
+ 1 file changed, 36 insertions(+), 2 deletions(-)
+
+diff --git a/dwm.c b/dwm.c
+index 137a10f..3da1c1a 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -27,6 +27,7 @@
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
++#include <time.h>
+ #include <unistd.h>
+ #include <sys/types.h>
+ #include <sys/wait.h>
+_AT_@ -157,6 +158,7 @@ static void grabkeys(void);
+ static void incnmaster(const Arg *arg);
+ static void keypress(XEvent *e);
+ static void killclient(const Arg *arg);
++static void locktagsfor(const Arg *arg);
+ static void manage(Window w, XWindowAttributes *wa);
+ static void mappingnotify(XEvent *e);
+ static void maprequest(XEvent *e);
+_AT_@ -246,6 +248,8 @@ static Display *dpy;
+ static Drw *drw;
+ static Monitor *mons, *selmon;
+ static Window root;
++static time_t locktagsuntil = 0;
++static int tagslocked(){ return difftime(locktagsuntil, time(NULL)) > 0; }
+
+ /* configuration, allows nested code to access above variables */
+ #include "config.def.h"
+_AT_@ -789,12 +793,16 @@ drawbar(Monitor *m)
+ urg |= c->tags;
+ }
+ x = 0;
++
++ const int locked = tagslocked();
++
+ for (i = 0; i < LENGTH(tags); i++) {
+ w = TEXTW(tags[i]);
+ drw_setscheme(drw, m->tagset[m->seltags] & 1 << i ? &scheme[SchemeSel] : &scheme[SchemeNorm]);
+- drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i);
++ drw_text(drw, x, 0, w, bh,
++ !locked || m->tagset[m->seltags] & 1 << i ? tags[i] : "", !locked && (urg & 1 << i));
+ drw_rect(drw, x + 1, 1, dx, dx, m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
+- occ & 1 << i, urg & 1 << i);
++ (m->tagset[m->seltags] & 1 << i || !locked) && occ & 1 << i, !locked && (urg & 1 << i));
+ x += w;
+ }
+ w = blw = TEXTW(m->ltsymbol);
+_AT_@ -1113,6 +1121,19 @@ killclient(const Arg *arg)
+ }
+ }
+
++void
++locktagsfor(const Arg *arg)
++{
++#if 0 // enable for a shortcut to break out early
++ if(tagslocked()){
++ locktagsuntil = time(NULL);
++ return;
++ }
++#endif
++ // all sane implementations implement time_t as integral second count, so we just add seconds here
++ locktagsuntil = time(NULL) + (time_t) arg->ui;
++}
++
+ void
+ manage(Window w, XWindowAttributes *wa)
+ {
+_AT_@ -1747,6 +1768,9 @@ spawn(const Arg *arg)
+ void
+ tag(const Arg *arg)
+ {
++ if(tagslocked())
++ return;
++
+ if (selmon->sel && arg->ui & TAGMASK) {
+ selmon->sel->tags = arg->ui & TAGMASK;
+ focus(NULL);
+_AT_@ -1816,6 +1840,9 @@ toggletag(const Arg *arg)
+ {
+ unsigned int newtags;
+
++ if(tagslocked())
++ return;
++
+ if (!selmon->sel)
+ return;
+ newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
+_AT_@ -1832,6 +1859,9 @@ toggleview(const Arg *arg)
+ unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
+ int i;
+
++ if(tagslocked())
++ return;
++
+ if (newtagset) {
+ if(newtagset == ~0) {
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+_AT_@ -2153,6 +2183,10 @@ view(const Arg *arg)
+
+ if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
+ return;
++
++ if(tagslocked())
++ return;
++
+ selmon->seltags ^= 1; /* toggle sel tagset */
+ if(arg->ui & TAGMASK) {
+ selmon->pertag->prevtag = selmon->pertag->curtag;
+--
+2.30.1
+
diff --git a/dwm.suckless.org/patches/locktagsfor/index.md b/dwm.suckless.org/patches/locktagsfor/index.md
new file mode 100644
index 00000000..c41081a6
--- /dev/null
+++ b/dwm.suckless.org/patches/locktagsfor/index.md
_AT_@ -0,0 +1,36 @@
+locktagsfor
+===========
+
+Description
+-----------
+
+To reduce procrastination and focus on individual tasks in workflows
+where multiple projects are open in disjoint tag sets, this patch
+enables users to lock their currently selected tags for some duration
+and force them to focus on what is currently shown on their screen.
+
+The patch retains all WM functionality that does not change tags,
+especially multi-monitor setups and layout changes.
+
+Of course it does not support you at all if you procrastinate
+away from your computer or just open new unrelated windows.
+Forbidding the latter would be much harder and too restrictive
+from the perspective of the patch author.
+
+To use this patch add a shortcut to your config.h.
+E.g., to lock tags for 300 seconds via MOD+F1, add
+`{ MODKEY, XK_F1, locktagsfor, {.ui = 300 } }`
+
+Lastly, if you notice (you will at some point) that the forced
+lock hampers your productivity, find the `#if` to enable a
+way to break out from the lock.
+
+Download
+--------
+* [dwm-locktagsfor-20210928-3465be.diff](dwm-locktagsfor-20210928-3465be.diff)
+
+Authors
+-------
+* v4hn - `<me at v4hn dot de>`
+
+Feedback is more than welcome :-)
Received on Tue Sep 28 2021 - 21:59:14 CEST
This archive was generated by hypermail 2.3.0
: Tue Sep 28 2021 - 22:00:45 CEST