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

+48 -1
View File
@@ -46,11 +46,13 @@ pub const T_MODULES: usize = 3;
pub const T_INSTANCES: usize = 4;
pub const T_WALLPAPERS: usize = 5;
pub const T_SESSION_SETTINGS: usize = 6;
/// App id -> raster image handle (`raster.load-image`), behind `icons.app-icon`.
pub const T_ICONS: usize = 7;
/// Host data every module reads from, shared by all loaded modules.
#[derive(Default)]
pub struct Shared {
pub tables: [Vec<u8>; 7],
pub tables: [Vec<u8>; 8],
pub layout_mode: i32,
pub wallpaper: i32,
/// Which session settings are on: bit i for row i of the session settings table.
@@ -304,6 +306,18 @@ impl d::session_settings::Host for PState {
}
}
impl d::icons::Host for PState {
/// The handle the compositor published for this app id: it found the app's .desktop file and
/// its themed icon, and had the rasteriser load it. Modules never see the path.
fn app_icon(&mut self, app_id: String) -> u32 {
self.rows(T_ICONS, "si")
.iter()
.find(|r| s(&r[0]) == app_id)
.map(|r| i(&r[1]) as u32)
.unwrap_or(0)
}
}
impl d::system::Host for PState {
fn read(&mut self) -> d::system::Snapshot {
self.shared.borrow().system.clone().unwrap_or(d::system::Snapshot {
@@ -646,4 +660,37 @@ mod tests {
assert!(rt.shared.borrow().requests.is_empty());
rt.unload(h);
}
#[test]
fn task_list_draws_the_published_icon_handle_else_the_letter_tile() {
let mut rt = runtime();
let l = rt.load(&module("tasks")).expect("tasks loads");
assert!(l.imports.contains(&"icons".to_string()));
// windows table (isii: id title focused minimized) and the richer windows.all view
let mut t = 2u32.to_le_bytes().to_vec();
for (id, title) in [(3i32, "Firefox"), (4, "foot")] {
t.extend(id.to_le_bytes());
t.extend((title.len() as u32).to_le_bytes());
t.extend(title.as_bytes());
t.extend(0i32.to_le_bytes());
t.extend(0i32.to_le_bytes());
}
// icons table (si: app id, image handle): only Firefox has one
let mut ic = 1u32.to_le_bytes().to_vec();
ic.extend(7u32.to_le_bytes());
ic.extend(b"firefox");
ic.extend(42i32.to_le_bytes());
{
let mut sh = rt.shared.borrow_mut();
sh.tables[T_WINDOWS] = t;
sh.tables[T_ICONS] = ic;
sh.windows = vec![(3, "Firefox".into(), "firefox".into(), false), (4, "foot".into(), "foot".into(), false)];
}
let ops = rt.render(l.handle, Size { w: 400, h: 36 });
let images: Vec<u32> =
ops.iter().filter_map(|o| if let d::types::DrawOp::Image(i) = o { Some(i.image) } else { None }).collect();
assert_eq!(images, [42]);
assert_eq!(texts(&ops), ["Firefox", "F", "foot"]);
rt.unload(l.handle);
}
}