Nimbin[12]?Sway / SwBr / commits / 15437d4

SwBr git · main

SwBr - status bar for sway

sway wayland c bar · first commit 2026-08-27 · last commit 2026-11-12 (11 days ago) · synced 1 hour ago · upstream: github.com/nimbin2/SwBr

C 95.6% Markdown 4%
git clone https://git.christianimmanuel.de/sway/SwBr.gitwget https://git.christianimmanuel.de/sway/SwBr/archive/SwBr.tar.gz

swbr: tint busy workspace buttons, and make a failed alert audible

Christian Immanuel · 2026-10-14 08:01 · 15437d450dbe7d44d1356197e0668c62fee04483

ws_cpu_wash=45 tints a workspace button in the load colour, more of it the
busier the workspace is. The two-pixel dot column was the only sign before and
was easy to miss across a whole screen; the dots stay as the scale, the tint
is what the row says at a glance. The focused workspace keeps its own colour:
that is a different question and must not become a matter of degree.

Measured offscreen at 0.9 and 3.9 cores: a busy button's mean colour distance
from the bar background goes from 22 to 85 and from 48 to 80, while idle
buttons and the focused one are unchanged.

Also in this release, from the battery alert work:

- alert_gain (35%) sets the loudness of the generated tone, which moves no
  mixer at all.
- alert_vol_min raises the mixer for the tone and puts it back, through
  alert_vol_get / alert_vol_set. The restore is the shell's own EXIT trap, so
  it survives the alert being killed part way through. Not exec'ing the player
  is load-bearing here: exec replaces the shell and takes the trap with it.
- A player that fails during an alert now reports it on the bar. It used to
  fail silently, because swbr is started by sway and its stderr goes nowhere.
- swbr --alert-test fires an alert now, prints the levels, gain and mixer
  floor, plays the tone and reports the player's exit status, and shows what
  alert_cmd would run at each level without running it.
- The shipped example contradicted itself: alert_cmd runs at a level and only
  at a level, so the `[ %c -le 1 ] && poweroff` guard could never be true with
  levels 30,20,10,5. The list is now 30,20,10,5,1.
 README.md               |  1 +
 commit_message.txt      | 28 ++++++++++++++++++++++++++++
 config.advanced.example |  5 +++++
 config.example          |  2 ++
 swbr.c                  | 36 ++++++++++++++++++++++++++++--------
 5 files changed, 64 insertions(+), 8 deletions(-)

diff --git a/README.md b/README.md
index d9622f0..2ed5ffb 100644
--- a/README.md
+++ b/README.md
@@ -340,6 +340,7 @@ panels, and a `poweroff` at one percent. Either goes to
 | `outputs`, `ws_other` | which monitors get a bar, and whose workspaces show |
 | `ws_names`, `ws_inset`, `ws_radius`, `ws_border` | numbers or names, pills or blocks, outlined or not |
 | `ws_slots`, `ws_empty_alpha` | show every number, open or not, and how faint |
+| `ws_cpu`, `ws_cpu_wash` | how busy each workspace is: dots, and a tint |
 | `slim_ws_w`, `slim_bar_segs`, `slim_bar_gap` | folded slot width, gauge blocks |
 | `font`, `font_alt`, `ui_scale`, `text_px` | text |
 | `markup` | the pango subset: `<span foreground=..>`, `<b>`, `&amp;` |
