Battery panel module: charge, charging state, time left, low-battery warning
CI / test (push) Failing after 18s
CI / test (push) Failing after 18s
- New `battery` panel module (components/battery, logic in lib/battery): a battery icon filled to
the charge with the percentage and time remaining ("73% 2:05"; time to full while charging).
The fill turns green when charging or full, amber at 20 % and below, and at 10 % the whole
button turns red and a "Battery low" popup opens by itself, once per discharge spell. A click
opens the details (charge, state, time left in words). Without a battery it shows a plug.
- Right-click "Module settings": Show percentage, Show time remaining, and Without a battery
(Show a plug / Show nothing). Saved per module in state.edn like the clocks' settings.
- New `battery` capability (wit/capabilities.wit: read -> status {percent, charge-state,
secs-left}). Served by the wasmer stub (host ints 7-9), host-wasm and wasmhost (publish-battery).
- Host side (compositor/shell/battery.mbt): reads /sys/class/power_supply, every battery
together (energy_* / power_now, or charge_* / current_now; capacity when that is all there
is; device-scope batteries like mice are skipped). The `system` snapshot the Power tab uses
now reads the battery through the same code. Time left follows a running average of the
rate, starting over when the state changes.
- A fresh panel gets the battery module before the clock only on a machine with a battery.
- wasm_stub: MAX_INST 512 -> 2048. The host test binary creates ~70 compositors without
unloading their modules; at 512 the last tests' panels came up half empty.
- Tests: sysfs reading against a fake power supply (energy and charge units, two packs,
charging, full, capacity only, no battery), the running average, the module in the panel
(text, settings, click, the critical warning, the plug), the rendering logic, and a
host-wasm test of the module.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hky51dmaUqiYW746Gz
This commit is contained in:
48 files changed
+2143
-17
No files matched your search
@@ -0,0 +1,364 @@
|
||||
///| Render logic for the battery panel module (pure: tokens + a reading in, ops out).
|
||||
///
|
||||
/// The module (components/battery) only adapts the `battery` capability to `Reading` and keeps
|
||||
/// one `BatteryConfig` and one `LowWarning`; everything it draws is decided here.
|
||||
|
||||
///| What the host reported: the `battery` capability's `status`, with the charge state as its
|
||||
/// index (STATE_*).
|
||||
#derive(Eq, Debug)
|
||||
pub(all) struct Reading {
|
||||
/// 0..100, or -1 without a battery.
|
||||
percent : Int
|
||||
state : Int
|
||||
/// Estimated seconds until empty (discharging) or full (charging); 0 unknown.
|
||||
secs_left : Int
|
||||
}
|
||||
|
||||
///| Charge states, in the order of the `charge-state` enum.
|
||||
pub let state_none : Int = 0
|
||||
|
||||
///|
|
||||
pub let state_discharging : Int = 1
|
||||
|
||||
///|
|
||||
pub let state_charging : Int = 2
|
||||
|
||||
///|
|
||||
pub let state_full : Int = 3
|
||||
|
||||
///|
|
||||
pub let state_not_charging : Int = 4
|
||||
|
||||
///| Below this (discharging) the icon turns amber.
|
||||
pub let low_percent : Int = 20
|
||||
|
||||
///| At or below this (discharging) the module turns red and opens its low-battery warning.
|
||||
pub let critical_percent : Int = 10
|
||||
|
||||
///|
|
||||
pub fn info() -> (String, String, Int, Int, Int) {
|
||||
// id, name, preferred w, preferred h, min w
|
||||
("org.chandra.battery", "Battery", 104, 34, 34)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Reading::has_battery(self : Reading) -> Bool {
|
||||
self.percent >= 0 && self.state != state_none
|
||||
}
|
||||
|
||||
///| 0 normal, 1 low, 2 critical. Only a discharging battery is ever low.
|
||||
pub fn Reading::level(self : Reading) -> Int {
|
||||
if !self.has_battery() || self.state != state_discharging {
|
||||
0
|
||||
} else if self.percent <= critical_percent {
|
||||
2
|
||||
} else if self.percent <= low_percent {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
///| "2:05" (hours:minutes), rounded down to the minute; "" when unknown.
|
||||
pub fn short_time(secs : Int) -> String {
|
||||
if secs <= 0 {
|
||||
return ""
|
||||
}
|
||||
let m = secs / 60
|
||||
let mm = m % 60
|
||||
(m / 60).to_string() + ":" + (if mm < 10 { "0" } else { "" }) + mm.to_string()
|
||||
}
|
||||
|
||||
///| "2 h 05 min" / "35 min"; "" when unknown.
|
||||
pub fn long_time(secs : Int) -> String {
|
||||
if secs <= 0 {
|
||||
return ""
|
||||
}
|
||||
let m = secs / 60
|
||||
if m < 60 {
|
||||
return m.to_string() + " min"
|
||||
}
|
||||
let mm = m % 60
|
||||
(m / 60).to_string() + " h " + (if mm < 10 { "0" } else { "" }) + mm.to_string() + " min"
|
||||
}
|
||||
|
||||
///| One line describing the state: "Discharging, 2 h 05 min left".
|
||||
pub fn Reading::describe(self : Reading) -> String {
|
||||
if !self.has_battery() {
|
||||
return "No battery: on mains power"
|
||||
}
|
||||
let t = long_time(self.secs_left)
|
||||
match self.state {
|
||||
1 => if t == "" { "Discharging" } else { "Discharging, " + t + " left" }
|
||||
2 => if t == "" { "Charging" } else { "Charging, full in " + t }
|
||||
3 => "Fully charged, plugged in"
|
||||
4 => "Plugged in, not charging"
|
||||
_ => ""
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- settings
|
||||
|
||||
///| One item of the right-click "Module settings" menu (the `module-config` record).
|
||||
#derive(Eq, Debug)
|
||||
pub(all) struct ConfigEntry {
|
||||
key : String
|
||||
label : String
|
||||
choices : Array[String]
|
||||
value : String
|
||||
}
|
||||
|
||||
///| What the user picked for the module.
|
||||
pub(all) struct BatteryConfig {
|
||||
mut show_percent : Bool
|
||||
mut show_time : Bool
|
||||
/// Without a battery: draw a plug (true) or nothing.
|
||||
mut plug_without_battery : Bool
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn BatteryConfig::new() -> BatteryConfig {
|
||||
{ show_percent: true, show_time: true, plug_without_battery: true }
|
||||
}
|
||||
|
||||
///|
|
||||
fn on_off(b : Bool) -> String {
|
||||
if b { "on" } else { "off" }
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn BatteryConfig::items(self : BatteryConfig) -> Array[ConfigEntry] {
|
||||
[
|
||||
{ key: "percent", label: "Show percentage", choices: [], value: on_off(self.show_percent) },
|
||||
{ key: "time", label: "Show time remaining", choices: [], value: on_off(self.show_time) },
|
||||
{
|
||||
key: "no-battery",
|
||||
label: "Without a battery",
|
||||
choices: ["Show a plug", "Show nothing"],
|
||||
value: if self.plug_without_battery { "Show a plug" } else { "Show nothing" },
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
///| Apply one setting; true when it changed something. Unknown keys and values are ignored.
|
||||
pub fn BatteryConfig::set(self : BatteryConfig, key : String, value : String) -> Bool {
|
||||
let flag = fn(cur : Bool, set : (Bool) -> Unit) -> Bool {
|
||||
match value {
|
||||
"on" if !cur => { set(true); true }
|
||||
"off" if cur => { set(false); true }
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
match key {
|
||||
"percent" => flag(self.show_percent, fn(b) { self.show_percent = b })
|
||||
"time" => flag(self.show_time, fn(b) { self.show_time = b })
|
||||
"no-battery" =>
|
||||
match value {
|
||||
"Show a plug" if !self.plug_without_battery => { self.plug_without_battery = true; true }
|
||||
"Show nothing" if self.plug_without_battery => { self.plug_without_battery = false; true }
|
||||
_ => false
|
||||
}
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
///| The module's settings (one module instance per wasm instance).
|
||||
pub let config : BatteryConfig = BatteryConfig::new()
|
||||
|
||||
// ---------------------------------------------------------------- low-battery warning
|
||||
|
||||
///| Opens the warning once per discharge spell when the charge reaches `critical_percent`; it
|
||||
/// arms again after the machine is plugged in (or charges above it).
|
||||
pub(all) struct LowWarning {
|
||||
mut fired : Bool
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn LowWarning::new() -> LowWarning {
|
||||
{ fired: false }
|
||||
}
|
||||
|
||||
///| Feed a reading; true when the warning should open now.
|
||||
pub fn LowWarning::update(self : LowWarning, r : Reading) -> Bool {
|
||||
if r.level() == 2 {
|
||||
if self.fired {
|
||||
false
|
||||
} else {
|
||||
self.fired = true
|
||||
true
|
||||
}
|
||||
} else {
|
||||
self.fired = false
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- drawing
|
||||
|
||||
///|
|
||||
let red : @types.Color = @ui.color(235, 64, 52, 255)
|
||||
|
||||
///|
|
||||
let amber : @types.Color = @ui.color(240, 165, 30, 255)
|
||||
|
||||
///|
|
||||
let green : @types.Color = @ui.color(70, 185, 90, 255)
|
||||
|
||||
///| Icon width (body plus the terminal nub).
|
||||
let icon_w : Int = 24
|
||||
|
||||
///| A horizontal battery at (x, cy): outline, nub, fill for the charge, and a bolt when charging.
|
||||
fn battery_icon(x : Int, cy : Int, r : Reading, fg : @types.Color, fill : @types.Color) -> Array[@types.DrawOp] {
|
||||
let bw = 21
|
||||
let bh = 12
|
||||
let y = cy - bh / 2
|
||||
let ops = [
|
||||
@ui.stroke_rect(@ui.rect(x, y, bw, bh), fg, width=1, radius=2),
|
||||
@ui.fill_rect(@ui.rect(x + bw, cy - 3, 3, 6), fg, radius=1),
|
||||
]
|
||||
let inner = bw - 4
|
||||
let pct = if r.percent < 0 { 0 } else if r.percent > 100 { 100 } else { r.percent }
|
||||
let fw = if pct == 0 { 0 } else if inner * pct / 100 < 1 { 1 } else { inner * pct / 100 }
|
||||
if fw > 0 {
|
||||
ops.push(@ui.fill_rect(@ui.rect(x + 2, y + 2, fw, bh - 4), fill, radius=1))
|
||||
}
|
||||
if r.state == state_charging {
|
||||
// A bolt over the middle, outlined in the panel colour so it shows on the fill.
|
||||
let mx = x + bw / 2
|
||||
ops.push(@ui.line(mx + 2, y - 1, mx - 3, cy + 1, fg, width=2))
|
||||
ops.push(@ui.line(mx - 3, cy + 1, mx + 3, cy - 1, fg, width=2))
|
||||
ops.push(@ui.line(mx + 3, cy - 1, mx - 2, y + bh + 1, fg, width=2))
|
||||
}
|
||||
ops
|
||||
}
|
||||
|
||||
///| A mains plug at (x, cy): two prongs, the head, and the cable.
|
||||
fn plug_icon(x : Int, cy : Int, fg : @types.Color) -> Array[@types.DrawOp] {
|
||||
[
|
||||
@ui.line(x + 6, cy - 8, x + 6, cy - 4, fg, width=2),
|
||||
@ui.line(x + 12, cy - 8, x + 12, cy - 4, fg, width=2),
|
||||
@ui.fill_rect(@ui.rect(x + 3, cy - 4, 13, 7), fg, radius=2),
|
||||
@ui.line(x + 9, cy + 3, x + 9, cy + 8, fg, width=2),
|
||||
]
|
||||
}
|
||||
|
||||
///| The text after the icon: "73%", "73% 2:05", "2:05" or "".
|
||||
pub fn panel_text(r : Reading, c : BatteryConfig) -> String {
|
||||
if !r.has_battery() {
|
||||
return ""
|
||||
}
|
||||
let parts : Array[String] = []
|
||||
if c.show_percent {
|
||||
parts.push(r.percent.to_string() + "%")
|
||||
}
|
||||
if c.show_time && (r.state == state_discharging || r.state == state_charging) {
|
||||
let t = short_time(r.secs_left)
|
||||
if t != "" {
|
||||
parts.push(t)
|
||||
}
|
||||
}
|
||||
parts.join(" ")
|
||||
}
|
||||
|
||||
///| The panel button. Critical: a red chip with white content; open popup: the accent chip.
|
||||
pub fn render(
|
||||
size : @types.Size,
|
||||
t : @theme.Tokens,
|
||||
r : Reading,
|
||||
c : BatteryConfig,
|
||||
open? : Bool = false,
|
||||
) -> Array[@types.DrawOp] {
|
||||
let w = size.w.reinterpret_as_int()
|
||||
let h = size.h.reinterpret_as_int()
|
||||
let fs = t.font_size.reinterpret_as_int() - 2
|
||||
let radius = t.radius.reinterpret_as_int()
|
||||
let p = t.palette
|
||||
let ops : Array[@types.DrawOp] = []
|
||||
if !r.has_battery() && !c.plug_without_battery {
|
||||
return ops
|
||||
}
|
||||
let level = r.level()
|
||||
let fg = if level == 2 {
|
||||
@ui.color(255, 255, 255, 255)
|
||||
} else if open {
|
||||
p.accent_foreground
|
||||
} else {
|
||||
p.foreground
|
||||
}
|
||||
if level == 2 {
|
||||
ops.push(@ui.fill_rect(@ui.rect(0, 0, w, h), red, radius~))
|
||||
} else if open {
|
||||
ops.push(@ui.fill_rect(@ui.rect(0, 0, w, h), p.accent, radius~))
|
||||
}
|
||||
let cy = h / 2
|
||||
if !r.has_battery() {
|
||||
ops.append(plug_icon(w / 2 - 9, cy, fg))
|
||||
return ops
|
||||
}
|
||||
let fill = if level == 2 {
|
||||
fg
|
||||
} else if level == 1 {
|
||||
amber
|
||||
} else if r.state == state_charging || r.state == state_full {
|
||||
green
|
||||
} else {
|
||||
fg
|
||||
}
|
||||
// Text only when it fits; the icon and text are centred together.
|
||||
let txt = panel_text(r, c)
|
||||
let tw = if txt == "" { 0 } else { @ui.text_width(txt, fs) }
|
||||
let show_txt = tw > 0 && icon_w + 6 + tw + 8 <= w
|
||||
let total = if show_txt { icon_w + 6 + tw } else { icon_w }
|
||||
let x0 = (w - total) / 2
|
||||
ops.append(battery_icon(x0, cy, r, fg, fill))
|
||||
if show_txt {
|
||||
ops.push(@ui.text(x0 + icon_w + 6, cy, txt, fs, fg))
|
||||
}
|
||||
ops
|
||||
}
|
||||
|
||||
///| Popup width; rows are `popup_row_h` tall.
|
||||
pub let popup_w : Int = 260
|
||||
|
||||
///|
|
||||
let popup_row_h : Int = 24
|
||||
|
||||
///| The details popup (a click on the module, or the low-battery warning): the charge in large
|
||||
/// type, the state with time left, and on a critical battery a line asking to plug in.
|
||||
pub fn render_popup(t : @theme.Tokens, r : Reading, warning? : Bool = false) -> (Int, Int, Array[@types.DrawOp]) {
|
||||
let fs = t.font_size.reinterpret_as_int()
|
||||
let radius = t.radius.reinterpret_as_int()
|
||||
let p = t.palette
|
||||
let lines : Array[(String, Int, @types.Color, Bool)] = [] // text, size, colour, bold
|
||||
if !r.has_battery() {
|
||||
lines.push(("Power", fs, p.foreground, true))
|
||||
lines.push((r.describe(), fs - 2, p.foreground_muted, false))
|
||||
} else {
|
||||
let critical = r.level() == 2
|
||||
let head = if warning && critical { "Battery low: " } else { "Battery " }
|
||||
lines.push(
|
||||
(
|
||||
head + r.percent.to_string() + "%",
|
||||
fs + 2,
|
||||
if critical { red } else { p.foreground },
|
||||
true,
|
||||
),
|
||||
)
|
||||
lines.push((r.describe(), fs - 2, p.foreground_muted, false))
|
||||
if critical {
|
||||
lines.push(("Plug in the computer to keep working.", fs - 2, p.foreground, false))
|
||||
}
|
||||
}
|
||||
let m = 10
|
||||
let h = m * 2 + lines.length() * popup_row_h
|
||||
let w = popup_w
|
||||
let ops = [
|
||||
@ui.fill_rect(@ui.rect(0, 0, w, h), p.surface_popup, radius~),
|
||||
@ui.stroke_rect(@ui.rect(0, 0, w, h), if warning { red } else { p.border }, width=1, radius~),
|
||||
]
|
||||
for i, l in lines {
|
||||
let (s, size, col, bold) = l
|
||||
ops.push(@ui.text(m + 4, m + i * popup_row_h + popup_row_h / 2, s, size, col, bold~))
|
||||
}
|
||||
(w, h, ops)
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
///|
|
||||
fn test_tokens() -> @theme.Tokens {
|
||||
let c = @ui.color(10, 20, 30, 255)
|
||||
{
|
||||
name: "t",
|
||||
palette: {
|
||||
desktop_top: c,
|
||||
desktop_bottom: c,
|
||||
surface: c,
|
||||
surface_hover: c,
|
||||
surface_popup: c,
|
||||
foreground: c,
|
||||
foreground_muted: c,
|
||||
accent: c,
|
||||
accent_foreground: c,
|
||||
border: c,
|
||||
},
|
||||
font_size: 14,
|
||||
radius: 6,
|
||||
spacing: 6,
|
||||
panel_height: 44,
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn texts(ops : Array[@types.DrawOp]) -> Array[String] {
|
||||
let out : Array[String] = []
|
||||
for op in ops {
|
||||
if op is Text(t) {
|
||||
out.push(t.text)
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
///|
|
||||
fn has_red(ops : Array[@types.DrawOp]) -> Bool {
|
||||
ops.iter().any(op => op is FillRect(f) && f.color.r == b'\xEB' && f.color.g == b'\x40')
|
||||
}
|
||||
|
||||
///|
|
||||
let size : @types.Size = { w: 104, h: 34 }
|
||||
|
||||
///|
|
||||
test "time formats" {
|
||||
assert_eq(short_time(0), "")
|
||||
assert_eq(short_time(59), "0:00")
|
||||
assert_eq(short_time(7500), "2:05")
|
||||
assert_eq(long_time(35 * 60 + 20), "35 min")
|
||||
assert_eq(long_time(7500), "2 h 05 min")
|
||||
assert_eq(long_time(-1), "")
|
||||
}
|
||||
|
||||
///|
|
||||
test "panel shows percent and time, each switchable" {
|
||||
let c = BatteryConfig::new()
|
||||
let r = { percent: 73, state: state_discharging, secs_left: 7500 }
|
||||
assert_eq(texts(render(size, test_tokens(), r, c)), ["73% 2:05"])
|
||||
assert_true(c.set("time", "off"))
|
||||
assert_false(c.set("time", "off"))
|
||||
assert_eq(texts(render(size, test_tokens(), r, c)), ["73%"])
|
||||
assert_true(c.set("percent", "off"))
|
||||
assert_eq(texts(render(size, test_tokens(), r, c)), [])
|
||||
assert_true(c.set("time", "on"))
|
||||
assert_eq(texts(render(size, test_tokens(), r, c)), ["2:05"])
|
||||
assert_eq(c.items().map(i => i.value), ["off", "on", "Show a plug"])
|
||||
assert_false(c.set("bogus", "on"))
|
||||
// Too narrow for text: icon only.
|
||||
c.show_percent = true
|
||||
assert_eq(texts(render({ w: 34, h: 34 }, test_tokens(), r, c)), [])
|
||||
}
|
||||
|
||||
///|
|
||||
test "charging shows time to full; full and unknown times show percent only" {
|
||||
let c = BatteryConfig::new()
|
||||
let charging = { percent: 40, state: state_charging, secs_left: 3600 }
|
||||
assert_eq(texts(render(size, test_tokens(), charging, c)), ["40% 1:00"])
|
||||
assert_eq(charging.describe(), "Charging, full in 1 h 00 min")
|
||||
let full = { percent: 100, state: state_full, secs_left: 0 }
|
||||
assert_eq(texts(render(size, test_tokens(), full, c)), ["100%"])
|
||||
assert_eq(full.describe(), "Fully charged, plugged in")
|
||||
let unknown = { percent: 55, state: state_discharging, secs_left: 0 }
|
||||
assert_eq(texts(render(size, test_tokens(), unknown, c)), ["55%"])
|
||||
assert_eq(unknown.describe(), "Discharging")
|
||||
assert_eq({ percent: 80, state: state_not_charging, secs_left: 0 }.describe(), "Plugged in, not charging")
|
||||
}
|
||||
|
||||
///|
|
||||
test "low and critical levels; charging is never low" {
|
||||
assert_eq({ percent: 21, state: state_discharging, secs_left: 0 }.level(), 0)
|
||||
assert_eq({ percent: 20, state: state_discharging, secs_left: 0 }.level(), 1)
|
||||
assert_eq({ percent: 10, state: state_discharging, secs_left: 0 }.level(), 2)
|
||||
assert_eq({ percent: 5, state: state_charging, secs_left: 0 }.level(), 0)
|
||||
let c = BatteryConfig::new()
|
||||
let crit = { percent: 8, state: state_discharging, secs_left: 600 }
|
||||
assert_true(has_red(render(size, test_tokens(), crit, c)))
|
||||
assert_false(has_red(render(size, test_tokens(), { ..crit, percent: 50 }, c)))
|
||||
let (_, _, ops) = render_popup(test_tokens(), crit, warning=true)
|
||||
assert_eq(texts(ops), ["Battery low: 8%", "Discharging, 10 min left", "Plug in the computer to keep working."])
|
||||
}
|
||||
|
||||
///|
|
||||
test "the low-battery warning opens once per discharge spell" {
|
||||
let lw = LowWarning::new()
|
||||
let r = { percent: 11, state: state_discharging, secs_left: 0 }
|
||||
assert_false(lw.update(r))
|
||||
assert_true(lw.update({ ..r, percent: 10 }))
|
||||
assert_false(lw.update({ ..r, percent: 9 }))
|
||||
assert_false(lw.update({ ..r, percent: 9, state: state_charging }))
|
||||
assert_true(lw.update({ ..r, percent: 9 }))
|
||||
}
|
||||
|
||||
///|
|
||||
test "without a battery: a plug, or nothing" {
|
||||
let c = BatteryConfig::new()
|
||||
let none = { percent: -1, state: state_none, secs_left: 0 }
|
||||
let ops = render(size, test_tokens(), none, c)
|
||||
assert_true(ops.length() > 0)
|
||||
assert_eq(texts(ops), [])
|
||||
assert_true(c.set("no-battery", "Show nothing"))
|
||||
assert_eq(render(size, test_tokens(), none, c).length(), 0)
|
||||
assert_eq(none.describe(), "No battery: on mains power")
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import {
|
||||
"chandra/desktop/interface/chandra/desktop/types" @types,
|
||||
"chandra/desktop/interface/chandra/desktop/theme" @theme,
|
||||
"chandra/desktop/lib/ui" @ui,
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// Generated using `moon info`, DON'T EDIT IT
|
||||
package "chandra/desktop/lib/battery"
|
||||
|
||||
import {
|
||||
"chandra/desktop/interface/chandra/desktop/theme",
|
||||
"chandra/desktop/interface/chandra/desktop/types",
|
||||
"moonbitlang/core/debug",
|
||||
}
|
||||
|
||||
// Values
|
||||
pub let config : BatteryConfig
|
||||
|
||||
pub let critical_percent : Int32
|
||||
|
||||
pub fn info() -> (String, String, Int32, Int32, Int32)
|
||||
|
||||
pub fn long_time(Int32) -> String
|
||||
|
||||
pub let low_percent : Int32
|
||||
|
||||
pub fn panel_text(Reading, BatteryConfig) -> String
|
||||
|
||||
pub let popup_w : Int32
|
||||
|
||||
pub fn render(@types.Size, @theme.Tokens, Reading, BatteryConfig, open? : Bool) -> Array[@types.DrawOp]
|
||||
|
||||
pub fn render_popup(@theme.Tokens, Reading, warning? : Bool) -> (Int32, Int32, Array[@types.DrawOp])
|
||||
|
||||
pub fn short_time(Int32) -> String
|
||||
|
||||
pub let state_charging : Int32
|
||||
|
||||
pub let state_discharging : Int32
|
||||
|
||||
pub let state_full : Int32
|
||||
|
||||
pub let state_none : Int32
|
||||
|
||||
pub let state_not_charging : Int32
|
||||
|
||||
// Errors
|
||||
|
||||
// Types and methods
|
||||
pub(all) struct BatteryConfig {
|
||||
mut show_percent : Bool
|
||||
mut show_time : Bool
|
||||
mut plug_without_battery : Bool
|
||||
}
|
||||
pub fn BatteryConfig::items(Self) -> Array[ConfigEntry]
|
||||
pub fn BatteryConfig::new() -> Self
|
||||
pub fn BatteryConfig::set(Self, String, String) -> Bool
|
||||
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) struct ConfigEntry {
|
||||
key : String
|
||||
label : String
|
||||
choices : Array[String]
|
||||
value : String
|
||||
}
|
||||
|
||||
pub(all) struct LowWarning {
|
||||
mut fired : Bool
|
||||
}
|
||||
pub fn LowWarning::new() -> Self
|
||||
pub fn LowWarning::update(Self, Reading) -> Bool
|
||||
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) struct Reading {
|
||||
percent : Int32
|
||||
state : Int32
|
||||
secs_left : Int32
|
||||
}
|
||||
pub fn Reading::describe(Self) -> String
|
||||
pub fn Reading::has_battery(Self) -> Bool
|
||||
pub fn Reading::level(Self) -> Int32
|
||||
|
||||
// Type aliases
|
||||
|
||||
// Traits
|
||||
Reference in new issue
Block a user