Files
chandra/compositor/raster/raster_wasm.mbt
T
Claude f2e870c251
CI / test (push) Failing after 16s
Task manager: draw each app's real icon from its .desktop file
Each pill now shows the icon the app's .desktop file names (Icon=), looked up in the
freedesktop icon themes, instead of the letter tile. The tile stays as the fallback for
windows with no app id, no desktop file or no icon the host can read.

- WIT: a new `icons` capability (`app-icon(app-id) -> u32`, a handle, never a path or pixels)
  and an `image(image-op)` draw op (appended, so existing modules keep their ABI).
  taskbar-widget and plasmoid-host import `icons`. Host raster gains `load-image(path)` and a
  `draw-image` op; the plasmoids host gets an icons table (6: app id, handle).
- Compositor (shell/icons.mbt): window app id -> desktop file (resolve_app_id, so StartupWMClass
  and last-dotted-part matches work) -> Icon= -> theme lookup (XDG data dirs, ~/.icons,
  flatpak exports; hicolor, Adwaita, breeze; 48/64/32 px PNG first, then scalable SVG when the
  host can draw it, then other sizes, then /usr/share/pixmaps). Absolute Icon= paths are used as
  they are. Results are cached per app id; the table is published only when a module imports
  `icons`.
- wasm host (host-wasm): PNG via the png crate, SVG via resvg (rendered sharp at each size),
  PNGs area-averaged to the drawn size; loads cached by path.
- Native build: a small PNG decoder (compositor/renderer/png.mbt: inflate + filters, 1-16 bit,
  palettes with tRNS) and the Image op in the software renderer. SVG-only icons fall back to the
  tile there. The wasmer stub serves `icons.app-icon` from the same table.
- Tests: PNG decoder fixtures (all filters, fixed/dynamic/stored blocks, palette), image scaling
  and drawing, icon lookup order, Icon= parsing, task module icon-or-tile (native and wasmtime),
  host raster PNG+SVG loading and drawing. Checked end to end with the wasm host: foot's
  hicolor icon shows on its pill.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hhmtDt52EjaW8jevGU
2026-11-25 18:52:58 +00:00

114 lines
3.8 KiB
MoonBit

///| Send a scene to the host to draw (`chandra:host/raster`).
///
/// The scene is the same one the software renderer takes (`@scene.SceneGraph`); here it is turned
/// into the interface's records and handed over. The host owns the framebuffer and does the pixel
/// work natively; client window buffers are already there (captured at commit, by id).
///|
fn conv_rect(r : @scene.Rect) -> @hostraster.Rect {
{ x: r.x, y: r.y, w: r.w, h: r.h }
}
///|
fn conv_color(c : @scene.Rgba) -> @hostraster.Color {
{ r: c.r, g: c.g, b: c.b, a: c.a }
}
///|
fn conv_align(a : @scene.TextAlign) -> Byte {
match a {
Left => b'\x00'
Center => b'\x01'
Right => b'\x02'
}
}
///|
fn conv_op(op : @scene.DrawOp) -> @hostraster.Op {
match op {
FillRect(r, c, radius) => FillRect({ area: conv_rect(r), color: conv_color(c), radius })
StrokeRect(r, c, width, radius) => StrokeRect({ area: conv_rect(r), color: conv_color(c), width, radius })
Line(x0, y0, x1, y1, c, width) => DrawLine({ x0, y0, x1, y1, color: conv_color(c), width })
Circle(cx, cy, radius, c, filled) => DrawCircle({ cx, cy, radius, color: conv_color(c), filled })
Text(x, y, text, size, c, align, bold) =>
DrawText({ x, y, text, size, color: conv_color(c), align: conv_align(align), bold, mono: false })
MonoText(x, y, text, size, c, align, bold) =>
DrawText({ x, y, text, size, color: conv_color(c), align: conv_align(align), bold, mono: true })
PushClip(r) => PushClip(conv_rect(r))
PopClip => PopClip
Image(r, image) => DrawImage({ area: conv_rect(r), image })
}
}
///|
fn conv_ops(ops : Array[@scene.DrawOp]) -> Array[@hostraster.Op] {
ops.map(conv_op)
}
///| The backdrop (wallpaper and the desktop card on it) the host last drew, and the size it was
/// drawn for. While neither changes the frame says "unchanged" and the host reuses its cached
/// pixels instead of being sent about two thousand ops again and drawing them.
let last_backdrop : Ref[Array[@scene.DrawOp]?] = { val: None }
///|
let last_size : Ref[(Int, Int)] = { val: (0, 0) }
///| Draw `scene` into the host framebuffer.
pub fn submit(scene : @scene.SceneGraph) -> Unit {
let backdrop = scene.wallpaper_ops + scene.background_ops
let same = match last_backdrop.val {
Some(prev) => prev == backdrop && last_size.val == (scene.output_w, scene.output_h)
None => false
}
if !same {
last_backdrop.val = Some(backdrop)
last_size.val = (scene.output_w, scene.output_h)
}
let windows : Array[@hostraster.Window] = scene.windows.map(w => {
let (top, right, bottom, left) = w.deco_insets
{
geometry: conv_rect(w.geometry),
inset_top: top,
inset_right: right,
inset_bottom: bottom,
inset_left: left,
deco: conv_ops(w.deco_ops),
fullscreen: w.fullscreen,
surface: match w.surface {
Some(s) => s.host_id
None => 0U
},
}
})
@hostraster.submit({
width: scene.output_w,
height: scene.output_h,
wallpaper: if same { None } else { Some(conv_ops(backdrop)) },
background: [],
windows,
panel: conv_ops(scene.panel_ops),
popups: scene.popups.map(p => { area: conv_rect(p.0), surface: p.1.host_id }),
})
}
///| The host framebuffer as a pixmap (screenshots and tests; the display path never needs it).
pub fn read_frame(width : Int, height : Int) -> @renderer.Pixmap {
let data = @hostraster.read_frame()
{ width, height, data }
}
///| Images already loaded, by path (0: it failed, don't ask the host again).
let loaded_images : Map[String, UInt] = {}
///| Have the host load the PNG or SVG file at `path` for `Image` draw ops: a handle, or 0.
pub fn load_image(path : String) -> UInt {
match loaded_images.get(path) {
Some(h) => h
None => {
let h = @hostraster.load_image(path)
loaded_images.set(path, h)
h
}
}
}