From 44688453d7c66feeb2e6cde63624ffe3701bf42b Mon Sep 17 00:00:00 2001 From: nandithebull Date: Wed, 25 Nov 2026 23:01:15 -0800 Subject: [PATCH] Icons: load an absolute Icon= path that has no extension AppImage managers write icons as extensionless files, so those apps got the generic icon. Any absolute path is now tried, and the loaders tell PNG and SVG apart from the contents. Co-Authored-By: Claude Sonnet 5.5 --- compositor/host/launcher_icons_test.mbt | 4 ++-- compositor/raster/raster_native.mbt | 10 +++------- compositor/shell/icons.mbt | 8 +++----- compositor/shell/icons_wbtest.mbt | 1 + wasmhost/bin/raster.mbt | 10 +++++++++- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/compositor/host/launcher_icons_test.mbt b/compositor/host/launcher_icons_test.mbt index 1310da3..133f25c 100644 --- a/compositor/host/launcher_icons_test.mbt +++ b/compositor/host/launcher_icons_test.mbt @@ -21,10 +21,10 @@ fn frame_rgb(f : @renderer.Pixmap, x : Int, y : Int) -> (Int, Int, Int) { } ///| A compositor with the six fake apps of `desk_comp`, where app0's .desktop file says -/// Icon=. +/// Icon=. fn icon_comp(tag : String) -> @host.ChandraCompositor { let comp = desk_comp(tag) - let png = "/tmp/chandra-icon-" + tag + "-" + @sys.getpid().to_string() + ".png" + let png = "/tmp/chandra-icon-" + tag + "-" + @sys.getpid().to_string() write_icon_png(png, 230, 20, 20) comp.shell.exec.set("app0", "app0") comp.shell.icon_names.set("app0", png) diff --git a/compositor/raster/raster_native.mbt b/compositor/raster/raster_native.mbt index 30e39cb..0b1c1ad 100644 --- a/compositor/raster/raster_native.mbt +++ b/compositor/raster/raster_native.mbt @@ -63,13 +63,9 @@ pub fn load_image(path : String) -> UInt { match loaded_images.get(path) { Some(h) => h None => { - let h = if path.has_suffix(".png") { - match @renderer.decode_png(@sys.read_file_bytes(path)) { - Some(p) => @renderer.add_image(p) - None => 0U - } - } else { - 0U + let h = match @renderer.decode_png(@sys.read_file_bytes(path)) { + Some(p) => @renderer.add_image(p) + None => 0U } loaded_images.set(path, h) h diff --git a/compositor/shell/icons.mbt b/compositor/shell/icons.mbt index 1be26be..08ce95f 100644 --- a/compositor/shell/icons.mbt +++ b/compositor/shell/icons.mbt @@ -268,11 +268,9 @@ fn icon_candidates( return [] } if name.has_prefix("/") { - return if name.has_suffix(".png") || (svg_ok && name.has_suffix(".svg")) { - [name] - } else { - [] - } + // Any file name: AppImage managers write icons without an extension, and the loader tells + // the type from the contents. + return if !svg_ok && name.has_suffix(".svg") { [] } else { [name] } } // Icon=foo.png is not allowed by the spec but common: look it up as "foo". let stem = if name.has_suffix(".png") || name.has_suffix(".svg") || name.has_suffix(".xpm") { diff --git a/compositor/shell/icons_wbtest.mbt b/compositor/shell/icons_wbtest.mbt index fa70553..a95a83a 100644 --- a/compositor/shell/icons_wbtest.mbt +++ b/compositor/shell/icons_wbtest.mbt @@ -62,6 +62,7 @@ test "themes without an index.theme use the hicolor layout, then pixmaps" { assert_eq(icon_candidates("foo.png", false, [("hicolor", None)], ["/b"], [])[0], "/b/hicolor/48x48/apps/foo.png") assert_eq(icon_candidates("/opt/app/icon.png", false, [], ["/b"], []), ["/opt/app/icon.png"]) assert_eq(icon_candidates("/opt/app/icon.svg", false, [], ["/b"], []), []) + assert_eq(icon_candidates("/opt/app/.icons/app", false, [], ["/b"], []), ["/opt/app/.icons/app"]) assert_eq(icon_candidates("", true, [], ["/b"], []), []) } diff --git a/wasmhost/bin/raster.mbt b/wasmhost/bin/raster.mbt index 55b0395..13d733b 100644 --- a/wasmhost/bin/raster.mbt +++ b/wasmhost/bin/raster.mbt @@ -826,6 +826,14 @@ let image_paths : Map[String, Int] = {} ///| Biggest image side accepted from a file. const MAX_IMAGE : Int = 1024 +///| Whether a file without the `.svg` extension is an SVG: it starts like XML and has an ` Bool { + let head = b[:@cmp.minimum(b.length(), 4096)] + let text = @utf8.decode_lossy(head).trim(chars="\u{FEFF} \t\r\n") + text.has_prefix("<") && text.contains(" Int { match image_paths.get(path) { @@ -839,7 +847,7 @@ fn load_image(path : String) -> Int { rs_image_put(0, p.width, p.height, p.data) _ => 0 } - } else if path.has_suffix(".svg") && b.length() > 0 { + } else if b.length() > 0 && (path.has_suffix(".svg") || looks_like_svg(b)) { rs_image_svg(b) } else { 0