From 88906113038c1b4986cfc3bf6afc0fb35c5e4127 Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Tue, 21 Apr 2026 01:24:42 +0100 Subject: waybar: heat-colour CPU/memory/wifi %/temperature values via pango --- dot_config/waybar/config.jsonc | 25 +++++++++++++++++++++-- dot_config/waybar/executable_memory-status.sh | 29 +++++++++++++++++++++++++++ dot_config/waybar/executable_wifi-status.sh | 10 +++++++-- 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100755 dot_config/waybar/executable_memory-status.sh (limited to 'dot_config/waybar') diff --git a/dot_config/waybar/config.jsonc b/dot_config/waybar/config.jsonc index b4d03ab..585fa38 100644 --- a/dot_config/waybar/config.jsonc +++ b/dot_config/waybar/config.jsonc @@ -27,19 +27,40 @@ "cpu": { "format": "CPU {usage}%", + "format-low": "CPU {usage}%", + "format-medium": "CPU {usage}%", + "format-high": "CPU {usage}%", + "format-critical": "CPU {usage}%", + "states": { + "low": 0, + "medium": 30, + "high": 60, + "critical": 80, + }, "interval": 5, "tooltip": false, }, "custom/memory": { - "exec": "awk '/^MemTotal:/{t=$2} /^MemAvailable:/{a=$2} END{u=t-a; printf \"MEM %.1fG (%d%%) / %.1fG (%d%%)\\n\", u/1048576, u*100/t, a/1048576, a*100/t}' /proc/meminfo", + "exec": "~/.config/waybar/memory-status.sh", + "return-type": "json", "interval": 10, "tooltip": false, }, "temperature": { "format": "{temperatureC}°C", - "critical-threshold": 80, + "format-cool": "{temperatureC}°C", + "format-warm": "{temperatureC}°C", + "format-hot": "{temperatureC}°C", + "format-scorching": "{temperatureC}°C", + "states": { + "cool": 0, + "warm": 50, + "hot": 65, + "scorching": 80, + }, + "interval": 5, }, "custom/wifi": { diff --git a/dot_config/waybar/executable_memory-status.sh b/dot_config/waybar/executable_memory-status.sh new file mode 100755 index 0000000..c68f5a4 --- /dev/null +++ b/dot_config/waybar/executable_memory-status.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# Emit waybar JSON with memory usage. Used% uses a heat scale (green → red), +# available% uses the inverse (red → green). Values embedded via Pango span. +set -eu + +awk ' +function heat(p) { + if (p < 30) return "#b8bb26" + if (p < 60) return "#fabd2f" + if (p < 80) return "#fe8019" + return "#fb4934" +} +function cool(p) { + if (p < 20) return "#fb4934" + if (p < 40) return "#fe8019" + if (p < 70) return "#fabd2f" + return "#b8bb26" +} +/^MemTotal:/ { t = $2 } +/^MemAvailable:/ { a = $2 } +END { + u = t - a + up = u * 100 / t + ap = a * 100 / t + printf "{\"text\":\"MEM %.1fG (%d%%) / %.1fG (%d%%)\"}\n", \ + u / 1048576, heat(up), up, \ + a / 1048576, cool(ap), ap +} +' /proc/meminfo diff --git a/dot_config/waybar/executable_wifi-status.sh b/dot_config/waybar/executable_wifi-status.sh index b93a28c..e69e5bb 100755 --- a/dot_config/waybar/executable_wifi-status.sh +++ b/dot_config/waybar/executable_wifi-status.sh @@ -22,6 +22,12 @@ rssi=$(printf '%s\n' "$out" | sed -n 's/^[[:space:]]*\*\{0,1\}[[:space:]]*AverageRSSI[[:space:]]\{2,\}//p' | awk '{print $1; exit}') pct=$(awk -v r="${rssi:-0}" 'BEGIN{p=2*(r+100); if(p>100)p=100; if(p<0)p=0; printf "%d",p}') +color=$(awk -v p="$pct" 'BEGIN{ + if (p < 20) print "#fb4934" + else if (p < 40) print "#fe8019" + else if (p < 70) print "#fabd2f" + else print "#b8bb26" +}') -printf '{"text":"%s %s%%","class":"up","tooltip":"%s · %s dBm"}\n' \ - "$ssid" "$pct" "$iface" "$rssi" +printf '{"text":"%s %s%%","class":"up","tooltip":"%s · %s dBm"}\n' \ + "$ssid" "$color" "$pct" "$iface" "$rssi" -- cgit v1.2.3-70-g09d2