Let the idle timings know whether you are plugged in

An idle screen costs a screen on wall power and the rest of your
afternoon on battery, so they should not be the same number. hypridle
has no concept of a power source -- one config, one set of timeouts --
so rather than maintaining two configs and swapping them, panama-idle
builds the single config from whichever key set applies, and IdleLock
rebuilds it when the charger comes or goes. That runs through the same
400ms debounce a settings change uses, so a loose charger cannot
restart hypridle in a loop.

The battery keys fall back to their AC counterparts rather than to the
schema defaults. Without that, unplugging would silently override a
deliberately long timing with a shipped short one, which is the kind
of thing you would notice only by losing work.

A machine with no battery reads none of it and generates exactly what
it generated before. The contract pins that alongside the two obvious
directions, and was checked by sabotaging the detection to confirm it
fails rather than passing vacuously.
This commit is contained in:
Gabriel Brown
2026-08-21 22:18:29 -04:00
parent 3c359f3f7e
commit bc6d63b70f
8 changed files with 187 additions and 8 deletions
@@ -1003,6 +1003,33 @@ Singleton {
detail: "Requires your password when the machine wakes"
},
// The same three timings again, for when the machine is running on
// its own battery. hypridle has no concept of a power source, so
// there is one generated config and panama-idle rebuilds it from
// whichever set applies when the charger comes or goes.
//
// Shorter defaults, because the cost of an idle screen differs: on
// wall power it is a screen, on battery it is the rest of your
// afternoon. A machine with no battery never reads these at all.
{
key: "screenBlankMinutesBattery", type: "int", def: 2, min: 0, max: 120, step: 1,
unit: "min", group: "idleBattery",
label: "Turn the screen off after",
detail: "On battery. Blanks the display; nothing is locked yet"
},
{
key: "lockMinutesBattery", type: "int", def: 5, min: 0, max: 240, step: 1,
unit: "min", group: "idleBattery",
label: "Lock after",
detail: "On battery. Requires your password to get back in"
},
{
key: "suspendMinutesBattery", type: "int", def: 20, min: 0, max: 480, step: 5,
unit: "min", group: "idleBattery",
label: "Suspend after",
detail: "On battery, sleeping is what makes the charge last"
},
// ── Night light schedule ────────────────────────────────────────────
// Hours as decimals, so 17.5 is half past five. Wrapping past midnight
// is normal here and is what the shipped values do: on at 17:00, off at