diff --git a/commit_message.txt b/commit_message.txt
new file mode 100644
index 0000000..bff5107
--- /dev/null
+++ b/commit_message.txt
@@ -0,0 +1,28 @@
+swbr: tint busy workspace buttons, and make a failed alert audible
+
+ws_cpu_wash=45 tints a workspace button in the load colour, more of it the
+busier the workspace is. The two-pixel dot column was the only sign before and
+was easy to miss across a whole screen; the dots stay as the scale, the tint
+is what the row says at a glance. The focused workspace keeps its own colour:
+that is a different question and must not become a matter of degree.
+
+Measured offscreen at 0.9 and 3.9 cores: a busy button's mean colour distance
+from the bar background goes from 22 to 85 and from 48 to 80, while idle
+buttons and the focused one are unchanged.
+
+Also in this release, from the battery alert work:
+
+- alert_gain (35%) sets the loudness of the generated tone, which moves no
+  mixer at all.
+- alert_vol_min raises the mixer for the tone and puts it back, through
+  alert_vol_get / alert_vol_set. The restore is the shell's own EXIT trap, so
+  it survives the alert being killed part way through. Not exec'ing the player
+  is load-bearing here: exec replaces the shell and takes the trap with it.
+- A player that fails during an alert now reports it on the bar. It used to
+  fail silently, because swbr is started by sway and its stderr goes nowhere.
+- swbr --alert-test fires an alert now, prints the levels, gain and mixer
+  floor, plays the tone and reports the player's exit status, and shows what
+  alert_cmd would run at each level without running it.
+- The shipped example contradicted itself: alert_cmd runs at a level and only
+  at a level, so the `[ %c -le 1 ] && poweroff` guard could never be true with
+  levels 30,20,10,5. The list is now 30,20,10,5,1.
diff --git a/config.advanced.example b/config.advanced.example
index 0d21940..8689cc1 100644
--- a/config.advanced.example
+++ b/config.advanced.example
@@ -391,6 +391,11 @@ ws_other=1         # 1 = also show the workspaces of your other monitors, as
 ws_cpu=1           # a dot on each workspace button showing how much
                    # processor time the windows on it are using. Folded, the
                    # workspace slot fills from the bottom instead
+ws_cpu_wash=45     # and the whole button tinted in the same colour, up to
+                   # this much at full load: which workspaces are working is
+                   # then the first thing the row says, not something to go
+                   # looking for. 0 = dots only. The focused workspace keeps
+                   # its own colour whatever it is doing
 ws_cpu_interval=3  # seconds between samples
 # tree_min_s=5     # the load dots and source=window cells need sway's tree.
                    # It is fetched only when sway reports a change, and never
diff --git a/config.example b/config.example
index c1f44e5..6bd20a7 100644
--- a/config.example
+++ b/config.example
@@ -32,6 +32,8 @@ refresh=0.25       # how often the bar may redraw, in seconds. Cell updates
 ws_names=1         # 1 = names, 0 = numbers only
 ws_other=1         # also the workspaces of your other monitors, as short pills
 ws_cpu=1           # a column of dots: how busy each workspace is, in cores
+ws_cpu_wash=45     # and a tint across the button, more of it the busier it
+                   # is. 0 = dots only
 ws_border=0        # 1 = a thin outline around every button. 0 = none, just
                    # the gap between them
 ws_slots=10        # always show the numbers 1..10, open or not; a free one
diff --git a/swbr.c b/swbr.c
index c0adc81..b8545db 100644
--- a/swbr.c
+++ b/swbr.c
@@ -1384,6 +1384,7 @@ typedef struct {
     int  ws_names, ws_pad, ws_gap, ws_min_w, ws_click, scroll_workspace, ws_inset;
     int  ws_border;              /* outline thickness in px, 0 = none        */
     int  ws_slots;               /* show this many numbers, used or not      */
+    int  ws_cpu_wash;            /* busy workspaces tinted this much, pct    */
     int  ws_empty_alpha;         /* how visible a free number is, percent    */
     int  slim_bar_segs;          /* folded gauges: this many segments, 0 = solid */
     int  slim_bar_gap;           /* px between those segments                */
@@ -1458,6 +1459,7 @@ static void config_defaults(Config *c)
     c->ws_inset = 0;
     c->ws_border = 0;            /* off: the bar looked busier, not clearer */
     c->ws_slots = 10;
+    c->ws_cpu_wash = 45;
     c->ws_empty_alpha = 35;
     c->slim_bar_segs = 10;
     c->slim_bar_gap = 2;
@@ -1757,6 +1759,7 @@ static void config_set(Config *c, const char *k, const char *v)
     else if (!strcmp(k, "ws_inset")) c->ws_inset = atoi(v);
     else if (!strcmp(k, "ws_border")) c->ws_border = atoi(v);
     else if (!strcmp(k, "ws_slots")) c->ws_slots = atoi(v);
+    else if (!strcmp(k, "ws_cpu_wash")) c->ws_cpu_wash = atoi(v);
     else if (!strcmp(k, "ws_empty_alpha")) c->ws_empty_alpha = atoi(v);
     else if (!strcmp(k, "ws_click")) c->ws_click = atoi(v);
     else if (!strcmp(k, "ws_radius")) c->ws_radius = (float)atof(v);
@@ -4319,6 +4322,22 @@ static void ws_block_draw(Canvas *cv, Bar *b, Font *f, float x, float y0,
                          (float)cfg.ws_border * s,
                          col_scale_alpha(cfg.ws_border_col, bfade));
         }
