Task manager: draw each app's real icon from its .desktop file
CI / test (push) Failing after 16s

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
This commit is contained in:
Claude committed 2026-11-25 18:52:58 +00:00
1 parent 0e6a1257e1
commit f2e870c251
53 files changed
+2284 -473

No files matched your search

+88
View File
@@ -0,0 +1,88 @@
///| Images the compositor loaded (app icons) and the `Image` draw op that shows them.
///| Loaded images; handle `i + 1` is `images[i]` (0 means "no image").
let images : Array[Pixmap] = []
///| Each image scaled to the sizes it has been drawn at, by (handle, w, h).
let scaled : Map[(UInt, Int, Int), Pixmap] = {}
///| Keep `p` for `Image` ops and return its handle (never 0).
pub fn add_image(p : Pixmap) -> UInt {
images.push(p)
images.length().reinterpret_as_uint()
}
///| Scale `src` to `w`x`h`: each target pixel averages the source pixels it covers (alpha
/// weighted, so transparent edges don't darken), or takes the nearest one when enlarging.
pub fn scale_pixmap(src : Pixmap, w : Int, h : Int) -> Pixmap {
let out = Pixmap::new(w, h)
for y = 0; y < h; y = y + 1 {
let y0 = y * src.height / h
let y1 = { let e = (y + 1) * src.height / h; if e > y0 { e } else { y0 + 1 } }
for x = 0; x < w; x = x + 1 {
let x0 = x * src.width / w
let x1 = { let e = (x + 1) * src.width / w; if e > x0 { e } else { x0 + 1 } }
let mut r = 0
let mut g = 0
let mut b = 0
let mut a = 0
let mut n = 0
for sy = y0; sy < y1; sy = sy + 1 {
for sx = x0; sx < x1; sx = sx + 1 {
let o = (sy * src.width + sx) * 4
let pa = src.data[o + 3].to_int()
r = r + src.data[o].to_int() * pa
g = g + src.data[o + 1].to_int() * pa
b = b + src.data[o + 2].to_int() * pa
a = a + pa
n = n + 1
}
}
let o = (y * w + x) * 4
if a > 0 {
out.data[o] = (r / a).to_byte()
out.data[o + 1] = (g / a).to_byte()
out.data[o + 2] = (b / a).to_byte()
out.data[o + 3] = (a / n).to_byte()
}
}
}
out
}
///| Draw image `handle` scaled into `r` (unknown handles draw nothing).
fn draw_image(dst : Pixmap, handle : UInt, r : @scene.Rect, clip : @scene.Rect?) -> Unit {
let i = handle.reinterpret_as_int() - 1
if i < 0 || i >= images.length() || r.w <= 0 || r.h <= 0 || r.w > 1024 || r.h > 1024 {
return
}
let key = (handle, r.w, r.h)
let img = match scaled.get(key) {
Some(p) => p
None => {
let src = images[i]
let p = if src.width == r.w && src.height == r.h {
src
} else {
scale_pixmap(src, r.w, r.h)
}
scaled.set(key, p)
p
}
}
for y = 0; y < r.h; y = y + 1 {
for x = 0; x < r.w; x = x + 1 {
let o = (y * r.w + x) * 4
blend_pixel(
dst,
r.x + x,
r.y + y,
img.data[o].to_int(),
img.data[o + 1].to_int(),
img.data[o + 2].to_int(),
img.data[o + 3].to_int(),
clip,
)
}
}
}