aboutsummaryrefslogtreecommitdiff
path: root/yambar
diff options
context:
space:
mode:
authorHenry J. Webster <hwebs@hwebs.info>2026-08-03 17:32:39 -0500
committerHenry J. Webster <hwebs@hwebs.info>2026-08-03 17:32:39 -0500
commit9717be5863eb56c5163ee79b1b6678867cd68fb0 (patch)
tree7e0882772f1f6bb73c05ebc6de2b126f11137ec6 /yambar
parent6c974e1cb3cddd96a26527ee630582ac310456f3 (diff)
yambar: add niri workspace indicator on the left
Show workspace numbers on the left of the bar, highlighting the focused one. A new niri-workspaces.sh script feeds the focused output's workspace state to yambar's script module (one ws1..ws9 tag per slot: focused / active / exists / none), re-rendering on niri workspace events. Each number is clickable to focus that workspace. Requires jq + niri on the yambar service PATH (added in nixos-config). Assisted-by: Claude Code:claude-opus-4-8
Diffstat (limited to 'yambar')
-rw-r--r--yambar/.config/yambar/config.yml71
-rwxr-xr-xyambar/.config/yambar/niri-workspaces.sh30
2 files changed, 101 insertions, 0 deletions
diff --git a/yambar/.config/yambar/config.yml b/yambar/.config/yambar/config.yml
index f17ec83..aec9fb0 100644
--- a/yambar/.config/yambar/config.yml
+++ b/yambar/.config/yambar/config.yml
@@ -12,6 +12,77 @@ bar:
border:
top-margin: 0
+ left:
+ - script:
+ path: ~/.config/yambar/niri-workspaces.sh
+ content:
+ list:
+ spacing: 10
+ items:
+ - map:
+ on-click: niri msg action focus-workspace 1
+ default: {empty: {}}
+ conditions:
+ ws1 == "focused": {string: {text: "1", foreground: 50fa7bff}}
+ ws1 == "active": {string: {text: "1", foreground: f1fa8cff}}
+ ws1 == "exists": {string: {text: "1", foreground: 6272a4ff}}
+ - map:
+ on-click: niri msg action focus-workspace 2
+ default: {empty: {}}
+ conditions:
+ ws2 == "focused": {string: {text: "2", foreground: 50fa7bff}}
+ ws2 == "active": {string: {text: "2", foreground: f1fa8cff}}
+ ws2 == "exists": {string: {text: "2", foreground: 6272a4ff}}
+ - map:
+ on-click: niri msg action focus-workspace 3
+ default: {empty: {}}
+ conditions:
+ ws3 == "focused": {string: {text: "3", foreground: 50fa7bff}}
+ ws3 == "active": {string: {text: "3", foreground: f1fa8cff}}
+ ws3 == "exists": {string: {text: "3", foreground: 6272a4ff}}
+ - map:
+ on-click: niri msg action focus-workspace 4
+ default: {empty: {}}
+ conditions:
+ ws4 == "focused": {string: {text: "4", foreground: 50fa7bff}}
+ ws4 == "active": {string: {text: "4", foreground: f1fa8cff}}
+ ws4 == "exists": {string: {text: "4", foreground: 6272a4ff}}
+ - map:
+ on-click: niri msg action focus-workspace 5
+ default: {empty: {}}
+ conditions:
+ ws5 == "focused": {string: {text: "5", foreground: 50fa7bff}}
+ ws5 == "active": {string: {text: "5", foreground: f1fa8cff}}
+ ws5 == "exists": {string: {text: "5", foreground: 6272a4ff}}
+ - map:
+ on-click: niri msg action focus-workspace 6
+ default: {empty: {}}
+ conditions:
+ ws6 == "focused": {string: {text: "6", foreground: 50fa7bff}}
+ ws6 == "active": {string: {text: "6", foreground: f1fa8cff}}
+ ws6 == "exists": {string: {text: "6", foreground: 6272a4ff}}
+ - map:
+ on-click: niri msg action focus-workspace 7
+ default: {empty: {}}
+ conditions:
+ ws7 == "focused": {string: {text: "7", foreground: 50fa7bff}}
+ ws7 == "active": {string: {text: "7", foreground: f1fa8cff}}
+ ws7 == "exists": {string: {text: "7", foreground: 6272a4ff}}
+ - map:
+ on-click: niri msg action focus-workspace 8
+ default: {empty: {}}
+ conditions:
+ ws8 == "focused": {string: {text: "8", foreground: 50fa7bff}}
+ ws8 == "active": {string: {text: "8", foreground: f1fa8cff}}
+ ws8 == "exists": {string: {text: "8", foreground: 6272a4ff}}
+ - map:
+ on-click: niri msg action focus-workspace 9
+ default: {empty: {}}
+ conditions:
+ ws9 == "focused": {string: {text: "9", foreground: 50fa7bff}}
+ ws9 == "active": {string: {text: "9", foreground: f1fa8cff}}
+ ws9 == "exists": {string: {text: "9", foreground: 6272a4ff}}
+
right:
- network:
poll-interval: 30000
diff --git a/yambar/.config/yambar/niri-workspaces.sh b/yambar/.config/yambar/niri-workspaces.sh
new file mode 100755
index 0000000..5527ada
--- /dev/null
+++ b/yambar/.config/yambar/niri-workspaces.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+# Feed niri workspace state to yambar's script module.
+#
+# Emits one string tag per workspace slot (ws1..ws9) for the currently
+# focused output, with values: focused / active / exists / none.
+# Re-renders whenever niri reports a workspace change.
+
+emit() {
+ niri msg --json workspaces | jq -r '
+ (first(.[] | select(.is_focused)).output) as $fout
+ | ( reduce (.[] | select(.output == $fout)) as $w ({};
+ .[$w.idx | tostring] =
+ (if $w.is_focused then "focused"
+ elif $w.is_active then "active"
+ else "exists" end)) ) as $st
+ | ( [range(1; 10) | "ws\(.)|string|" + ($st[(. | tostring)] // "none")]
+ | join("\n") ) + "\n"
+ '
+ # blank line commits the update to yambar
+ echo
+}
+
+emit
+niri msg --json event-stream | while read -r line; do
+ case "$line" in
+ *WorkspacesChanged*|*WorkspaceActivated*|*WorkspaceUrgencyChanged*)
+ emit
+ ;;
+ esac
+done