diff --git a/README.md b/README.md index 18e8b1a..d165871 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ If you are experiencing issues then you may want to check out the [Known Issues] ### Changelog: +2021-11-23 - Added the taglabels patch + 2021-09-08 - Added the alwayscenter patch 2021-07-27 - Added the winicon patch @@ -703,6 +705,9 @@ If you are experiencing issues then you may want to check out the [Known Issues] - [taggrid](https://dwm.suckless.org/patches/taggrid/) - adds an option to place tags in rows like in many other window managers + - [taglabels](https://dwm.suckless.org/patches/taglabels/) + - shows tag + class of master client in the tags section of the bar + - [tagmonfixfs](https://github.com/bakkeby/patches/wiki/tagmonfixfs/) - allows moving a fullscreen window to another monitor while remaining in fullscreen diff --git a/config.def.h b/config.def.h index aa79412..2ed1a25 100644 --- a/config.def.h +++ b/config.def.h @@ -91,6 +91,12 @@ static const char buttonbar[] = ""; static const unsigned int systrayspacing = 2; /* systray spacing */ static const int showsystray = 1; /* 0 means no systray */ #endif // BAR_SYSTRAY_PATCH +#if BAR_TAGLABELS_PATCH +static const char ptagf[] = "[%s %s]"; /* format of a tag label */ +static const char etagf[] = "[%s]"; /* format of an empty tag */ +static const int lcaselbl = 0; /* 1 means make tag label lowercase */ +#endif // BAR_TAGLABELS_PATCH + /* Indicators: see patch/bar_indicators.h for options */ static int tagindicatortype = INDICATOR_TOP_LEFT_SQUARE; static int tiledindicatortype = INDICATOR_NONE; @@ -480,6 +486,9 @@ static const BarRule barrules[] = { #if BAR_TAGS_PATCH { -1, 0, BAR_ALIGN_LEFT, width_tags, draw_tags, click_tags, "tags" }, #endif // BAR_TAGS_PATCH + #if BAR_TAGLABELS_PATCH + { -1, 0, BAR_ALIGN_LEFT, width_taglabels, draw_taglabels, click_taglabels, "taglabels" }, + #endif // BAR_TAGLABELS_PATCH #if BAR_TAGGRID_PATCH { -1, 0, BAR_ALIGN_LEFT, width_taggrid, draw_taggrid, click_taggrid, "taggrid" }, #endif // BAR_TAGGRID_PATCH diff --git a/dwm.c b/dwm.c index fb9ced1..d1e1dbe 100644 --- a/dwm.c +++ b/dwm.c @@ -485,6 +485,9 @@ struct Monitor { #if INSETS_PATCH Inset inset; #endif // INSETS_PATCH + #if BAR_TAGLABELS_PATCH + char taglabel[NUMTAGS][64]; + #endif // BAR_TAGLABELS_PATCH #if IPC_PATCH char lastltsymbol[16]; TagState tagstate; diff --git a/patch/bar_taglabels.c b/patch/bar_taglabels.c new file mode 100644 index 0000000..f9c3cf8 --- /dev/null +++ b/patch/bar_taglabels.c @@ -0,0 +1,87 @@ +int +width_taglabels(Bar *bar, BarArg *a) +{ + int w, i; + Client *c; + Monitor *m = bar->mon; + char *icon; + unsigned int occ = 0; + + for (c = m->clients; c; c = c->next) + occ |= c->tags == 255 ? 0 : c->tags; + + for (w = 0, i = 0; i < NUMTAGS; i++) { + m->taglabel[i][0] = '\0'; + #if BAR_HIDEVACANTTAGS_PATCH + if (!(occ & 1 << i || m->tagset[m->seltags] & 1 << i)) + continue; + #endif // BAR_HIDEVACANTTAGS_PATCH + icon = tagicon(m, i); + XClassHint ch = { NULL, NULL }; + for (c = m->clients; c; c = c->next) { + if (c->tags & (1 << i)) { + XGetClassHint(dpy, c->win, &ch); + break; + } + } + if (ch.res_class) { + if (lcaselbl) + ch.res_class[0] = tolower(ch.res_class[0]); + snprintf(m->taglabel[i], 64, ptagf, icon, ch.res_class); + } else + snprintf(m->taglabel[i], 64, etagf, icon); + + w += TEXTW(m->taglabel[i]); + } + return w; +} + +int +draw_taglabels(Bar *bar, BarArg *a) +{ + int invert = 0; + int w, x = a->x; + unsigned int i, occ = 0, urg = 0; + Client *c; + Monitor *m = bar->mon; + + for (c = m->clients; c; c = c->next) + if (c->isurgent) + urg |= c->tags; + + for (i = 0; i < NUMTAGS; i++) { + /* do not draw vacant tags */ + if (!m->taglabel[i][0]) + continue; + drw_setscheme(drw, scheme[ + m->tagset[m->seltags] & 1 << i + ? SchemeTagsSel + : urg & 1 << i + ? SchemeUrg + : SchemeTagsNorm + ]); + w = TEXTW(m->taglabel[i]); + drw_text(drw, x, a->y, w, a->h, lrpad / 2, m->taglabel[i], invert, False); + drawindicator(m, NULL, occ, x, a->y, w, a->h, i, -1, invert, tagindicatortype); + x += w; + } + + return 1; +} + +int +click_taglabels(Bar *bar, Arg *arg, BarArg *a) +{ + int i = 0, x = lrpad / 2; + Monitor *m = bar->mon; + + do { + if (!m->taglabel[i][0]) + continue; + x += TEXTW(m->taglabel[i]); + } while (a->x >= x && ++i < NUMTAGS); + if (i < NUMTAGS) { + arg->ui = 1 << i; + } + return ClkTagBar; +} diff --git a/patch/bar_taglabels.h b/patch/bar_taglabels.h new file mode 100644 index 0000000..57250f9 --- /dev/null +++ b/patch/bar_taglabels.h @@ -0,0 +1,5 @@ +#include /* for making tab label lowercase, very tiny standard library */ + +static int width_taglabels(Bar *bar, BarArg *a); +static int draw_taglabels(Bar *bar, BarArg *a); +static int click_taglabels(Bar *bar, Arg *arg, BarArg *a); \ No newline at end of file diff --git a/patch/include.c b/patch/include.c index 29dac83..d47c6fd 100644 --- a/patch/include.c +++ b/patch/include.c @@ -56,6 +56,9 @@ #if BAR_TAGS_PATCH #include "bar_tags.c" #endif +#if BAR_TAGLABELS_PATCH +#include "bar_taglabels.c" +#endif #if BAR_TAGGRID_PATCH #include "bar_taggrid.c" #endif diff --git a/patch/include.h b/patch/include.h index eea37a8..f26f36e 100644 --- a/patch/include.h +++ b/patch/include.h @@ -56,6 +56,9 @@ #if BAR_TAGS_PATCH #include "bar_tags.h" #endif +#if BAR_TAGLABELS_PATCH +#include "bar_taglabels.h" +#endif #if BAR_TAGGRID_PATCH #include "bar_taggrid.h" #endif diff --git a/patches.def.h b/patches.def.h index bcd15e2..7451dc4 100644 --- a/patches.def.h +++ b/patches.def.h @@ -152,9 +152,14 @@ */ #define BAR_SYSTRAY_PATCH 0 -/* Show tag symbols in bar */ +/* Show tag symbols in the bar. */ #define BAR_TAGS_PATCH 1 +/* Show tag symbols + class of master window in the bar. + * https://dwm.suckless.org/patches/taglabels/ + */ +#define BAR_TAGLABELS_PATCH 0 + /* This patch adds the window icon next to the window title in the bar. * * The patch depends on Imlib2 for icon scaling.