Krolyxon
Commit 35d4d85

Branches

Refs →

aurora35d4d85

waybar: add waycat/cpucat custom module

Author
krolyxon
Date
2026-09-18 12:11 +0530
Parent
9ec4b19
Commit
35d4d854cbce40194ea34a16803ed5d46556a808

+85 −1

4 files changed

  1. M .config/waybar/config.jsonc +5 −1
  2. A .config/waybar/scripts/catloop.sh +72 −0
  3. M .config/waybar/style.css +8 −0
  4. A .local/share/fonts/Waycat.ttf
M .config/waybar/config.jsonc View
@@ -5,7 +5,8 @@
55 "width": 0, // Waybar width (0 == auto)
66 "spacing": 0, // Gaps between modules
77 "modules-left": [
8− "hyprland/workspaces"
8+ "hyprland/workspaces",
9+ "custom/cpucat"
910 ],
1011 "modules-center" : [
1112 "hyprland/window"
@@ -86,6 +87,9 @@
8687 "interval": "once",
8788 "on-click": "~/.local/bin/envyswitch",
8889 },
90+ "custom/cpucat": {
91+ "exec":"~/.config/waybar/scripts/catloop.sh",
92+ },
8993 "cpu": {
9094 "format": " {usage:2}%",
9195 "interval": 1,
A .config/waybar/scripts/catloop.sh View
@@ -0,0 +1,72 @@
1+#!/usr/bin/env bash
2+set -euo pipefail
3+
4+CPU_USAGE=0.0
5+SLEEP_AFTER=4
6+
7+AWAKE_FRAMES=($(eval echo {A..E}))
8+SLEEP_FRAMES=($(eval echo {G..N}))
9+
10+COUNT=0
11+
12+read_cpu() {
13+ awk '/^cpu /{
14+ user=$2; nice=$3; sys=$4; idle=$5;
15+ active = user + nice + sys;
16+ total = active + idle;
17+ printf "%d %d\n", active, total;
18+ exit
19+ }' /proc/stat
20+}
21+
22+read prev_active prev_total < <(read_cpu)
23+
24+while true; do
25+
26+ read active total < <(read_cpu)
27+
28+ delta_active=$((active - prev_active))
29+ delta_total=$((total - prev_total))
30+
31+ if [ "$delta_total" -le 0 ] || [ "$delta_active" -lt 0 ]; then
32+ utilization="0.0000"
33+ else
34+ utilization=$(awk -v a="$delta_active" -v t="$delta_total" 'BEGIN { printf "%.4f", (a / t) }')
35+ fi
36+
37+ CPU_USAGE=$utilization
38+
39+ SPEED=$(awk -v u="$CPU_USAGE" 'BEGIN { printf "%.2f", 1 / (4 + (u * 100)) }')
40+ # clip minimum speed
41+ if (( $(echo "$SPEED < 0.03" | bc -l) )); then
42+ SPEED=0.03
43+ fi
44+
45+ ### MAKE THE CAT SLEEP IF CPU USAGE IS LOW after SLEEP_AFTER ###
46+ if (( $(echo "$CPU_USAGE < 0.02" | bc -l) )); then
47+ COUNT=$((COUNT + 1))
48+ else
49+ COUNT=0
50+ fi
51+
52+ ### CAT IS SLEEPING ###
53+ if [ $COUNT -ge $SLEEP_AFTER ]; then
54+ for s in "${SLEEP_FRAMES[@]}";do
55+ echo $s
56+ sleep $SPEED
57+ done
58+
59+ ### CAT IS AWAKE ###
60+ else
61+ for i in "${AWAKE_FRAMES[@]}";do
62+ echo $i
63+ sleep $SPEED
64+ done
65+
66+ fi
67+
68+ prev_active=$active
69+ prev_total=$total
70+done
71+
72+# vim: set ts=2 sw=2
M .config/waybar/style.css View
@@ -113,6 +113,14 @@ window#waybar.hidden {
113113
114114 }
115115
116+#custom-cpucat {
117+ font-family: "Waycat", monospace;
118+ font-size: 14px;
119+ font-weight: bold;
120+ color: @foreground;
121+ padding: 0 12px 0 12px;
122+}
123+
116124 /* If workspaces is the leftmost module, omit left margin */
117125 .modules-left>widget:first-child>#workspaces {
118126 margin-left: 0;
A .local/share/fonts/Waycat.ttf View

[Binary file]