Icons: load an absolute Icon= path that has no extension
CI / test (push) Failing after 31m49s

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 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-25 23:01:20 -08:00
1 parent 27252a97ab
commit 44688453d7
5 files changed
+16 -13

No files matched your search

+2 -2
View File
@@ -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 ///| A compositor with the six fake apps of `desk_comp`, where app0's .desktop file says
/// Icon=<an absolute path to a red PNG>. /// Icon=<an absolute path to a red PNG without an extension, as AppImage managers write it>.
fn icon_comp(tag : String) -> @host.ChandraCompositor { fn icon_comp(tag : String) -> @host.ChandraCompositor {
let comp = desk_comp(tag) 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) write_icon_png(png, 230, 20, 20)
comp.shell.exec.set("app0", "app0") comp.shell.exec.set("app0", "app0")
comp.shell.icon_names.set("app0", png) comp.shell.icon_names.set("app0", png)
+1 -5
View File
@@ -63,14 +63,10 @@ pub fn load_image(path : String) -> UInt {
match loaded_images.get(path) { match loaded_images.get(path) {
Some(h) => h Some(h) => h
None => { None => {
let h = if path.has_suffix(".png") { let h = match @renderer.decode_png(@sys.read_file_bytes(path)) {
match @renderer.decode_png(@sys.read_file_bytes(path)) {
Some(p) => @renderer.add_image(p) Some(p) => @renderer.add_image(p)
None => 0U None => 0U
} }
} else {
0U
}
loaded_images.set(path, h) loaded_images.set(path, h)
h h
} }
+3 -5
View File
@@ -268,11 +268,9 @@ fn icon_candidates(
return [] return []
} }
if name.has_prefix("/") { if name.has_prefix("/") {
return if name.has_suffix(".png") || (svg_ok && name.has_suffix(".svg")) { // Any file name: AppImage managers write icons without an extension, and the loader tells
[name] // the type from the contents.
} else { 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". // 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") { let stem = if name.has_suffix(".png") || name.has_suffix(".svg") || name.has_suffix(".xpm") {
+1
View File
@@ -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("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.png", false, [], ["/b"], []), ["/opt/app/icon.png"])
assert_eq(icon_candidates("/opt/app/icon.svg", false, [], ["/b"], []), []) 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"], []), []) assert_eq(icon_candidates("", true, [], ["/b"], []), [])
} }
+9 -1
View File
@@ -826,6 +826,14 @@ let image_paths : Map[String, Int] = {}
///| Biggest image side accepted from a file. ///| Biggest image side accepted from a file.
const MAX_IMAGE : Int = 1024 const MAX_IMAGE : Int = 1024
///| Whether a file without the `.svg` extension is an SVG: it starts like XML and has an `<svg`
/// tag near the top.
fn looks_like_svg(b : Bytes) -> 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("<svg")
}
///| Load the PNG or SVG at `path` (an app icon); the same path gives the same handle. 0 on failure. ///| Load the PNG or SVG at `path` (an app icon); the same path gives the same handle. 0 on failure.
fn load_image(path : String) -> Int { fn load_image(path : String) -> Int {
match image_paths.get(path) { 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) rs_image_put(0, p.width, p.height, p.data)
_ => 0 _ => 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) rs_image_svg(b)
} else { } else {
0 0