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:
@@ -23,15 +23,54 @@ snapshot_baseline() {
|
|||||||
if [ -f "$FAN_AUTO" ]; then echo 1; else echo 0; fi > "$STATE_DIR/baseline.fanauto"
|
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) -------------
|
# --- effects ------------------------------------------------------------------
|
||||||
effect_idle_on() { run : "idle inhibit on"; }
|
effect_idle_on() {
|
||||||
effect_idle_off() { run : "idle inhibit off"; }
|
if [ "$DRYRUN" = 1 ]; then log "would: systemd-inhibit idle"; return; fi
|
||||||
effect_dnd_on() { run : "dnd on"; }
|
command -v systemd-inhibit >/dev/null 2>&1 || { log "no systemd-inhibit"; return; }
|
||||||
effect_dnd_off() { run : "dnd off"; }
|
systemd-inhibit --what=idle --who=gamemode --why="gaming session" --mode=block \
|
||||||
effect_perf_on() { run : "perf on"; }
|
sleep infinity >/dev/null 2>&1 &
|
||||||
effect_perf_off() { run : "perf off"; }
|
echo $! > "$STATE_DIR/idle.pid"
|
||||||
effect_waybar_on() { run : "waybar hide"; }
|
}
|
||||||
effect_waybar_off(){ run : "waybar restore"; }
|
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; }
|
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; }
|
revert_effects() { effect_idle_off; effect_dnd_off; effect_perf_off; effect_waybar_off; }
|
||||||
|
|||||||
Reference in New Issue
Block a user