power
Power profiles, mains or battery, and battery power draw.
list {
direction = "horizontal",
items = mantle.power:map(function(power)
return power.profiles
end),
each = function(name)
return rect {
padding = 6,
background = mantle.power:map(function(power)
return power.active_profile == name and "#89B4FA" or "#313244"
end, "#313244"),
on_click = function() mantle.power:set_profile(name) end,
children = { text { content = name } },
}
end,
}
State
mantle.power:get() returns PowerState, nil before the first push. A field marked ? may be absent.
mantle.power’s payload. Profile fields are nil without power-profiles-daemon, the rest without UPower;
a failed read is also nil. With neither service the payload is an empty table.
| Field | Type | Description |
|---|---|---|
active_profile? | string | Active platform profile, e.g. "balanced". |
energy_rate? | number | UPower’s display-device EnergyRate in watts; direction is mantle.battery.state. |
on_battery? | boolean | UPower’s OnBattery: running on battery rather than mains. |
profiles? | string[] | Available profiles in daemon order, e.g. {"power-saver", "balanced", "performance"}. |
Actions
Call each as mantle.power:<action>(arguments...); ? marks an argument you may omit.
| Action | Arguments | Description |
|---|---|---|
set_profile | name: string | Switches to one of profiles; a name not in it, or one the daemon rejects, is logged and active_profile stays. |
Backend
| Half | Source | Missing |
|---|---|---|
active_profile, profiles | power-profiles-daemon: org.freedesktop.UPower.PowerProfiles, else net.hadess.PowerProfiles | Both fields absent; set_profile is logged and ignored |
on_battery, energy_rate | UPower’s OnBattery and its DisplayDevice’s EnergyRate | Both fields absent |
Every OnBattery, EnergyRate or ActiveProfile change re-reads all four fields, and so does
either daemon stopping or restarting: a stopped one’s fields are absent, a restarted one’s are read
fresh. With neither service the push is an empty table.
Gotchas
| Trap | Fix |
|---|---|
| power-profiles-daemon started after the capability never shows up | The daemon is looked up once, on the first read. Restart mantle after installing it |
energy_rate has no sign | It is a magnitude in watts. Read mantle.battery’s state for the direction |
See also: battery for charge and time estimates.