Add: bar-modes patch

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.
This commit is contained in:
nate zhou 2026-03-08 11:48:37 +08:00 committed by A Frederick Christensen
parent 97b9dbc1e6
commit 507f76f981
3 changed files with 162 additions and 0 deletions

View File

@ -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/)

View File

@ -0,0 +1,131 @@
From 4f2c8a99720d90a551bf38f2c8d25ad239346eef Mon Sep 17 00:00:00 2001
From: nate zhou <gnuunixchad@outlook.com>
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB