gamemode-session: real effects (idle, DND, perf+fan, waybar)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
funman300
2026-07-15 21:32:32 -07:00
parent 05707afc04
commit 4b1773ac4e
+48 -9
View File
@@ -23,15 +23,54 @@ snapshot_baseline() {
if [ -f "$FAN_AUTO" ]; then echo 1; else echo 0; fi > "$STATE_DIR/baseline.fanauto"
}
# --- effects (bodies filled in Task 2; dryrun-safe stubs for now) -------------
effect_idle_on() { run : "idle inhibit on"; }
effect_idle_off() { run : "idle inhibit off"; }
effect_dnd_on() { run : "dnd on"; }
effect_dnd_off() { run : "dnd off"; }
effect_perf_on() { run : "perf on"; }
effect_perf_off() { run : "perf off"; }
effect_waybar_on() { run : "waybar hide"; }
effect_waybar_off(){ run : "waybar restore"; }
# --- effects ------------------------------------------------------------------
effect_idle_on() {
if [ "$DRYRUN" = 1 ]; then log "would: systemd-inhibit idle"; return; fi
command -v systemd-inhibit >/dev/null 2>&1 || { log "no systemd-inhibit"; return; }
systemd-inhibit --what=idle --who=gamemode --why="gaming session" --mode=block \
sleep infinity >/dev/null 2>&1 &
echo $! > "$STATE_DIR/idle.pid"
}
effect_idle_off() {
local pid; pid=$(cat "$STATE_DIR/idle.pid" 2>/dev/null || echo "")
[ -n "$pid" ] && run kill "$pid"
rm -f "$STATE_DIR/idle.pid"
}
effect_dnd_on() { command -v makoctl >/dev/null 2>&1 && run makoctl mode -a do-not-disturb; }
effect_dnd_off() { command -v makoctl >/dev/null 2>&1 && run makoctl mode -r do-not-disturb; }
# maps a power profile to the fw-fanctrl strategy (mirrors fan-profile.sh)
fan_for() { case "$1" in power-saver) echo lazy;; balanced) echo medium;; performance) echo agile;; *) return 1;; esac; }
effect_perf_on() {
local base; base=$(cat "$STATE_DIR/baseline.profile" 2>/dev/null || echo "")
if [ -n "$base" ] && [ "$base" != performance ]; then
run powerprofilesctl set performance
run pkill -RTMIN+8 waybar
fi
if [ "$(cat "$STATE_DIR/baseline.fanauto" 2>/dev/null)" = 1 ]; then
run fw-fanctrl use agile
fi
}
effect_perf_off() {
local base; base=$(cat "$STATE_DIR/baseline.profile" 2>/dev/null || echo "")
if [ -n "$base" ] && [ "$base" != performance ]; then
run powerprofilesctl set "$base"
run pkill -RTMIN+8 waybar
fi
if [ -n "$base" ] && [ "$(cat "$STATE_DIR/baseline.fanauto" 2>/dev/null)" = 1 ]; then
local strat; strat=$(fan_for "$base") && run fw-fanctrl use "$strat"
fi
}
effect_waybar_on() { # hide
pgrep -x waybar >/dev/null 2>&1 && run pkill -x waybar
}
effect_waybar_off() { # restore if it was running at entry
[ "$(cat "$STATE_DIR/baseline.waybar" 2>/dev/null)" = 1 ] || return 0
if [ "$DRYRUN" = 1 ]; then log "would: relaunch waybar"; else setsid waybar >/dev/null 2>&1 & fi
}
apply_effects() { effect_idle_on; effect_dnd_on; effect_perf_on; effect_waybar_on; }
revert_effects() { effect_idle_off; effect_dnd_off; effect_perf_off; effect_waybar_off; }