Applications menu and Icon Desktop: show each app's .desktop icon
CI / test (push) Failing after 2m56s
CI / test (push) Failing after 2m56s
The launcher's rows drew a letter circle and the Icon Desktop fell back to letter tiles for every app that wasn't in the dock: the shell only published icons for windows' and dock apps. publish_icons now also covers the rows the open Applications menu lists (only those, so opening it looks up a handful of icons) and every catalog app when the desktop module imports icons. Lookups are the dock's (theme chain, absolute Icon= paths, PNG on the native host, SVG too on the wasm host, generic app icon, then the letter tile) and cached per id; an unchanged icons table is no longer re-sent every frame. launcher-widget imports icons; the JS host has an icons stub (always 0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hkhaM5djqPXPQNs7QR
This commit is contained in:
12 files changed
+273
-29
No files matched your search
@@ -0,0 +1,112 @@
|
||||
///| App icons in the Applications menu and on the Icon Desktop: the shell publishes the .desktop
|
||||
/// icon of every app they show (compositor/shell/icons.mbt `icon_app_ids`), and both draw it.
|
||||
/// Needs the modules built: scripts/build-modules.sh.
|
||||
|
||||
///| A 48x48 PNG of one colour at `path`.
|
||||
fn write_icon_png(path : String, r : Int, g : Int, b : Int) -> Unit {
|
||||
let p = @renderer.Pixmap::new(48, 48)
|
||||
for i = 0; i < 48 * 48; i = i + 1 {
|
||||
p.data[i * 4] = r.to_byte()
|
||||
p.data[i * 4 + 1] = g.to_byte()
|
||||
p.data[i * 4 + 2] = b.to_byte()
|
||||
p.data[i * 4 + 3] = b'\xff'
|
||||
}
|
||||
ignore(@sys.write_file_bytes(path, @renderer.encode_png(p)))
|
||||
}
|
||||
|
||||
///| The (r, g, b) of the frame at (x, y).
|
||||
fn frame_rgb(f : @renderer.Pixmap, x : Int, y : Int) -> (Int, Int, Int) {
|
||||
let i = (y * f.width + x) * 4
|
||||
(f.data[i].to_int(), f.data[i + 1].to_int(), f.data[i + 2].to_int())
|
||||
}
|
||||
|
||||
///| A compositor with the six fake apps of `desk_comp`, where app0's .desktop file says
|
||||
/// Icon=<an absolute path to a red PNG>.
|
||||
fn icon_comp(tag : String) -> @host.ChandraCompositor {
|
||||
let comp = desk_comp(tag)
|
||||
let png = "/tmp/chandra-icon-" + tag + "-" + @sys.getpid().to_string() + ".png"
|
||||
write_icon_png(png, 230, 20, 20)
|
||||
comp.shell.exec.set("app0", "app0")
|
||||
comp.shell.icon_names.set("app0", png)
|
||||
// The first frame already looked app0 up (the dock pins it): forget that.
|
||||
comp.shell.icon_handles.remove("app0")
|
||||
comp
|
||||
}
|
||||
|
||||
///|
|
||||
test "the Icon Desktop gets every catalog app's icon, drawn from an absolute Icon= path" {
|
||||
let comp = icon_comp("idesk")
|
||||
let before = comp.shell.icon_app_ids()
|
||||
assert_false(before.contains("app5"))
|
||||
assert_true(comp.shell.set_desktop("icon-desktop"))
|
||||
ignore(comp.compose_frame())
|
||||
let ids = comp.shell.icon_app_ids()
|
||||
for i = 0; i < 6; i = i + 1 {
|
||||
assert_true(ids.contains("app" + i.to_string()))
|
||||
}
|
||||
assert_true(comp.shell.window_icon("app0") != 0U)
|
||||
// app0's icon sits in the first cell (see desktop_test): its middle is the PNG's red.
|
||||
let f = comp.compose_frame()
|
||||
assert_eq(frame_rgb(f, 68, 50), (230, 20, 20))
|
||||
ignore(@sys.write_file_bytes("_build/desktop_icons_real.png", @renderer.encode_png(f)))
|
||||
comp.shell.shutdown()
|
||||
}
|
||||
|
||||
///|
|
||||
test "the open Applications menu gets its rows' icons and draws them" {
|
||||
let comp = icon_comp("lmenu")
|
||||
assert_false(comp.shell.icon_app_ids().contains("app5"))
|
||||
comp.shell.toggle_launcher()
|
||||
for _ in 0..<10 {
|
||||
@sys.sleep_ms(30) // the popup slides in
|
||||
ignore(comp.compose_frame())
|
||||
}
|
||||
let pr = comp.shell.slot_popup_rect(comp.shell.slot_of("launcher"))
|
||||
assert_true(pr.w > 0)
|
||||
let ids = comp.shell.icon_app_ids()
|
||||
for i = 0; i < 6; i = i + 1 {
|
||||
assert_true(ids.contains("app" + i.to_string()))
|
||||
}
|
||||
let f = comp.compose_frame()
|
||||
// Row 0 is app0 ("Files"): its icon is centred 30 px in, half a row (46 px) below the header.
|
||||
assert_eq(frame_rgb(f, pr.x + 30, pr.y + 52 + 22), (230, 20, 20))
|
||||
ignore(@sys.write_file_bytes("_build/launcher_icons.png", @renderer.encode_png(f)))
|
||||
// Closed again: the menu's apps drop out of the table.
|
||||
comp.shell.toggle_launcher()
|
||||
ignore(comp.compose_frame())
|
||||
assert_false(comp.shell.icon_app_ids().contains("app5"))
|
||||
comp.shell.shutdown()
|
||||
}
|
||||
|
||||
///| For a look: the menu and the Icon Desktop with theme icons (whatever the machine's hicolor
|
||||
/// theme has for these names; letter tiles or the generic icon where it has nothing). Writes
|
||||
/// _build/launcher_icons_themed.png and _build/desktop_icons_themed.png.
|
||||
test "screenshots: Applications menu and Icon Desktop with theme icons" {
|
||||
let comp = desk_comp("ishot")
|
||||
let apps = [
|
||||
("org.libreoffice.Writer", "Writer", "Word processor", "libreoffice-writer"),
|
||||
("org.libreoffice.Calc", "Calc", "Spreadsheets", "libreoffice-calc"),
|
||||
("org.libreoffice.Impress", "Impress", "Presentations", "libreoffice-impress"),
|
||||
("org.libreoffice.Draw", "Draw", "Drawings and diagrams", "libreoffice-draw"),
|
||||
("xterm", "XTerm", "Terminal emulator", "xterm-color"),
|
||||
("gvim", "GVim", "Text editor", "gvim"),
|
||||
]
|
||||
comp.shell.apps.clear()
|
||||
for a in apps {
|
||||
comp.shell.apps.push({ id: a.0, name: a.1, comment: a.2, category: "", glyph: "" })
|
||||
comp.shell.exec.set(a.0, a.0)
|
||||
comp.shell.icon_names.set(a.0, a.3)
|
||||
comp.shell.icon_handles.remove(a.0)
|
||||
}
|
||||
comp.shell.apps_dirty = true
|
||||
assert_true(comp.shell.set_desktop("icon-desktop"))
|
||||
ignore(comp.compose_frame())
|
||||
ignore(@sys.write_file_bytes("_build/desktop_icons_themed.png", @renderer.encode_png(comp.compose_frame())))
|
||||
comp.shell.toggle_launcher()
|
||||
for _ in 0..<10 {
|
||||
@sys.sleep_ms(30)
|
||||
ignore(comp.compose_frame())
|
||||
}
|
||||
ignore(@sys.write_file_bytes("_build/launcher_icons_themed.png", @renderer.encode_png(comp.compose_frame())))
|
||||
comp.shell.shutdown()
|
||||
}
|
||||
+54
-21
@@ -493,37 +493,70 @@ pub fn DesktopShell::window_icon(self : DesktopShell, app_id : String) -> UInt {
|
||||
if app_id.length() == 0 { 0U } else { self.app_icon(app_id) }
|
||||
}
|
||||
|
||||
///| Publish the icons table (app id -> image handle) for the windows' apps and the dock's.
|
||||
fn DesktopShell::publish_icons(self : DesktopShell) -> Unit {
|
||||
let t = @wasm.Table::new()
|
||||
///| The app ids whose icons the modules need now: the windows' apps, the dock's apps (running or
|
||||
/// not), the rows the Applications menu shows while it is open (only those, so opening it looks
|
||||
/// up a handful of icons, not the whole catalog), and every app the desktop module can show when
|
||||
/// it imports `icons` (Icon Desktop). Each id once, in that order.
|
||||
pub fn DesktopShell::icon_app_ids(self : DesktopShell) -> Array[String] {
|
||||
let out : Array[String] = []
|
||||
let seen : Map[String, Bool] = {}
|
||||
for w in self.win_list {
|
||||
if w.app_id.length() > 0 && !seen.contains(w.app_id) {
|
||||
seen.set(w.app_id, true)
|
||||
let h = self.app_icon(w.app_id)
|
||||
if h != 0U {
|
||||
t.str(w.app_id)
|
||||
t.int(h.reinterpret_as_int())
|
||||
t.end_row()
|
||||
}
|
||||
let add = fn(id : String) {
|
||||
if id.length() > 0 && !seen.contains(id) {
|
||||
seen.set(id, true)
|
||||
out.push(id)
|
||||
}
|
||||
}
|
||||
// The dock's apps, running or not.
|
||||
for w in self.win_list {
|
||||
add(w.app_id)
|
||||
}
|
||||
for id in self.dock_app_ids() {
|
||||
if !seen.contains(id) {
|
||||
seen.set(id, true)
|
||||
let h = self.app_icon(id)
|
||||
if h != 0U {
|
||||
t.str(id)
|
||||
t.int(h.reinterpret_as_int())
|
||||
t.end_row()
|
||||
add(id)
|
||||
}
|
||||
for id in self.launcher_icon_ids() {
|
||||
add(id)
|
||||
}
|
||||
match self.desk_mod {
|
||||
Some(d) if d.has_cap("icons") =>
|
||||
for a in self.apps {
|
||||
add(a.id)
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
///| The apps the open Applications menu lists (as the shell follows its search), else none.
|
||||
fn DesktopShell::launcher_icon_ids(self : DesktopShell) -> Array[String] {
|
||||
let st = self.launcher_state
|
||||
if !st.open {
|
||||
return []
|
||||
}
|
||||
@launcher.shown_rows(self.apps, st).map(a => a.id)
|
||||
}
|
||||
|
||||
///| Publish the icons table (app id -> image handle) for `icon_app_ids`. Lookups are cached per id
|
||||
/// (`lookup_icon`), and an unchanged table is not sent again.
|
||||
fn DesktopShell::publish_icons(self : DesktopShell) -> Unit {
|
||||
let rows : Array[(String, UInt)] = []
|
||||
for id in self.icon_app_ids() {
|
||||
let h = self.app_icon(id)
|
||||
if h != 0U {
|
||||
rows.push((id, h))
|
||||
}
|
||||
}
|
||||
if rows == self.icons_published {
|
||||
return
|
||||
}
|
||||
self.icons_published = rows
|
||||
let t = @wasm.Table::new()
|
||||
for r in rows {
|
||||
t.str(r.0)
|
||||
t.int(r.1.reinterpret_as_int())
|
||||
t.end_row()
|
||||
}
|
||||
@wasm.publish(Icons, t)
|
||||
}
|
||||
|
||||
|
||||
///| The image handle of theme icon `name` (say "drive-harddisk"; 0: none), cached.
|
||||
pub fn DesktopShell::theme_icon(self : DesktopShell, name : String) -> UInt {
|
||||
if name == "" {
|
||||
|
||||
@@ -242,6 +242,9 @@ pub(all) struct DesktopShell {
|
||||
/// (0: no icon), for the `icons` capability.
|
||||
icon_names : Map[String, String]
|
||||
icon_handles : Map[String, UInt]
|
||||
/// The icons table as last published (app id, handle), so an unchanged table isn't sent again
|
||||
/// every frame.
|
||||
mut icons_published : Array[(String, UInt)]
|
||||
/// Icon base dirs and theme chain (icons.mbt), read on first use.
|
||||
mut icon_search : IconSearch?
|
||||
/// Wayland socket handed to launched apps as WAYLAND_DISPLAY.
|
||||
@@ -432,6 +435,7 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
|
||||
wm_classes,
|
||||
icon_names,
|
||||
icon_handles: {},
|
||||
icons_published: [],
|
||||
icon_search: None,
|
||||
display,
|
||||
widgets: [],
|
||||
|
||||
Reference in new issue
Block a user