diff --git a/patches/bar-modes/README.md b/patches/bar-modes/README.md new file mode 100644 index 0000000..e7dc12d --- /dev/null +++ b/patches/bar-modes/README.md @@ -0,0 +1,31 @@ +![dwl bar-modes patch example](./example.png) + +### Description + +Add a mode indicator to bar that tells which mode you are in, just like +river-classic's [dam](https://codeberg.org/sewn/dam) bar. + +The string from `modes_labels` defined in `config.h` is used, while normal mode +is ignored. + +Another usage is to serve as a hint for each modes keybindings: + +```c +enum { + BROWSER, +}; +const char *modes_lablels[] = { + "[f]irefox [b]rave [c]hromium [q]utebrowser", +}; +``` + +### Dependencies +this patch depends on: +- [bar](https://codeberg.org/dwl/dwl-patches/src/branch/main/patches/bar/) patch +- [modes](https://codeberg.org/dwl/dwl-patches/src/branch/main/patches/modes/) patch + +### Download +- [v0.8](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/bar-modes/bar-modes.patch) + +### Authors +- [unixchad](https://codeberg.org/unixchad/) diff --git a/patches/bar-modes/bar-modes.patch b/patches/bar-modes/bar-modes.patch new file mode 100644 index 0000000..8e239a2 --- /dev/null +++ b/patches/bar-modes/bar-modes.patch @@ -0,0 +1,131 @@ +From 4f2c8a99720d90a551bf38f2c8d25ad239346eef Mon Sep 17 00:00:00 2001 +From: nate zhou +Date: Mon, 2 Mar 2026 21:54:03 +0800 +Subject: [PATCH] Patch: bar-modes for 0.8 + +Add modes_labels indicator to bar, which behaves like river-classic's +dam bar. This patch has to be applied after the bar and modes patch. +--- + dwl.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++---------- + 1 file changed, 59 insertions(+), 11 deletions(-) + +diff --git a/dwl.c b/dwl.c +index ae290ad..df525d3 100644 +--- a/dwl.c ++++ b/dwl.c +@@ -1585,19 +1585,26 @@ drawbar(Monitor *m) + uint32_t i, occ = 0, urg = 0; + Client *c; + Buffer *buf; ++ char mode_text[256] = ""; ++ int mode_width = 0; + + if (!m->scene_buffer->node.enabled) + return; + if (!(buf = bufmon(m))) + return; + +- /* draw status first so it can be overdrawn by tags later */ +- if (m == selmon) { /* status is only drawn on selected monitor */ +- drwl_setscheme(m->drw, colors[SchemeNorm]); +- tw = TEXTW(m, stext) - m->lrpad + 2; /* 2px right padding */ +- drwl_text(m->drw, m->b.width - tw, 0, tw, m->b.height, 0, stext, 0); ++ /* get current mode text if in a mode (not normal) */ ++ if (active_mode_index >= 0 && active_mode_index < LENGTH(modes_labels) && ++ modes_labels[active_mode_index]) { ++ strncpy(mode_text, modes_labels[active_mode_index], sizeof(mode_text) - 1); ++ mode_text[sizeof(mode_text) - 1] = '\0'; ++ mode_width = TEXTW(m, mode_text); + } + ++ /* calculate status text width */ ++ drwl_setscheme(m->drw, colors[SchemeNorm]); ++ tw = TEXTW(m, stext) - m->lrpad + 2; ++ + wl_list_for_each(c, &clients, link) { + if (c->mon != m) + continue; +@@ -1607,6 +1614,8 @@ drawbar(Monitor *m) + } + x = 0; + c = focustop(m); ++ ++ /* draw tags (always shown) */ + for (i = 0; i < LENGTH(tags); i++) { + w = TEXTW(m, tags[i]); + drwl_setscheme(m->drw, colors[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); +@@ -1617,19 +1626,57 @@ drawbar(Monitor *m) + urg & 1 << i); + x += w; + } ++ ++ /* draw mode indicator after tags if in a mode */ ++ if (mode_text[0]) { ++ drwl_setscheme(m->drw, colors[SchemeSel]); ++ drwl_text(m->drw, x, 0, mode_width, m->b.height, m->lrpad / 2, mode_text, 0); ++ x += mode_width; ++ } ++ ++ /* draw layout symbol after mode */ + w = TEXTW(m, m->ltsymbol); + drwl_setscheme(m->drw, colors[SchemeNorm]); +- x = drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, m->ltsymbol, 0); ++ drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, m->ltsymbol, 0); ++ x += w; ++ ++ int remaining = m->b.width - x; + +- if ((w = m->b.width - tw - x) > m->b.height) { +- if (c) { ++ if (mode_text[0]) { ++ int title_width = remaining; ++ ++ if (title_width > m->b.height && c) { + drwl_setscheme(m->drw, colors[m == selmon ? SchemeSel : SchemeNorm]); +- drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, client_get_title(c), 0); ++ drwl_text(m->drw, x, 0, title_width, m->b.height, m->lrpad / 2, ++ client_get_title(c), 0); + if (c && c->isfloating) + drwl_rect(m->drw, x + boxs, boxs, boxw, boxw, 0, 0); +- } else { ++ } else if (title_width > 0) { ++ drwl_setscheme(m->drw, colors[SchemeNorm]); ++ drwl_rect(m->drw, x, 0, title_width, m->b.height, 1, 1); ++ } ++ /* no status text when in a mode - completely omitted */ ++ } else { ++ /* not in a mode - normal behavior with status */ ++ if (remaining >= tw) { ++ drwl_setscheme(m->drw, colors[SchemeNorm]); ++ drwl_text(m->drw, m->b.width - tw, 0, tw, m->b.height, 0, stext, 0); ++ ++ int title_space = remaining - tw; ++ if (title_space > m->b.height && c) { ++ drwl_setscheme(m->drw, colors[m == selmon ? SchemeSel : SchemeNorm]); ++ drwl_text(m->drw, x, 0, title_space, m->b.height, m->lrpad / 2, ++ client_get_title(c), 0); ++ if (c && c->isfloating) ++ drwl_rect(m->drw, x + boxs, boxs, boxw, boxw, 0, 0); ++ } else if (title_space > 0) { ++ drwl_setscheme(m->drw, colors[SchemeNorm]); ++ drwl_rect(m->drw, x, 0, title_space, m->b.height, 1, 1); ++ } ++ } else if (remaining > 0) { + drwl_setscheme(m->drw, colors[SchemeNorm]); +- drwl_rect(m->drw, x, 0, w, m->b.height, 1, 1); ++ drwl_text(m->drw, m->b.width - remaining, 0, remaining, m->b.height, 0, ++ stext, 0); + } + } + +@@ -3437,6 +3484,7 @@ entermode(const Arg *arg) + { + active_mode_index = arg->i; + printstatus(); ++ drawbars(); + } + + #ifdef XWAYLAND +-- +2.53.0 + diff --git a/patches/bar-modes/example.png b/patches/bar-modes/example.png new file mode 100644 index 0000000..185b4fe Binary files /dev/null and b/patches/bar-modes/example.png differ