feat(rofi): battery charge-limit toggle in the System menu
All checks were successful
Check / eval (push) Successful in 2m54s
All checks were successful
Check / eval (push) Successful in 2m54s
Add a `batterylimit` nomarchy-menu subcommand — a preset picker (80/90/60/Off/Custom…) that writes settings.power.batteryChargeLimit via theme-sync (--no-switch; lands on the next sys-rebuild, power.nix's oneshot applies it). Surfaced as a first-class System row, self-gated on the charge_control_end_threshold sysfs node like Power profile. Moved out of the gum control-center (removed its Battery Limit case + choose entry) so the toggle lives in one place — the rofi menu Bernardo actually uses, per his request. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -692,6 +692,10 @@ ${themeRows}
|
||||
if [ -e "''${bats[0]}" ] && command -v powerprofilesctl >/dev/null 2>&1; then
|
||||
row "Power profile" preferences-system-power
|
||||
fi
|
||||
# Self-gated on the charge-threshold sysfs node (laptops that
|
||||
# expose it), like Power profile above.
|
||||
[ -e "''${bats[0]}/charge_control_end_threshold" ] \
|
||||
&& row "Battery limit" battery-080
|
||||
back
|
||||
} | rofi -dmenu -show-icons -markup-rows -p System) || exit 0
|
||||
case "$choice" in
|
||||
@@ -710,6 +714,50 @@ ${themeRows}
|
||||
*Doctor*) exec "$0" doctor ;;
|
||||
*"Control Center"*) exec "$0" controlcenter ;;
|
||||
*"Power profile"*) exec "$0" power-profile ;;
|
||||
*"Battery limit"*) exec "$0" batterylimit ;;
|
||||
esac ;;
|
||||
|
||||
batterylimit)
|
||||
# Battery charge-limit preset picker — the rofi-System counterpart of
|
||||
# the control-center's toggle (Bernardo: he wanted this in the menu,
|
||||
# not buried in the gum TUI). Writes the baked NixOS option
|
||||
# settings.power.batteryChargeLimit via theme-sync (--no-switch), so
|
||||
# it lands on the next sys-rebuild — the sysfs oneshot in power.nix
|
||||
# owns applying it (boot + AC-replug). Self-gated in System; guard
|
||||
# here too in case it's invoked directly.
|
||||
bats=(/sys/class/power_supply/BAT*)
|
||||
[ -e "''${bats[0]}/charge_control_end_threshold" ] \
|
||||
|| { notify-send "Battery limit" "No charge-threshold control on this machine."; exit 0; }
|
||||
cur=$(nomarchy-theme-sync get settings.power.batteryChargeLimit 2>/dev/null)
|
||||
sel=$( {
|
||||
row "80% (recommended)" battery-080
|
||||
row "90%" battery-090
|
||||
row "60%" battery-060
|
||||
row "Off — charge to 100%" battery-100
|
||||
row "Custom…" battery
|
||||
back
|
||||
} | rofi -dmenu -show-icons -p "Battery limit (now: ''${cur:-default})") || exit 0
|
||||
set_limit() {
|
||||
nomarchy-theme-sync --quiet set settings.power.batteryChargeLimit "$1" --no-switch
|
||||
notify-send "Battery limit" "$2 — applies on the next rebuild."
|
||||
}
|
||||
case "$sel" in
|
||||
"$BACK") exec "$0" system ;;
|
||||
"80%"*) set_limit 80 "Set to 80%" ;;
|
||||
"90%"*) set_limit 90 "Set to 90%" ;;
|
||||
"60%"*) set_limit 60 "Set to 60%" ;;
|
||||
"Off"*) set_limit null "Off — charges to 100%" ;;
|
||||
"Custom"*)
|
||||
limit=$(rofi -dmenu -p "Charge limit % (50–100)" < /dev/null) || exit 0
|
||||
[ -n "$limit" ] || exit 0
|
||||
case "$limit" in
|
||||
*[!0-9]*) notify-send "Battery limit" "Not a whole number: $limit"; exit 0 ;;
|
||||
esac
|
||||
if [ "$limit" -ge 50 ] && [ "$limit" -le 100 ]; then
|
||||
set_limit "$limit" "Set to $limit%"
|
||||
else
|
||||
notify-send "Battery limit" "Out of range (50–100): $limit"
|
||||
fi ;;
|
||||
esac ;;
|
||||
|
||||
"")
|
||||
@@ -734,7 +782,7 @@ ${themeRows}
|
||||
esac ;;
|
||||
|
||||
*)
|
||||
echo "usage: nomarchy-menu [lookfeel|tools|system|power|power-profile|theme|clipboard|calc|files|emoji|web|network|bluetooth|audio|display|display-profile|printers|capture|colorpicker|keybinds|ask|dnd|nightlight|autotimezone|autocommit|vpn|snapshot]" >&2
|
||||
echo "usage: nomarchy-menu [lookfeel|tools|system|power|power-profile|batterylimit|theme|clipboard|calc|files|emoji|web|network|bluetooth|audio|display|display-profile|printers|capture|colorpicker|keybinds|ask|dnd|nightlight|autotimezone|autocommit|vpn|snapshot]" >&2
|
||||
exit 64 ;;
|
||||
esac
|
||||
'';
|
||||
|
||||
Reference in New Issue
Block a user