This patch adds keybinds to toggle each part of the dwm bar. This include the title, tags, layout indicator, status and floating indicator. It also allows you to show/hide parts by default, similar to showbar. There is also a version without keybinds if you don't want keybinds, see the dwm-bartoggle-6.4.diff patch. diff -up a/config.def.h b/config.def.h --- a/config.def.h 2022-10-04 19:38:18.000000000 +0200 +++ b/config.def.h 2022-10-22 14:40:36.113933644 +0200 @@ -4,6 +4,11 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int snap = 32; /* snap pixel */ static const int showbar = 1; /* 0 means no bar */ +static const int showtitle = 1; /* 0 means no title */ +static const int showtags = 1; /* 0 means no tags */ +static const int showlayout = 1; /* 0 means no layout indicator */ +static const int showstatus = 1; /* 0 means no status bar */ +static const int showfloating = 1; /* 0 means no floating indicator */ static const int topbar = 1; /* 0 means bottom bar */ static const char *fonts[] = { "monospace:size=10" }; static const char dmenufont[] = "monospace:size=10"; @@ -78,6 +83,11 @@ static const Key keys[] = { { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, { MODKEY, XK_space, setlayout, {0} }, { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, + { MODKEY, XK_t, togglebartitle, {0} }, + { MODKEY, XK_s, togglebarstatus,{0} }, + { MODKEY|ShiftMask, XK_t, togglebartags, {0} }, + { MODKEY|ShiftMask, XK_s, togglebarlt, {0} }, + { MODKEY|ShiftMask, XK_f, togglebarfloat, {0} }, { MODKEY, XK_0, view, {.ui = ~0 } }, { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, { MODKEY, XK_comma, focusmon, {.i = -1 } }, diff -up a/dwm.c b/dwm.c --- a/dwm.c 2022-10-04 19:38:18.000000000 +0200 +++ b/dwm.c 2022-10-22 14:41:29.903932288 +0200 @@ -123,6 +123,11 @@ struct Monitor { unsigned int sellt; unsigned int tagset[2]; int showbar; + int showtitle; + int showtags; + int showlayout; + int showstatus; + int showfloating; int topbar; Client *clients; Client *sel; @@ -211,6 +216,11 @@ static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void tile(Monitor *m); static void togglebar(const Arg *arg); +static void togglebartags(const Arg *arg); +static void togglebartitle(const Arg *arg); +static void togglebarlt(const Arg *arg); +static void togglebarstatus(const Arg *arg); +static void togglebarfloat(const Arg *arg); static void togglefloating(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); @@ -435,16 +445,17 @@ buttonpress(XEvent *e) if (ev->window == selmon->barwin) { i = x = 0; do - x += TEXTW(tags[i]); + if (selmon->showtags) + x += TEXTW(tags[i]); while (ev->x >= x && ++i < LENGTH(tags)); - if (i < LENGTH(tags)) { + if (i < LENGTH(tags) && selmon->showtags) { click = ClkTagBar; arg.ui = 1 << i; - } else if (ev->x < x + TEXTW(selmon->ltsymbol)) + } else if (ev->x < x + TEXTW(selmon->ltsymbol) && selmon->showlayout) click = ClkLtSymbol; - else if (ev->x > selmon->ww - (int)TEXTW(stext)) + else if (ev->x > selmon->ww - (int)TEXTW(stext) && selmon->showstatus) click = ClkStatusText; - else + else if (selmon->showtitle) click = ClkWinTitle; } else if ((c = wintoclient(ev->window))) { focus(c); @@ -641,6 +652,11 @@ createmon(void) m->mfact = mfact; m->nmaster = nmaster; m->showbar = showbar; + m->showtitle = showtitle; + m->showtags = showtags; + m->showlayout = showlayout; + m->showstatus = showstatus; + m->showfloating = showfloating; m->topbar = topbar; m->lt[0] = &layouts[0]; m->lt[1] = &layouts[1 % LENGTH(layouts)]; @@ -709,7 +725,7 @@ drawbar(Monitor *m) return; /* draw status first so it can be overdrawn by tags later */ - if (m == selmon) { /* status is only drawn on selected monitor */ + if (m == selmon && selmon->showstatus) { /* status is only drawn on selected monitor */ drw_setscheme(drw, scheme[SchemeNorm]); tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */ drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0); @@ -717,29 +733,35 @@ drawbar(Monitor *m) for (c = m->clients; c; c = c->next) { occ |= c->tags; - if (c->isurgent) + if (c->isurgent && selmon->showtags) urg |= c->tags; } 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); - x += w; - } - w = TEXTW(m->ltsymbol); - drw_setscheme(drw, scheme[SchemeNorm]); - x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); + if (selmon->showtags) { + 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 && selmon->showfloating) + drw_rect(drw, x + boxs, boxs, boxw, boxw, + m == selmon && selmon->sel && selmon->sel->tags & 1 << i, + urg & 1 << i); + x += w; + } + } + + /* draw layout indicator if selmon->showlayout */ + if (selmon->showlayout) { + w = TEXTW(m->ltsymbol); + drw_setscheme(drw, scheme[SchemeNorm]); + x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); + } if ((w = m->ww - tw - x) > bh) { - if (m->sel) { + if (m->sel && selmon->showtitle) { drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]); drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0); - if (m->sel->isfloating) + if (m->sel->isfloating && selmon->showfloating) drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); } else { drw_setscheme(drw, scheme[SchemeNorm]); @@ -1238,7 +1260,7 @@ propertynotify(XEvent *e) } if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { updatetitle(c); - if (c == c->mon->sel) + if (c == c->mon->sel && selmon->showtitle) drawbar(c->mon); } if (ev->atom == netatom[NetWMWindowType]) @@ -1704,6 +1726,41 @@ togglebar(const Arg *arg) } void +togglebartags(const Arg *arg) +{ + selmon->showtags = !selmon->showtags; + arrange(selmon); +} + +void +togglebartitle(const Arg *arg) +{ + selmon->showtitle = !selmon->showtitle; + arrange(selmon); +} + +void +togglebarlt(const Arg *arg) +{ + selmon->showlayout = !selmon->showlayout; + arrange(selmon); +} + +void +togglebarstatus(const Arg *arg) +{ + selmon->showstatus = !selmon->showstatus; + arrange(selmon); +} + +void +togglebarfloat(const Arg *arg) +{ + selmon->showfloating = !selmon->showfloating; + arrange(selmon); +} + +void togglefloating(const Arg *arg) { if (!selmon->sel) @@ -1987,7 +2044,7 @@ updatesizehints(Client *c) void updatestatus(void) { - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) + if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)) && selmon->showstatus) strcpy(stext, "dwm-"VERSION); drawbar(selmon); }