Add backlight control to the shell and regenerate WIT bindings
CI / test (push) Canceled after 0s

- Add compositor/shell/backlight.mbt for backlight control in the shell
- Update wit/capabilities.wit and wit/host/plasmoids.wit, then regenerate the component and interface ffi.mbt bindings (mostly export reordering)
- Add world/launcher-widget/README.md
This commit is contained in:
nandi committed 2026-11-28 02:16:07 -08:00
1 parent 2e00009c79
commit 74235cb0ca
84 files changed
+1525 -864

No files matched your search

+23
View File
@@ -151,6 +151,7 @@ pub(all) struct ChandraCompositor {
/// idle, and whether this idle spell already suspended.
mut last_input_ms : UInt64
mut screen_off : Bool
mut manual_screen_off : Bool
mut idle_suspended : Bool
mut output_w : Int
mut output_h : Int
@@ -384,6 +385,7 @@ pub fn ChandraCompositor::new(
login_session: false,
last_input_ms: @sys.monotonic_ms(),
screen_off: false,
manual_screen_off: false,
idle_suspended: false,
output_w,
output_h,
@@ -2071,6 +2073,27 @@ fn ChandraCompositor::handle_input_inner(
ev : @nested.InputEvent,
time_ms : UInt,
) -> Unit {
match ev {
Key(116U, pressed) => {
if pressed {
if self.screen_off || self.manual_screen_off {
self.manual_screen_off = false
self.note_activity(@sys.monotonic_ms())
} else {
self.manual_screen_off = true
}
}
return
}
_ => ()
}
if self.manual_screen_off {
return
}
if self.screen_off {
self.note_activity(@sys.monotonic_ms())
return
}
self.note_activity(@sys.monotonic_ms())
match ev {
Modifiers(dep, lat, lock, group) => {
+60
View File
@@ -214,6 +214,8 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin
"windows each window: frame, layout, box, shadow, size limits; and what is under the pointer",
"screenshot [PATH] save a full-screen PNG directly (without opening the editor)",
"rotate [cw|ccw|flip|0|90|180|270|status] rotate or flip the display",
"screen [on|off|toggle|status] blank or wake the display",
"brightness [PCT|status] read or set display backlight percent (5..100)",
"auth-demo [MODE] show the password dialog with a pretend check (password \"demo\"); MODE: " +
@polkit.demo_modes.join(", "),
"auth-status the password dialog's agent: running, registered, or why not",
@@ -398,6 +400,64 @@ pub fn ChandraCompositor::control_command(self : ChandraCompositor, line : Strin
_ => (["error usage: rotate [cw|ccw|flip|0|90|180|270|status]"], false)
}
}
"screen" => {
let arg = if words.length() >= 2 { words[1] } else { "status" }
if words.length() > 2 {
return (["error usage: screen [on|off|toggle|status]"], false)
}
match arg {
"status" => (["ok " + (if self.screen_off || self.manual_screen_off { "off" } else { "on" })], true)
"off" => {
self.set_manual_screen_off(true)
(["ok off"], true)
}
"on" => {
self.set_manual_screen_off(false)
(["ok on"], true)
}
"toggle" => {
let next_off = !(self.screen_off || self.manual_screen_off)
self.set_manual_screen_off(next_off)
(["ok " + (if next_off { "off" } else { "on" })], true)
}
_ => (["error usage: screen [on|off|toggle|status]"], false)
}
}
"brightness" => {
let arg = if words.length() >= 2 { words[1] } else { "status" }
if words.length() > 2 {
return (["error usage: brightness [PCT|status]"], false)
}
if arg == "status" {
let cur = @shell.read_backlight_percent()
if cur < 0 {
(["error no backlight"], false)
} else {
(["ok " + cur.to_string()], true)
}
} else {
let mut val = 0
let mut valid = arg.length() > 0
for ch in arg {
let c = ch.to_int()
if c >= 48 && c <= 57 {
val = val * 10 + (c - 48)
} else {
valid = false
break
}
}
if !valid {
return (["error usage: brightness [PCT|status]"], false)
}
let next = self.shell.set_brightness(val)
if next < 0 {
(["error no backlight"], false)
} else {
(["ok " + next.to_string()], true)
}
}
}
other => (["error unknown command '" + other + "' (try: help)"], false)
}
}
+59 -1
View File
@@ -1739,7 +1739,7 @@ test "the settings module's Power tab steps the timeouts and confirms power off"
// Rows of 28 below the tab bar (40): [Battery heading, battery,] When idle, screen off,
// suspend, Now, Suspend, Restart, Power off.
let n = (pr.h - 40 - 6) / 28
assert_true(n == 7 || n == 9)
assert_true(n == 7 || n == 9 || n == 11)
let first = n - 7
let row_y = fn(i : Int) { pr.y + 40 + (first + i) * 28 + 13 }
assert_eq(comp.shell.screen_off_min, 10)
@@ -1775,3 +1775,61 @@ test "power timeouts are saved to state.edn and restored" {
assert_false(read_state_edn().contains(":power"))
}
}
///|
test "power key toggles manual screen off and wakes without leaking touches" {
let comp = new_comp("powerbtn")
comp.note_activity(1000UL)
assert_eq(comp.power_tick(1000UL), NoChange)
// Pressing KEY_POWER (116) turns screen off; releasing it leaves it off.
comp.handle_input(@nested.InputEvent::Key(116U, true), 10U)
comp.handle_input(@nested.InputEvent::Key(116U, false), 20U)
assert_eq(comp.power_tick(1050UL), ScreenOff)
assert_eq(comp.power_tick(1060UL), NoChange)
// Stray touch/pointer activity while manually blanked does not wake the screen.
comp.handle_input(@nested.InputEvent::PointerMove(50.0, 50.0), 30U)
assert_eq(comp.power_tick(1100UL), NoChange)
// Second KEY_POWER press wakes the screen and keeps it awake after release.
comp.handle_input(@nested.InputEvent::Key(116U, true), 40U)
comp.handle_input(@nested.InputEvent::Key(116U, false), 50U)
assert_eq(comp.power_tick(1200UL), ScreenOn)
assert_eq(comp.power_tick(1300UL), NoChange)
// Control socket screen commands work symmetrically.
let (r1, ok1) = comp.control_command("screen off")
assert_true(ok1 && r1 == ["ok off"])
assert_eq(comp.power_tick(1400UL), ScreenOff)
let (r2, ok2) = comp.control_command("screen on")
assert_true(ok2 && r2 == ["ok on"])
assert_eq(comp.power_tick(1500UL), ScreenOn)
}
///|
test "settings Power tab displays and adjusts backlight brightness" {
let root = "/tmp/chandra-test-backlight"
let dev = root + "/ae94000.dsi.0"
ignore(@sys.mkdir_p(dev))
assert_eq(@sys.write_file_bytes(dev + "/max_brightness", @utf8.encode("1000\n")), 0)
assert_eq(@sys.write_file_bytes(dev + "/brightness", @utf8.encode("500\n")), 0)
@shell.set_backlight_root(root)
let comp = new_comp("brightness")
comp.shell.refresh_brightness()
let slot = comp.shell.slot_of("session-settings")
assert_true(comp.shell.open_settings(Power))
ignore(comp.compose_frame())
let texts = comp.shell.slot_popup_texts(slot).map(t => t.0)
assert_true(texts.contains("Brightness"))
assert_true(texts.contains("50%"))
let pr = comp.shell.slot_popup_rect(slot)
let (_, br) = comp.control_command("brightness 80")
assert_true(br)
ignore(comp.compose_frame())
assert_true(comp.shell.slot_popup_texts(slot).map(t => t.0).contains("80%"))
assert_eq(@shell.read_backlight_percent(), 80)
// Clicking the '-' button (x inside [margin..47]) steps 80 -> 70%.
let n = (pr.h - 40 - 6) / 28
let bright_row = n - 8
assert_true(bright_row >= 1)
click_at(comp, pr.x + 25, pr.y + 40 + bright_row * 28 + 13, 10U)
assert_eq(@shell.read_backlight_percent(), 70)
@shell.set_backlight_root("/sys/class/backlight")
}
+19 -1
View File
@@ -21,8 +21,26 @@ pub fn ChandraCompositor::note_activity(self : ChandraCompositor, now_ms : UInt6
self.last_input_ms = now_ms
}
///| Check the idle timeouts at monotonic time `now_ms`.
///| Turn the screen off or back on from a manual action (power button or `chandra-ctl screen`).
pub fn ChandraCompositor::set_manual_screen_off(
self : ChandraCompositor,
off : Bool,
) -> Unit {
self.manual_screen_off = off
if !off {
self.note_activity(@sys.monotonic_ms())
}
}
///| Check the idle timeouts and manual screen blank state at monotonic time `now_ms`.
pub fn ChandraCompositor::power_tick(self : ChandraCompositor, now_ms : UInt64) -> PowerChange {
if self.manual_screen_off {
if !self.screen_off {
self.screen_off = true
return ScreenOff
}
return NoChange
}
let idle = if now_ms > self.last_input_ms { now_ms - self.last_input_ms } else { 0UL }
let minutes = fn(m : Int) { m.to_uint64() * 60000UL }
let off = self.shell.screen_off_min