Explicit profile selections from the power panel or menu are now saved under an ac/battery key in ~/.local/state/omarchy/powerprofiles and reapplied on boot and on plug/unplug. Only successful, user-made selections are persisted, so the performance/balanced defaults still apply when nothing has been chosen. All entry points key off the same power signal, UPower's OnBattery: the shell reads it natively and omarchy-powerprofiles-set autodetect queries it via busctl. This replaces the sysfs online checks, which disagreed with the shell on desktops without power_supply entries and lagged behind plug events on some USB-C laptops. Plug/unplug switching moves from the udev rule into the shell's battery service, which already receives UPower's debounced state changes, so the udev rule and its settle-sleep workaround are gone. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
64 lines
1.7 KiB
Bash
Executable File
64 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Set and remember the power profile for AC or battery use
|
|
# omarchy:args=[autodetect|ac|battery] [power-saver|balanced|performance]
|
|
|
|
action="${1:-autodetect}"
|
|
requested_profile="${2:-}"
|
|
|
|
usage() {
|
|
echo "Usage: omarchy-powerprofiles-set [autodetect|ac|battery] [power-saver|balanced|performance]" >&2
|
|
exit 1
|
|
}
|
|
|
|
(( $# <= 2 )) || usage
|
|
|
|
case "$action" in
|
|
autodetect)
|
|
# Use the same signal as the shell (UPower.onBattery) so every entry point
|
|
# saves and restores the profile under the same ac/battery key.
|
|
if [[ $(busctl get-property org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower OnBattery 2>/dev/null) == "b true" ]]; then
|
|
action=battery
|
|
else
|
|
action=ac
|
|
fi
|
|
;;
|
|
ac | battery) ;;
|
|
*) usage ;;
|
|
esac
|
|
|
|
mapfile -t profiles < <(powerprofilesctl list | awk '/^\s*[* ]\s*[a-zA-Z0-9\-]+:$/ { gsub(/^[*[:space:]]+|:$/,""); print }')
|
|
|
|
profile_available() {
|
|
[[ " ${profiles[*]} " == *" $1 "* ]]
|
|
}
|
|
|
|
state_dir="${OMARCHY_POWERPROFILES_STATE_DIR:-${XDG_STATE_HOME:-$HOME/.local/state}/omarchy/powerprofiles}"
|
|
state_file="$state_dir/$action"
|
|
|
|
if [[ -n $requested_profile ]]; then
|
|
profile_available "$requested_profile" || {
|
|
echo "Power profile is not available: $requested_profile" >&2
|
|
exit 1
|
|
}
|
|
|
|
profile="$requested_profile"
|
|
elif [[ -r $state_file ]]; then
|
|
profile=$(<"$state_file")
|
|
fi
|
|
|
|
if [[ -z ${profile:-} ]] || ! profile_available "$profile"; then
|
|
if [[ $action == "ac" ]] && profile_available performance; then
|
|
profile=performance
|
|
else
|
|
profile=balanced
|
|
fi
|
|
fi
|
|
|
|
powerprofilesctl set "$profile" || exit
|
|
|
|
if [[ -n $requested_profile ]]; then
|
|
mkdir -p "$state_dir"
|
|
printf '%s\n' "$requested_profile" >"$state_file"
|
|
fi
|