+        /* A column of dots two pixels wide is easy to miss across a whole
+         * screen. The button itself is tinted in the load colour as well, more
+         * of it the busier the workspace, so which ones are working is the
+         * first thing the row says rather than something to go looking for.
+         * The focused one keeps its own colour: that is a different question
+         * and it must not become a matter of degree. */
+        Col lcol; float lfrac; bool lfaint;
+        bool busy = cpu_load_col(i, &lcol, &lfrac, &lfaint);
+        if (busy && cfg.ws_cpu_wash > 0 && !w->focused) {
+            Col wash = lcol;
+            float k = lfaint ? 0.18f : 0.35f + 0.65f * lfrac;
+            wash.a = (uint8_t)clampf((float)cfg.ws_cpu_wash * k * 2.55f, 0.0f, 255.0f);
+            pill(cv, x, by, bh, bwid, s, mine ? rad : rad * 0.6f,
+                 col_scale_alpha(wash, bfade));
+        }
+
         if (mine)
             text_draw(cv, f, x + (bwid - tw) * 0.5f, base,
                       col_scale_alpha(fg, fade), w->label);
@@ -4330,15 +4349,15 @@ static void ws_block_draw(Canvas *cv, Bar *b, Font *f, float x, float y0,
                       col_scale_alpha(fg, bfade * 0.72f), w->label);
         }
 
-        Col lc; float lf; bool faint;
-        if (cpu_load_col(i, &lc, &lf, &faint)) {
+        if (busy) {
             /* Up the right edge of the button, the same dots as the folded
-             * strip so the two read as one idea. */
+             * strip so the two read as one idea. They are the scale; the wash
+             * is the glance. */
             float dw  = clampf(2.0f * s, 1.0f, 3.0f);
             float pad = 3.0f * s;
             dot_column(cv, x + bwid - dw - pad, by + pad, dw, bh - 2.0f * pad,
-                       2.0f * s, 2.0f * s, faint ? 0.001f : lf,
-                       col_scale_alpha(lc, bfade));
+                       2.0f * s, 2.0f * s, lfaint ? 0.001f : lfrac,
+                       col_scale_alpha(lcol, bfade));
         }
 
         if (b->hits < MAX_WORKSPACES) {
@@ -5915,7 +5934,8 @@ static void usage(void)
 "\n"
 "workspaces\n"
 "  ws_names=0          0 = number only, 1 = the full workspace name\n"
-"  ws_pad=11 ws_gap=4 ws_min_w=0 ws_border=0\n""  ws_slots=10         show the numbers 1..n whether or not they exist\n""  ws_empty_alpha=35   how visible a free number is, percent\n"
+"  ws_pad=11 ws_gap=4 ws_min_w=0 ws_border=0\n""  ws_slots=10         show the numbers 1..n whether or not they exist\n"
+"  ws_cpu_wash=45      how much a busy workspace button is tinted, percent\n""  ws_empty_alpha=35   how visible a free number is, percent\n"
 "  ws_inset=0          gap above and below the buttons; >0 makes them pills\n"
 "  ws_radius=0         0 = square, the button spans the whole bar height\n"
 "                      -1 = a full pill when inset, else follows radius\n"
@@ -6072,10 +6092,10 @@ static void dump_config(void)
            c.min_width, c.align_x, (double)c.radius, c.outputs);
     printf("\n# --- workspaces ---\n");
     printf("ws_names=%d\nws_pad=%d\nws_gap=%d\nws_min_w=%d\nws_inset=%d\nws_radius=%g\n"
-           "ws_border=%d\nws_slots=%d\nws_empty_alpha=%d\n"
+           "ws_border=%d\nws_slots=%d\nws_empty_alpha=%d\nws_cpu_wash=%d\n"
            "ws_click=%d\nscroll_workspace=%d\nmode_show=%d\n",
            c.ws_names, c.ws_pad, c.ws_gap, c.ws_min_w, c.ws_inset, (double)c.ws_radius,
-           c.ws_border, c.ws_slots, c.ws_empty_alpha,
+           c.ws_border, c.ws_slots, c.ws_empty_alpha, c.ws_cpu_wash,
            c.ws_click, c.scroll_workspace, c.mode_show);
     printf("\n# --- text ---\n");
     printf("# font=\n# font_alt=\nui_scale=%g\ntext_px=%g\nws_px=%g\ntext_y=%g\n"