From 54689f978144bf43ebcb0f17e0e1c6e9d3e0f2f2 Mon Sep 17 00:00:00 2001 From: funman300 Date: Wed, 22 Apr 2026 17:27:29 -0700 Subject: [PATCH] Add power profile and fan strategy waybar modules - scripts/power-profile.sh: waybar module + wofi menu for powerprofilesctl - scripts/fan-profile.sh: waybar module + wofi menu for fw-fanctrl - waybar/config.jsonc: add custom/power-profile and custom/fan-profile modules - waybar/style.css: add padding and class colors for new modules - packages.txt: add power-profiles-daemon and fw-fanctrl - install.sh: symlink new scripts to ~/.local/bin --- install.sh | 2 ++ packages.txt | 2 ++ scripts/fan-profile.sh | 33 +++++++++++++++++++++++++++++++++ scripts/power-profile.sh | 26 ++++++++++++++++++++++++++ waybar/config.jsonc | 18 +++++++++++++++++- waybar/style.css | 11 ++++++++++- 6 files changed, 90 insertions(+), 2 deletions(-) create mode 100755 scripts/fan-profile.sh create mode 100755 scripts/power-profile.sh diff --git a/install.sh b/install.sh index c23f1a5..fd89d87 100755 --- a/install.sh +++ b/install.sh @@ -30,6 +30,8 @@ echo "==> Installing scripts" mkdir -p ~/.local/bin ln -sf "$(pwd)/scripts/powermenu.sh" ~/.local/bin/powermenu ln -sf "$(pwd)/scripts/clipboard.sh" ~/.local/bin/clipboard-picker +ln -sf "$(pwd)/scripts/power-profile.sh" ~/.local/bin/power-profile +ln -sf "$(pwd)/scripts/fan-profile.sh" ~/.local/bin/fan-profile echo "==> Enabling systemd user services" mkdir -p ~/.config/systemd/user diff --git a/packages.txt b/packages.txt index 791766f..aef6d95 100644 --- a/packages.txt +++ b/packages.txt @@ -33,4 +33,6 @@ zathura-pdf-mupdf thunar-archive-plugin file-roller xwayland-satellite +power-profiles-daemon +fw-fanctrl diff --git a/scripts/fan-profile.sh b/scripts/fan-profile.sh new file mode 100755 index 0000000..9540d15 --- /dev/null +++ b/scripts/fan-profile.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +if [ "$1" = "--menu" ]; then + CHOICE=$(fw-fanctrl print list 2>/dev/null \ + | grep "^-" \ + | sed 's/^- //' \ + | wofi --dmenu \ + --prompt "Fan Strategy:" \ + --width 260 \ + --height 300 \ + --hide-scroll \ + --no-actions \ + --insensitive) + [ -n "$CHOICE" ] && fw-fanctrl use "$CHOICE" && pkill -RTMIN+9 waybar + exit +fi + +OUTPUT=$(fw-fanctrl print 2>/dev/null) +CURRENT=$(echo "$OUTPUT" | awk -F"'" '/^Strategy:/{print $2}') +SPEED=$(echo "$OUTPUT" | awk '/^Speed:/{print $2}') + +case "$CURRENT" in + laziest|deaf) ICON="󰈐"; LEVEL="silent" ;; + lazy) ICON="󰈐"; LEVEL="quiet" ;; + medium) ICON="󰈐"; LEVEL="medium" ;; + agile) ICON="󰈐"; LEVEL="agile" ;; + very-agile) ICON="󰈐"; LEVEL="fast" ;; + aeolus) ICON="󰈐"; LEVEL="max" ;; + *) ICON="󰈐"; LEVEL="$CURRENT" ;; +esac + +printf '{"text": "%s %s", "tooltip": "Fan strategy: %s\\nSpeed: %s\\nClick to change", "class": "%s"}\n' \ + "$ICON" "$CURRENT" "$CURRENT" "$SPEED" "$LEVEL" diff --git a/scripts/power-profile.sh b/scripts/power-profile.sh new file mode 100755 index 0000000..ef42754 --- /dev/null +++ b/scripts/power-profile.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +if [ "$1" = "--menu" ]; then + CHOICE=$(printf "󰓅 performance\n󰕲 balanced\n󰌪 power-saver" \ + | wofi --dmenu \ + --prompt "Power Profile:" \ + --width 260 \ + --height 160 \ + --hide-scroll \ + --no-actions \ + --insensitive \ + | awk '{print $NF}') + [ -n "$CHOICE" ] && powerprofilesctl set "$CHOICE" && pkill -RTMIN+8 waybar + exit +fi + +CURRENT=$(powerprofilesctl get) +case "$CURRENT" in + performance) ICON="󰓅" ;; + balanced) ICON="󰕲" ;; + power-saver) ICON="󰌪" ;; + *) ICON="" ;; +esac + +printf '{"text": "%s %s", "tooltip": "Power profile: %s\\nClick to change", "class": "%s"}\n' \ + "$ICON" "$CURRENT" "$CURRENT" "$CURRENT" diff --git a/waybar/config.jsonc b/waybar/config.jsonc index a1a16c2..4601aab 100644 --- a/waybar/config.jsonc +++ b/waybar/config.jsonc @@ -5,7 +5,23 @@ "modules-left": ["niri/workspaces"], "modules-center": ["clock"], - "modules-right": ["pulseaudio", "network", "battery", "tray"], + "modules-right": ["custom/power-profile", "custom/fan-profile", "pulseaudio", "network", "battery", "tray"], + + "custom/power-profile": { + "exec": "~/.local/bin/power-profile", + "return-type": "json", + "interval": 30, + "signal": 8, + "on-click": "~/.local/bin/power-profile --menu" + }, + + "custom/fan-profile": { + "exec": "~/.local/bin/fan-profile", + "return-type": "json", + "interval": 5, + "signal": 9, + "on-click": "~/.local/bin/fan-profile --menu" + }, "clock": { "format": "{:%a %b %d %H:%M}" diff --git a/waybar/style.css b/waybar/style.css index edad14b..a119ff0 100644 --- a/waybar/style.css +++ b/waybar/style.css @@ -17,10 +17,19 @@ window#waybar { color: #81a2be; } -#clock, #battery, #network, #pulseaudio { +#clock, #battery, #network, #pulseaudio, +#custom-power-profile, #custom-fan-profile { padding: 0 12px; } +#custom-power-profile.performance { + color: #f0c674; +} + +#custom-power-profile.power-saver { + color: #b5bd68; +} + #battery.warning { color: #f0c674; }