power
Power profiles, mains or battery, and battery power draw.
list {
direction = "Horizontal",
source = mantle.power:map(function(power)
return power and power.profiles or {}
end),
itemfn = function(name)
return button {
padding = 6,
background = mantle.power:map(function(power)
return (power and power.active_profile == name) and "#89B4FA" or "#313244"
end),
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. Not validated here; a rejected name 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. 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.