Skip to content

feat(power): configure the active power plan from power.setup - #45

Draft
blendonl wants to merge 1 commit into
mainfrom
feat/power-settings
Draft

blendonl wants to merge 1 commit into
mainfrom
feat/power-settings

Conversation

@blendonl

Copy link
Copy Markdown
Owner

What

mshell.power.setup{ screen_off = 10, sleep = 0, power_button = "sleep", lid_battery = "hibernate" }
mshell.exe --settings get power.screen_off power.lid
mshell.exe --settings set power.sleep_battery 15
  • screen_off, sleep, hibernate: minutes idle, 0 = never, 0–1440.
  • power_button, sleep_button: nothing | sleep | hibernate | shutdown | display_off.
  • lid: the same without display_off.
  • Every field has a _battery twin for the DC value.

Why not the Settings handlers

They offer these only as translated display labels ("15 minutes (Recommended)", "Do Nothing"), so a config would break on a non-English Windows. Power rows in the catalog instead carry the power subgroup and setting GUIDs, AC or DC, and a scale; src/settings_power.c reads and writes them on the active scheme with PowerRead/WriteAC/DCValueIndex and re-applies the scheme. Everything else — Lua validation, --settings, background apply on start and reload, failure notification — is the existing settings machinery.

Values belong to the active plan, so switching plans brings that plan's own values until the next reload writes them again.

Tested

  • make all with no warnings, make test, make test-asan, make meta (committed), README Lua blocks via check-config
  • settings_catalog suite (2173 assertions): power rows have braced GUIDs, numeric option indices, unique setting/AC-DC pairs; engine text and read-back words for timeouts and actions
  • Live on Windows 11, unelevated: all 12 fields read the same as powercfg /qh; screen_off 3 → 4 → 3 changed only the AC index (180 → 240 → 180 s); sleep_button_battery sleep → hibernate → sleep changed only the DC index; lid = display_off rejected; a 90 s plan value reads as 90 seconds and setting 3 writes 180
  • Config apply in the running shell (needs this build deployed) — see "Power plan settings" in MANUAL-TESTS.md

The Settings handlers only offer power timeouts and button actions as
translated display labels ("15 minutes (Recommended)"), which would break a
config on any non-English Windows. Power rows in the settings catalog instead
name a power setting by subgroup and setting GUID, AC or DC, and a scale, and
src/settings_power.c reads and writes them on the active scheme through
PowerRead/WriteAC/DCValueIndex, re-applying the scheme after a write.

power.setup takes screen_off, sleep and hibernate in minutes (0 never) and
power_button, sleep_button and lid actions, each with a _battery twin. The
same fields work from mshell.exe --settings and are applied in the background
on start and reload like the other Windows settings; a value that is not a
whole minute reads back in seconds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant