CachyOS / CachyOS/CachyOS-Settings
[BUG] The power-profiles-daemon reverts to the wrong gear after a game launched by the game-performance script exits.
- Dominant language
- Shell
- Stars
- 443
- Forks
- 76
- PR merge metrics
- No merged PRs in 30d
Description
### Problem Description
I had configured my KDE settings to switch to performance mode when plugged in and to balance mode when using battery, and I had also enabled "Limit maximum charge level" (though this shouldn't have any effect).
However, every time I launch Counter-Strike 2 on Steam using the launch option `LD_PRELOAD="" prime-run game-performance mangohud %command% -...`, after exiting, I always find that my original performance mode has been switched back to balance.
### Device Info
[output from cachyos_bugreport.sh](https://paste.cachyos.org/p/8f622da.log)
**MY GUESS:**
This is most likely another minor issue with PPD's internal implementation. I worked around the game-performance script to fix it.
```bash
#!/usr/bin/env bash
if ! command -v powerprofilesctl &>/dev/null; then
echo "Error: powerprofilesctl not found" >&2
exit 1
fi
# 1. Capture the initial state
PREVIOUS_PROFILE=$(powerprofilesctl get 2>/dev/null)
TARGET_PROFILE="performance"
# 2. Check if performance profile is even available
if ! powerprofilesctl list | grep -q "${TARGET_PROFILE}:"; then
exec "$@"
fi
# 3. Logic: If we are already in performance mode, don't use 'launch'
# 'launch' creates a temporary hold that resets to 'balanced' on exit.
# By skipping 'launch' when already in performance, we avoid the reset.
if [ "$PREVIOUS_PROFILE" = "$TARGET_PROFILE" ]; then
if [ -n "$GAME_PERFORMANCE_SCREENSAVER_ON" ]; then
exec "$@"
else
# Still inhibit sleep/screensaver, but don't touch power profiles
exec systemd-inhibit --why "Game is running (Performance already active)" -- "$@"
fi
fi
# 4. If we are NOT in performance mode, use 'launch' to switch temporarily
# and then explicitly restore the PREVIOUS_PROFILE after the game exits.
run_game() {
if [ -z "$GAME_PERFORMANCE_SCREENSAVER_ON" ]; then
systemd-inhibit --why "CachyOS game-performance is running" \
powerprofilesctl launch -p "$TARGET_PROFILE" \
-r "Launched with CachyOS game-performance utility" -- "$@"
else
powerprofilesctl launch -p "$TARGET_PROFILE" \
-r "Launched with CachyOS game-performance utility" -- "$@"
fi
# 5. Safety net: Explicitly restore the previous profile
# This fixes cases where 'launch' defaults back to 'balanced'
powerprofilesctl set "$PREVIOUS_PROFILE"
}
run_game "$@"
```
If there's no problem pls merge.
Contributor guide
Assessment
This issue has not been assessed yet.