370b4aa096
map_profile_to_strategy never writes to stderr — the suppression was silencing nothing real and would mislead a future reader. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
68 lines
2.4 KiB
Bash
Executable File
68 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
STATE_FILE="${XDG_STATE_HOME:-$HOME/.local/state}/fan-profile-auto"
|
|
|
|
map_profile_to_strategy() {
|
|
case "$1" in
|
|
power-saver) echo lazy ;;
|
|
balanced) echo medium ;;
|
|
performance) echo agile ;;
|
|
*) return 1 ;;
|
|
esac
|
|
}
|
|
|
|
if [ "$1" = "--menu" ]; then
|
|
STRATS=$(fw-fanctrl print list 2>/dev/null | grep "^-" | sed 's/^- //')
|
|
CHOICE=$(printf 'auto\n%s\n' "$STRATS" \
|
|
| wofi --dmenu \
|
|
--prompt "Fan Strategy:" \
|
|
--width 260 \
|
|
--height 320 \
|
|
--hide-scroll \
|
|
--no-actions \
|
|
--insensitive)
|
|
[ -z "$CHOICE" ] && exit
|
|
if [ "$CHOICE" = "auto" ]; then
|
|
mkdir -p "$(dirname "$STATE_FILE")"
|
|
touch "$STATE_FILE"
|
|
PROFILE=$(powerprofilesctl get 2>/dev/null) \
|
|
&& MAPPED=$(map_profile_to_strategy "$PROFILE") \
|
|
&& fw-fanctrl use "$MAPPED"
|
|
else
|
|
rm -f "$STATE_FILE"
|
|
fw-fanctrl use "$CHOICE"
|
|
fi
|
|
pkill -RTMIN+9 waybar
|
|
exit
|
|
fi
|
|
|
|
if [ -f "$STATE_FILE" ]; then
|
|
PROFILE=$(powerprofilesctl get 2>/dev/null)
|
|
MAPPED=$(map_profile_to_strategy "$PROFILE")
|
|
if [ -n "$MAPPED" ]; then
|
|
ACTIVE=$(fw-fanctrl print 2>/dev/null | awk -F"'" '/^Strategy:/{print $2}')
|
|
[ "$ACTIVE" != "$MAPPED" ] && fw-fanctrl use "$MAPPED" >/dev/null 2>&1
|
|
printf '{"text": " auto", "tooltip": "Auto fan strategy\\nProfile: %s → %s\\nClick to change", "class": "auto"}\n' "$PROFILE" "$MAPPED"
|
|
else
|
|
printf '{"text": " auto (?)", "tooltip": "Auto: power-profiles-daemon unreachable or unknown profile\\nClick to change", "class": "auto"}\n'
|
|
fi
|
|
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"
|