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

@@ -390,18 +390,25 @@ pub fn wasmExportOnEvent(p0 : Int, p1 : Int, p2 : Int, p3 : Int) -> Int {
}
///|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
///|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array16
#| local.get 0)
///|
#owned(str)
extern "wasm" fn mbt_ffi_str2ptr(str : String) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_store32(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store)
///|
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
@@ -412,15 +419,8 @@ extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_ptr2str(ptr : Int, len : Int) -> String =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array16
#| local.get 0)
extern "wasm" fn mbt_ffi_store8(offset : Int, value : Int) =
#|(func (param i32) (param i32) local.get 0 local.get 1 i32.store8)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
@@ -81,6 +81,8 @@ enum Row {
Browse
/// A line of text (the battery).
Info(String)
/// Display backlight slider (`power.brightness` / `power.set-brightness`).
Brightness
/// A timeout that steps through `choices`: 0 screen off, 1 suspend.
Timeout(Int, String)
/// Suspend (0), power off (1) or restart (2) now.
@@ -232,6 +234,10 @@ fn rows() -> Array[Row] {
let state = if snap.charging { " (charging)" } else { "" }
rs.push(Info(snap.battery_percent.to_string() + "%" + state))
}
if @power.brightness() >= 0 {
rs.push(Heading("Brightness"))
rs.push(Brightness)
}
rs.push(Heading("When idle"))
rs.push(Timeout(0, "Turn screen off after"))
rs.push(Timeout(1, "Suspend after"))
@@ -485,6 +491,19 @@ fn on_reset(sc : @shortcuts.Shortcut, x : Int) -> Bool {
sc.binding != sc.default_binding && !sc.capturing && x >= popup_w - margin - reset_w
}
let bright_btn_w : Int = 26
///|
let bright_bar_x : Int = margin + 8 + bright_btn_w + 8
///|
let bright_bar_w : Int = popup_w - margin - 44 - 8 - bright_btn_w - 8 - bright_bar_x
///|
fn clamp_brightness(v : Int) -> Int {
if v < 5 { 5 } else if v > 100 { 100 } else { v }
}
///| Act on row `i`: flip a setting, show a wallpaper, load a module, or browse. A panel-list row
/// acts only through button `btn` (0 move up, 1 move down, 2 remove).
fn act(rs : Array[Row], i : Int, btn~ : Int = -1, x~ : Int = 0) -> Unit {
@@ -494,6 +513,24 @@ fn act(rs : Array[Row], i : Int, btn~ : Int = -1, x~ : Int = 0) -> Unit {
let was_armed = armed.val
armed.val = -1
match rs[i] {
Brightness => {
let cur = @power.brightness()
if cur < 0 {
return
}
let next = if x > 0 && x < bright_bar_x {
clamp_brightness(cur - 10)
} else if x >= bright_bar_x + bright_bar_w + 4 {
clamp_brightness(cur + 10)
} else if x >= bright_bar_x && x <= bright_bar_x + bright_bar_w {
clamp_brightness(((x - bright_bar_x) * 100 + bright_bar_w / 2) / bright_bar_w)
} else if cur >= 100 {
10
} else {
clamp_brightness(cur + 10)
}
@power.set_brightness(next.reinterpret_as_uint())
}
Timeout(0, _) => @power.set_screen_off_minutes(next_choice(screen_off_choices, @power.screen_off_minutes().reinterpret_as_int()).reinterpret_as_uint())
Timeout(_, _) => @power.set_suspend_minutes(next_choice(suspend_choices, @power.suspend_minutes().reinterpret_as_int()).reinterpret_as_uint())
PowerNow(0, _) => @power.suspend()
@@ -659,7 +696,7 @@ pub fn popup() -> PopupSurface? {
match rs[i] {
Heading(_) | Category(_) | NothingToAdd | Browse => ()
// Rows with their own buttons get the soft fill, so the buttons stand out.
Setting(_, _) | FaceUse | Loaded(_, _, _, _) | Available(_, _, _, _) =>
Setting(_, _) | FaceUse | Brightness | Loaded(_, _, _, _) | Available(_, _, _, _) =>
if hot {
ops.push(@ui.fill_rect(@ui.rect(margin, y, w - 2 * margin, rh - 2), p.surface_hover, radius=r))
}
@@ -798,6 +835,32 @@ pub fn popup() -> PopupSurface? {
} else {
ops.push(@ui.text(margin + 10, mid, text, fs - 1, p.foreground))
}
Brightness => {
let cur = @power.brightness()
let pct = if cur < 0 { 0 } else if cur > 100 { 100 } else { cur }
let bx0 = margin + 8
let bh = 22
let by = mid - bh / 2
let bx1 = bright_bar_x + bright_bar_w + 8
let bbg = if hot { p.surface_popup } else { p.surface_hover }
ops.push(@ui.fill_rect(@ui.rect(bx0, by, bright_btn_w, bh), bbg, radius=r))
ops.push(@ui.stroke_rect(@ui.rect(bx0, by, bright_btn_w, bh), p.border, width=1, radius=r))
ops.push(@ui.text(bx0 + bright_btn_w / 2, mid, "-", fs, p.foreground, align=CENTER, bold=true))
let track_h = 8
let track_y = mid - track_h / 2
ops.push(@ui.fill_rect(@ui.rect(bright_bar_x, track_y, bright_bar_w, track_h), p.border, radius=track_h / 2))
let fill_w = bright_bar_w * pct / 100
if fill_w > 0 {
ops.push(@ui.fill_rect(@ui.rect(bright_bar_x, track_y, fill_w, track_h), p.accent, radius=track_h / 2))
}
let thumb_x = bright_bar_x + fill_w
ops.push(@ui.circle(thumb_x, mid, 6, p.accent))
ops.push(@ui.circle(thumb_x, mid, 4, p.accent_foreground))
ops.push(@ui.fill_rect(@ui.rect(bx1, by, bright_btn_w, bh), bbg, radius=r))
ops.push(@ui.stroke_rect(@ui.rect(bx1, by, bright_btn_w, bh), p.border, width=1, radius=r))
ops.push(@ui.text(bx1 + bright_btn_w / 2, mid, "+", fs, p.foreground, align=CENTER, bold=true))
ops.push(@ui.text(w - margin - 8, mid, pct.to_string() + "%", fs - 1, p.foreground, align=RIGHT, bold=true))
}
Timeout(k, label) => {
let m = if k == 0 { @power.screen_off_minutes() } else { @power.suspend_minutes() }
ops.push(@ui.text(margin + 10, mid, label, fs - 1, list_fg))
@@ -1000,6 +1063,17 @@ pub fn on_event(target : Surface, event : @types.InputEvent) -> Bool {
} else if k == "1" || k == "2" || k == "3" || k == "4" || k == "5" || k == "6" {
set_tab(k[0].to_int() - '1'.to_int())
true
} else if k == "-" || k == "_" || k == "+" || k == "=" {
let rs = rows()
if active(rs, hover.val) && rs[hover.val] is Brightness {
let cur = @power.brightness()
if cur >= 0 {
let delta = if k == "-" || k == "_" { -10 } else { 10 }
@power.set_brightness(clamp_brightness(cur + delta).reinterpret_as_uint())
return true
}
}
false
} else {
false
}