dwm-locktagsfor-20210928-3465be.diff (4140B)
1 From f86f23588bd96803137e65a0ef7a8dcc285e4583 Mon Sep 17 00:00:00 2001 2 From: v4hn <me@v4hn.de> 3 Date: Thu, 4 Feb 2021 14:12:34 +0100 4 Subject: [PATCH 1/2] introduce locktagsfor functionality 5 6 To reduce procrastination and focus on individual tasks in workflows 7 where multiple projects are open in disjoint tag sets, this patch 8 enables users to lock their currently selected tags for some duration 9 and force them to focus on what is currently shown on their screen. 10 11 The patch retains all WM functionality that does not change tags, 12 especially multi-monitor setups and layout changes. 13 14 Of course the patch does not support you at all if you procrastinate 15 away from your computer or just open new unrelated windows. 16 Forbidding the latter would be much harder and too restrictive 17 from the perspective of the patch author. 18 19 To use this patch add a shortcut to your config.h. 20 E.g., to lock tags for 300 seconds via MOD+F1, add 21 22 + { MODKEY, XK_F1, locktagsfor, {.ui = 300 } }, 23 --- 24 dwm.c | 38 ++++++++++++++++++++++++++++++++++++-- 25 1 file changed, 36 insertions(+), 2 deletions(-) 26 27 diff --git a/dwm.c b/dwm.c 28 index 137a10f..3da1c1a 100644 29 --- a/dwm.c 30 +++ b/dwm.c 31 @@ -27,6 +27,7 @@ 32 #include <stdio.h> 33 #include <stdlib.h> 34 #include <string.h> 35 +#include <time.h> 36 #include <unistd.h> 37 #include <sys/types.h> 38 #include <sys/wait.h> 39 @@ -157,6 +158,7 @@ static void grabkeys(void); 40 static void incnmaster(const Arg *arg); 41 static void keypress(XEvent *e); 42 static void killclient(const Arg *arg); 43 +static void locktagsfor(const Arg *arg); 44 static void manage(Window w, XWindowAttributes *wa); 45 static void mappingnotify(XEvent *e); 46 static void maprequest(XEvent *e); 47 @@ -246,6 +248,8 @@ static Display *dpy; 48 static Drw *drw; 49 static Monitor *mons, *selmon; 50 static Window root; 51 +static time_t locktagsuntil = 0; 52 +static int tagslocked(){ return difftime(locktagsuntil, time(NULL)) > 0; } 53 54 /* configuration, allows nested code to access above variables */ 55 #include "config.def.h" 56 @@ -789,12 +793,16 @@ drawbar(Monitor *m) 57 urg |= c->tags; 58 } 59 x = 0; 60 + 61 + const int locked = tagslocked(); 62 + 63 for (i = 0; i < LENGTH(tags); i++) { 64 w = TEXTW(tags[i]); 65 drw_setscheme(drw, m->tagset[m->seltags] & 1 << i ? &scheme[SchemeSel] : &scheme[SchemeNorm]); 66 - drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i); 67 + drw_text(drw, x, 0, w, bh, 68 + !locked || m->tagset[m->seltags] & 1 << i ? tags[i] : "", !locked && (urg & 1 << i)); 69 drw_rect(drw, x + 1, 1, dx, dx, m == selmon && selmon->sel && selmon->sel->tags & 1 << i, 70 - occ & 1 << i, urg & 1 << i); 71 + (m->tagset[m->seltags] & 1 << i || !locked) && occ & 1 << i, !locked && (urg & 1 << i)); 72 x += w; 73 } 74 w = blw = TEXTW(m->ltsymbol); 75 @@ -1113,6 +1121,19 @@ killclient(const Arg *arg) 76 } 77 } 78 79 +void 80 +locktagsfor(const Arg *arg) 81 +{ 82 +#if 0 // enable for a shortcut to break out early 83 + if(tagslocked()){ 84 + locktagsuntil = time(NULL); 85 + return; 86 + } 87 +#endif 88 + // all sane implementations implement time_t as integral second count, so we just add seconds here 89 + locktagsuntil = time(NULL) + (time_t) arg->ui; 90 +} 91 + 92 void 93 manage(Window w, XWindowAttributes *wa) 94 { 95 @@ -1747,6 +1768,9 @@ spawn(const Arg *arg) 96 void 97 tag(const Arg *arg) 98 { 99 + if(tagslocked()) 100 + return; 101 + 102 if (selmon->sel && arg->ui & TAGMASK) { 103 selmon->sel->tags = arg->ui & TAGMASK; 104 focus(NULL); 105 @@ -1816,6 +1840,9 @@ toggletag(const Arg *arg) 106 { 107 unsigned int newtags; 108 109 + if(tagslocked()) 110 + return; 111 + 112 if (!selmon->sel) 113 return; 114 newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); 115 @@ -1832,6 +1859,9 @@ toggleview(const Arg *arg) 116 unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); 117 int i; 118 119 + if(tagslocked()) 120 + return; 121 + 122 if (newtagset) { 123 if(newtagset == ~0) { 124 selmon->pertag->prevtag = selmon->pertag->curtag; 125 @@ -2153,6 +2183,10 @@ view(const Arg *arg) 126 127 if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) 128 return; 129 + 130 + if(tagslocked()) 131 + return; 132 + 133 selmon->seltags ^= 1; /* toggle sel tagset */ 134 if(arg->ui & TAGMASK) { 135 selmon->pertag->prevtag = selmon->pertag->curtag; 136 -- 137 2.30.1 138