diff options
| -rw-r--r-- | .config/waybar/config.jsonc | 6 | ||||
| -rwxr-xr-x | .config/waybar/scripts/catloop.sh | 72 | ||||
| -rw-r--r-- | .config/waybar/style.css | 8 | ||||
| -rw-r--r-- | .local/share/fonts/Waycat.ttf | bin | 0 -> 14624 bytes |
4 files changed, 85 insertions, 1 deletions
diff --git a/.config/waybar/config.jsonc b/.config/waybar/config.jsonc index a7b1bba..0666d22 100644 --- a/.config/waybar/config.jsonc +++ b/.config/waybar/config.jsonc @@ -5,7 +5,8 @@ "width": 0, // Waybar width (0 == auto) "spacing": 0, // Gaps between modules "modules-left": [ - "hyprland/workspaces" + "hyprland/workspaces", + "custom/cpucat" ], "modules-center" : [ "hyprland/window" @@ -86,6 +87,9 @@ "interval": "once", "on-click": "~/.local/bin/envyswitch", }, + "custom/cpucat": { + "exec":"~/.config/waybar/scripts/catloop.sh", + }, "cpu": { "format": " {usage:2}%", "interval": 1, diff --git a/.config/waybar/scripts/catloop.sh b/.config/waybar/scripts/catloop.sh new file mode 100755 index 0000000..1de3bb8 --- /dev/null +++ b/.config/waybar/scripts/catloop.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +set -euo pipefail + +CPU_USAGE=0.0 +SLEEP_AFTER=4 + +AWAKE_FRAMES=($(eval echo {A..E})) +SLEEP_FRAMES=($(eval echo {G..N})) + +COUNT=0 + +read_cpu() { + awk '/^cpu /{ + user=$2; nice=$3; sys=$4; idle=$5; + active = user + nice + sys; + total = active + idle; + printf "%d %d\n", active, total; + exit + }' /proc/stat +} + +read prev_active prev_total < <(read_cpu) + +while true; do + + read active total < <(read_cpu) + + delta_active=$((active - prev_active)) + delta_total=$((total - prev_total)) + + if [ "$delta_total" -le 0 ] || [ "$delta_active" -lt 0 ]; then + utilization="0.0000" + else + utilization=$(awk -v a="$delta_active" -v t="$delta_total" 'BEGIN { printf "%.4f", (a / t) }') + fi + + CPU_USAGE=$utilization + + SPEED=$(awk -v u="$CPU_USAGE" 'BEGIN { printf "%.2f", 1 / (4 + (u * 100)) }') + # clip minimum speed + if (( $(echo "$SPEED < 0.03" | bc -l) )); then + SPEED=0.03 + fi + + ### MAKE THE CAT SLEEP IF CPU USAGE IS LOW after SLEEP_AFTER ### + if (( $(echo "$CPU_USAGE < 0.02" | bc -l) )); then + COUNT=$((COUNT + 1)) + else + COUNT=0 + fi + + ### CAT IS SLEEPING ### + if [ $COUNT -ge $SLEEP_AFTER ]; then + for s in "${SLEEP_FRAMES[@]}";do + echo $s + sleep $SPEED + done + + ### CAT IS AWAKE ### + else + for i in "${AWAKE_FRAMES[@]}";do + echo $i + sleep $SPEED + done + + fi + + prev_active=$active + prev_total=$total +done + +# vim: set ts=2 sw=2 diff --git a/.config/waybar/style.css b/.config/waybar/style.css index 212be7c..8b2a620 100644 --- a/.config/waybar/style.css +++ b/.config/waybar/style.css @@ -113,6 +113,14 @@ window#waybar.hidden { } +#custom-cpucat { + font-family: "Waycat", monospace; + font-size: 14px; + font-weight: bold; + color: @foreground; + padding: 0 12px 0 12px; +} + /* If workspaces is the leftmost module, omit left margin */ .modules-left>widget:first-child>#workspaces { margin-left: 0; diff --git a/.local/share/fonts/Waycat.ttf b/.local/share/fonts/Waycat.ttf Binary files differnew file mode 100644 index 0000000..51cc979 --- /dev/null +++ b/.local/share/fonts/Waycat.ttf |
