aboutsummaryrefslogtreecommitdiffstats
path: root/bin/vms_dots.sh
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-15 12:58:31 +0200
committerDanilo M. <danix@danix.xyz>2026-09-15 12:58:31 +0200
commite996b6626c85f8cefb0f357d128091e350ee0ec0 (patch)
treee74b93bb7a7c0451f7e247d541b2b428b096df19 /bin/vms_dots.sh
downloadwaybar-theme-udt-e996b6626c85f8cefb0f357d128091e350ee0ec0.tar.gz
waybar-theme-udt-e996b6626c85f8cefb0f357d128091e350ee0ec0.zip
feat: a waybar bar for DP-3, themed by udt and drawn with icons
Builds the bar from scratch as a consumer of unified-desktop-theme: the palette comes from there, the layout and the modules live here. No font glyphs anywhere. Every symbol is a real icon from the icon theme GTK already uses, which needs all three of waybar's mechanisms because no single one covers everything: the icon-theme config key for the taskbar and tray, `image` modules driving wb-icon/wb-lang for volume, microphone, presentation mode and the keyboard flag, and CSS background-image for the workspaces, the clock pair and the launcher. The workspace icons have to be CSS because format-icons takes text rather than paths, and faking the strip with eight custom modules would have cost click-to-switch and the active and urgent states. The language flag goes the other way: hyprland/language styles as #language with no per-language class, so the flag could not be selected, and it is an image module. Icons keep their own colours: 2466 of the theme's 5169 panel icons carry a hardcoded gradient and are not recolourable, which is the intended look here. The two icons the theme lacks are shipped instead, and the monochrome Slackware mark takes the udt accent at install time. vms_dots.sh and privacy_dots.sh lived only in ~/bin, in no repository at all. They are versioned here now, symlinked back, and their hardcoded state colours read from the palette. Installs alongside the existing bar rather than over it, so DP-1 keeps working while this one is tried on DP-3. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'bin/vms_dots.sh')
-rwxr-xr-xbin/vms_dots.sh89
1 files changed, 89 insertions, 0 deletions
diff --git a/bin/vms_dots.sh b/bin/vms_dots.sh
new file mode 100755
index 0000000..bf95070
--- /dev/null
+++ b/bin/vms_dots.sh
@@ -0,0 +1,89 @@
+#! /bin/bash
+# One dot per defined VM, coloured by state.
+# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+# Licensed under the GNU General Public License v2 only.
+#
+# dependencies: libvirt (virsh), jq
+#
+# The colours come from the palette, not from here: install.sh writes
+# ~/.config/waybar-udt/dots.colors from the selected udt scheme, and this
+# sources it. The defaults below are only what a missing file falls back to,
+# so the bar still draws if the theme has not been installed yet.
+set -euo pipefail
+
+JQ_BIN="${JQ:-jq}"
+
+# Palette. Sourced, with fallbacks, so this script works standalone.
+DOT_SUCCESS="#a6da95"
+DOT_WARNING="#eed49f"
+DOT_CRITICAL="#ed8796"
+DOT_INFO="#8bd5ca"
+DOT_ACCENT="#b7bdf8"
+DOT_FAINT="#6e738d"
+colors="$HOME/.config/waybar-udt/dots.colors"
+# shellcheck source=/dev/null
+[[ -r "$colors" ]] && . "$colors"
+
+# Require virsh
+if ! command -v virsh >/dev/null 2>&1; then
+ $JQ_BIN -cn '{text: "", tooltip: "virsh not found", class: "vmdot"}'
+ exit 0
+fi
+
+# Collect all defined VMs and their states.
+# virsh list --all columns: Id Name State (state may be multi-word, e.g. "shut off")
+declare -A vm_states
+while IFS= read -r line; do
+ # Skip header lines and separator lines
+ [[ "$line" =~ ^[[:space:]]*Id[[:space:]] ]] && continue
+ [[ "$line" =~ ^[-[:space:]]+$ ]] && continue
+ [[ -z "${line// }" ]] && continue
+
+ # Fields: id (may be "-"), name, state (rest of line)
+ read -r _id name state_rest <<< "$line"
+ vm_states["$name"]="$state_rest"
+done < <(virsh list --all 2>/dev/null)
+
+if [[ ${#vm_states[@]} -eq 0 ]]; then
+ $JQ_BIN -cn '{text: "", tooltip: "No VMs defined", class: "vmdot"}'
+ exit 0
+fi
+
+# libvirt state → palette role.
+declare -A state_color=(
+ ["running"]="$DOT_SUCCESS"
+ ["idle"]="$DOT_WARNING" # running but idle
+ ["paused"]="$DOT_WARNING"
+ ["pmsuspended"]="$DOT_ACCENT" # PM sleep / ACPI S3
+ ["saved"]="$DOT_INFO" # managed save
+ ["crashed"]="$DOT_CRITICAL"
+ ["shut off"]="$DOT_FAINT"
+)
+fallback_color="$DOT_FAINT" # any unknown future state
+
+dots=()
+tooltip_parts=()
+classes="vmdot"
+
+# Sort VM names for stable ordering
+mapfile -t sorted_names < <(printf '%s\n' "${!vm_states[@]}" | sort)
+
+for name in "${sorted_names[@]}"; do
+ state="${vm_states[$name]}"
+ color="${state_color[$state]:-$fallback_color}"
+ # Derive a CSS-safe class token (spaces → hyphens)
+ state_class="${state// /-}"
+
+ dots+=("<span foreground=\"${color}\">●</span>")
+ classes="$classes vm-${state_class}"
+ tooltip_parts+=("${name}: ${state}")
+done
+
+text="${dots[*]}"
+tooltip="$(IFS=' | '; echo "${tooltip_parts[*]}")"
+
+$JQ_BIN -cn \
+ --arg text "$text" \
+ --arg tooltip "$tooltip" \
+ --arg class "$classes" \
+ '{text: $text, tooltip: $tooltip, class: $class}'