dwm-alternativetags-6.3.diff (4099B)
1 From 937130c8ea4884f54eb71357bfa99233e6c3e556 Mon Sep 17 00:00:00 2001 2 From: Tom Schwindl <schwindl@posteo.de> 3 Date: Sun, 18 Sep 2022 18:44:29 +0200 4 Subject: [PATCH] 6.3 alternativetags patch 5 6 --- 7 config.def.h | 3 +++ 8 dwm.c | 35 +++++++++++++++++++++++++++++++++-- 9 2 files changed, 36 insertions(+), 2 deletions(-) 10 11 diff --git a/config.def.h b/config.def.h 12 index 061ad662f82a..e912edd557cf 100644 13 --- a/config.def.h 14 +++ b/config.def.h 15 @@ -20,6 +20,8 @@ static const char *colors[][3] = { 16 17 /* tagging */ 18 static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; 19 +static const char *tagsalt[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; 20 +static const int momentaryalttags = 0; /* 1 means alttags will show only when key is held down*/ 21 22 static const Rule rules[] = { 23 /* xprop(1): 24 @@ -84,6 +86,7 @@ static const Key keys[] = { 25 { MODKEY, XK_period, focusmon, {.i = +1 } }, 26 { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, 27 { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, 28 + { MODKEY, XK_n, togglealttag, {0} }, 29 TAGKEYS( XK_1, 0) 30 TAGKEYS( XK_2, 1) 31 TAGKEYS( XK_3, 2) 32 diff --git a/dwm.c b/dwm.c 33 index e5efb6a22806..12ff3f0768bc 100644 34 --- a/dwm.c 35 +++ b/dwm.c 36 @@ -130,6 +130,7 @@ struct Monitor { 37 Monitor *next; 38 Window barwin; 39 const Layout *lt[2]; 40 + unsigned int alttag; 41 }; 42 43 typedef struct { 44 @@ -177,6 +178,7 @@ static void grabbuttons(Client *c, int focused); 45 static void grabkeys(void); 46 static void incnmaster(const Arg *arg); 47 static void keypress(XEvent *e); 48 +static void keyrelease(XEvent *e); 49 static void killclient(const Arg *arg); 50 static void manage(Window w, XWindowAttributes *wa); 51 static void mappingnotify(XEvent *e); 52 @@ -210,6 +212,7 @@ static void spawn(const Arg *arg); 53 static void tag(const Arg *arg); 54 static void tagmon(const Arg *arg); 55 static void tile(Monitor *); 56 +static void togglealttag(const Arg *arg); 57 static void togglebar(const Arg *arg); 58 static void togglefloating(const Arg *arg); 59 static void toggletag(const Arg *arg); 60 @@ -254,6 +257,7 @@ static void (*handler[LASTEvent]) (XEvent *) = { 61 [Expose] = expose, 62 [FocusIn] = focusin, 63 [KeyPress] = keypress, 64 + [KeyRelease] = keyrelease, 65 [MappingNotify] = mappingnotify, 66 [MapRequest] = maprequest, 67 [MotionNotify] = motionnotify, 68 @@ -699,7 +703,7 @@ dirtomon(int dir) 69 void 70 drawbar(Monitor *m) 71 { 72 - int x, w, tw = 0; 73 + int x, w, wdelta, tw = 0; 74 int boxs = drw->fonts->h / 9; 75 int boxw = drw->fonts->h / 6 + 2; 76 unsigned int i, occ = 0, urg = 0; 77 @@ -723,8 +727,9 @@ drawbar(Monitor *m) 78 x = 0; 79 for (i = 0; i < LENGTH(tags); i++) { 80 w = TEXTW(tags[i]); 81 + wdelta = selmon->alttag ? abs(TEXTW(tags[i]) - TEXTW(tagsalt[i])) / 2 : 0; 82 drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); 83 - drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); 84 + drw_text(drw, x, 0, w, bh, wdelta + lrpad / 2, (selmon->alttag ? tagsalt[i] : tags[i]), urg & 1 << i); 85 if (occ & 1 << i) 86 drw_rect(drw, x + boxs, boxs, boxw, boxw, 87 m == selmon && selmon->sel && selmon->sel->tags & 1 << i, 88 @@ -1003,6 +1008,25 @@ keypress(XEvent *e) 89 keys[i].func(&(keys[i].arg)); 90 } 91 92 +void 93 +keyrelease(XEvent *e) 94 +{ 95 + unsigned int i; 96 + KeySym keysym; 97 + XKeyEvent *ev; 98 + 99 + ev = &e->xkey; 100 + keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); 101 + 102 + for (i = 0; i < LENGTH(keys); i++) 103 + if (momentaryalttags 104 + && keys[i].func && keys[i].func == togglealttag 105 + && selmon->alttag 106 + && (keysym == keys[i].keysym 107 + || CLEANMASK(keys[i].mod) == CLEANMASK(ev->state))) 108 + keys[i].func(&(keys[i].arg)); 109 +} 110 + 111 void 112 killclient(const Arg *arg) 113 { 114 @@ -1694,6 +1718,13 @@ tile(Monitor *m) 115 } 116 } 117 118 +void 119 +togglealttag(const Arg *arg) 120 +{ 121 + selmon->alttag = !selmon->alttag; 122 + drawbar(selmon); 123 +} 124 + 125 void 126 togglebar(const Arg *arg) 127 { 128 -- 129 2.37.3 130