From 04b37902e0098fb69250fd25b5afbc610a284529 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 | 87 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 72 insertions(+), 15 deletions(-)

diff --git a/dwl.c b/dwl.c
index ae290ad..7229034 100644
--- a/dwl.c
+++ b/dwl.c
@@ -1585,19 +1585,29 @@ drawbar(Monitor *m)
 	uint32_t i, occ = 0, urg = 0;
 	Client *c;
 	Buffer *buf;
+	char mode_text[256] = "";
+	int mode_width = 0;
+	int title_width;
+	int remaining;
+	int status_shown = 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 +1617,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 +1629,63 @@ 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);
-
-	if ((w = m->b.width - tw - x) > m->b.height) {
-		if (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);
-			if (c && c->isfloating)
-				drwl_rect(m->drw, x + boxs, boxs, boxw, boxw, 0, 0);
-		} else {
+	drwl_text(m->drw, x, 0, w, m->b.height, m->lrpad / 2, m->ltsymbol, 0);
+	x += w;
+
+	remaining = m->b.width - x;
+
+	if (mode_text[0] && remaining >= tw) {
+		drwl_setscheme(m->drw, colors[SchemeNorm]);
+		drwl_text(m->drw, m->b.width - tw, 0, tw, m->b.height, 0, stext, 0);
+		remaining -= tw;
+		status_shown = 1;
+	}
+
+	title_width = remaining;
+
+	if (c && title_width > m->b.height) {
+		drwl_setscheme(m->drw, colors[m == selmon ? SchemeSel : SchemeNorm]);
+		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 if (title_width > 0) {
+		drwl_setscheme(m->drw, colors[SchemeNorm]);
+		drwl_rect(m->drw, x, 0, title_width, m->b.height, 1, 1);
+	}
+
+	if (!mode_text[0]) {
+		/* 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 +3493,7 @@ entermode(const Arg *arg)
 {
 	active_mode_index = arg->i;
 	printstatus();
+    drawbars();
 }
 
 #ifdef XWAYLAND
-- 
2.53.0

