Hiding vacant tags was actually great, let's get it back.

This commit is contained in:
Bartek Stalewski 2022-04-14 10:54:26 +02:00
parent 51233cea8d
commit f901b1b63e
6 changed files with 81 additions and 100 deletions

View File

@ -42,7 +42,6 @@ static Sp scratchpads[] = {
/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
static const char *alttags[] = { "<01>", "<02>", "<03>", "<04>", "<05>" };
static const Rule rules[] = {
/* xprop(1):
@ -54,9 +53,6 @@ static const Rule rules[] = {
{ "Firefox", NULL, NULL, 1 << 8, 0, 0, -1, -1 },
{ "St", NULL, NULL, 0, 0, 1, 0, -1 },
{ NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 }, /* xev */
{ NULL, "spterm", NULL, SPTAG(0), 1, 0, 0, -1 },
{ NULL, "spfm", NULL, SPTAG(1), 1, 0, 0, -1 },
{ NULL, "keepassxc", NULL, SPTAG(2), 0, 0, 0, -1 },
};
/* layout(s) */
@ -115,13 +111,13 @@ static Key keys[] = {
{ MODKEY, XK_period, focusmon, {.i = +1 } },
{ MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } },
{ MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } },
{ MODKEY, XK_y, togglescratch, {.ui = 0 } },
{ MODKEY, XK_u, togglescratch, {.ui = 1 } },
{ MODKEY, XK_x, togglescratch, {.ui = 2 } },
{ MODKEY, XK_minus, setgaps, {.i = -5 } },
{ MODKEY, XK_equal, setgaps, {.i = +5 } },
{ MODKEY|ShiftMask, XK_minus, setgaps, {.i = GAP_RESET } },
{ MODKEY|ShiftMask, XK_equal, setgaps, {.i = GAP_TOGGLE} },
{ MODKEY, XK_y, togglescratch, {.ui = 0 } },
{ MODKEY, XK_u, togglescratch, {.ui = 1 } },
{ MODKEY, XK_x, togglescratch, {.ui = 2 } },
TAGKEYS( XK_1, 0)
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)

View File

@ -42,7 +42,6 @@ static Sp scratchpads[] = {
/* tagging */
static const char *tags[] = {"\uf292", "\uf738", "\uf70d", "\uf7aa", "\uf120", "\uf120", "\ufc58", "\uf9b0", "\uf296", "\uf2bb"};
static const char *alttags[] = {"\uf292", "\uf738", "\uf70d", "\uf7aa", "\uf120", "\uf120", "\ufc58", "\uf9b0", "\uf296", "\uf2bb"};
static const Rule rules[] = {
/* xprop(1):
@ -71,9 +70,7 @@ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen win
static const Layout layouts[] = {
/* symbol arrange function */
{ "| \ufc56", tile }, /* first entry is default */
{ "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle },
{ "", tile }, /* first entry is default */
};
/* key definitions */

View File

@ -133,6 +133,19 @@ xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
die("no font specified.");
}
/* Do not allow using color fonts. This is a workaround for a BadLength
* error from Xft with color glyphs. Modelled on the Xterm workaround. See
* https://bugzilla.redhat.com/show_bug.cgi?id=1498269
* https://lists.suckless.org/dev/1701/30932.html
* https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916349
* and lots more all over the internet.
*/
FcBool iscol;
if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) {
XftFontClose(drw->dpy, xfont);
return NULL;
}
font = ecalloc(1, sizeof(Fnt));
font->xfont = xfont;
font->pattern = pattern;

View File

@ -551,7 +551,7 @@ unswallow(Client *c)
void
buttonpress(XEvent *e)
{
unsigned int i, x, click, occ;
unsigned int i, x, click;
Arg arg = {0};
Client *c;
Monitor *m;
@ -565,14 +565,16 @@ buttonpress(XEvent *e)
focus(NULL);
}
if (ev->window == selmon->barwin) {
i = x = occ = 0;
/* Bitmask of occupied tags */
i = x = 0;
unsigned int occ = 0;
for(c = m->clients; c; c=c->next)
occ |= c->tags;
do
x += TEXTW(occ & 1 << i ? alttags[i] : tags[i]);
while (ev->x >= x && ++i < LENGTH(tags));
do {
/* Do not reserve space for vacant tags */
if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
continue;
x += TEXTW(tags[i]);
} while (ev->x >= x && ++i < LENGTH(tags));
if (i < LENGTH(tags)) {
click = ClkTagBar;
arg.ui = 1 << i;
@ -1011,7 +1013,6 @@ drawbar(Monitor *m)
int boxs = drw->fonts->h / 9;
int boxw = drw->fonts->h / 6 + 2;
unsigned int i, occ = 0, urg = 0;
const char *tagtext;
Client *c;
if (!m->showbar)
@ -1033,10 +1034,12 @@ drawbar(Monitor *m)
}
x = 0;
for (i = 0; i < LENGTH(tags); i++) {
tagtext = occ & 1 << i ? alttags[i] : tags[i];
w = TEXTW(tagtext);
/* Do not draw vacant tags */
if(!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
continue;
w = TEXTW(tags[i]);
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, tagtext, urg & 1 << i);
drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
x += w;
}
w = blw = TEXTW(m->ltsymbol);

View File

@ -1,67 +0,0 @@
diff --git a/config.def.h b/config.def.h
index 1c0b587..d4b11fc 100644
--- a/config.def.h
+++ b/config.def.h
@@ -20,6 +20,7 @@ static const char *colors[][3] = {
/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+static const char *alttags[] = { "<01>", "<02>", "<03>", "<04>", "<05>" };
static const Rule rules[] = {
/* xprop(1):
diff --git a/dwm.c b/dwm.c
index 4465af1..a394159 100644
--- a/dwm.c
+++ b/dwm.c
@@ -416,7 +416,7 @@ attachstack(Client *c)
void
buttonpress(XEvent *e)
{
- unsigned int i, x, click;
+ unsigned int i, x, click, occ;
Arg arg = {0};
Client *c;
Monitor *m;
@@ -430,9 +430,13 @@ buttonpress(XEvent *e)
focus(NULL);
}
if (ev->window == selmon->barwin) {
- i = x = 0;
+ i = x = occ = 0;
+ /* Bitmask of occupied tags */
+ for (c = m->clients; c; c = c->next)
+ occ |= c->tags;
+
do
- x += TEXTW(tags[i]);
+ x += TEXTW(occ & 1 << i ? alttags[i] : tags[i]);
while (ev->x >= x && ++i < LENGTH(tags));
if (i < LENGTH(tags)) {
click = ClkTagBar;
@@ -699,6 +703,7 @@ drawbar(Monitor *m)
int boxs = drw->fonts->h / 9;
int boxw = drw->fonts->h / 6 + 2;
unsigned int i, occ = 0, urg = 0;
+ const char *tagtext;
Client *c;
/* draw status first so it can be overdrawn by tags later */
@@ -715,13 +720,10 @@ drawbar(Monitor *m)
}
x = 0;
for (i = 0; i < LENGTH(tags); i++) {
- w = TEXTW(tags[i]);
- drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
- drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
- if (occ & 1 << i)
- drw_rect(drw, x + boxs, boxs, boxw, boxw,
- m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
- urg & 1 << i);
+ tagtext = occ & 1 << i ? alttags[i] : tags[i];
+ w = TEXTW(tagtext);
+ drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
+ drw_text(drw, x, 0, w, bh, lrpad / 2, tagtext, urg & 1 << i);
x += w;
}
w = blw = TEXTW(m->ltsymbol);

View File

@ -0,0 +1,39 @@
diff --git a/dwm.c b/dwm.c
index a96f33c..f2da729 100644
--- a/dwm.c
+++ b/dwm.c
@@ -432,9 +432,15 @@ buttonpress(XEvent *e)
}
if (ev->window == selmon->barwin) {
i = x = 0;
- do
+ unsigned int occ = 0;
+ for(c = m->clients; c; c=c->next)
+ occ |= c->tags;
+ do {
+ /* Do not reserve space for vacant tags */
+ if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
+ continue;
x += TEXTW(tags[i]);
- while (ev->x >= x && ++i < LENGTH(tags));
+ } while (ev->x >= x && ++i < LENGTH(tags));
if (i < LENGTH(tags)) {
click = ClkTagBar;
arg.ui = 1 << i;
@@ -719,13 +725,12 @@ drawbar(Monitor *m)
}
x = 0;
for (i = 0; i < LENGTH(tags); i++) {
+ /* Do not draw vacant tags */
+ if(!(occ & 1 << i || m->tagset[m->seltags] & 1 << i))
+ continue;
w = TEXTW(tags[i]);
drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]);
drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
- if (occ & 1 << i)
- drw_rect(drw, x + boxs, boxs, boxw, boxw,
- m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
- urg & 1 << i);
x += w;
}
w = blw = TEXTW(m->ltsymbol);