Task manager: show an app icon on each window's pill
CI / test (push) Failing after 18s

Each pill now starts with the app's icon: the same coloured tile with a
letter that the dock draws for that app id, so an app looks the same in
both. The app id comes from windows.all (the task-bar rows carry only
titles); windows without one fall back to a title-keyed tile. Pills
narrower than 72px show just the centred icon.

The tile drawing moves into lib/dock (app_icon, app_glyph) and the dock
uses it too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hm1XqzhrA4N8FyhuRa
This commit is contained in:
Claude committed 2026-11-25 18:31:41 +00:00
1 parent 46780c399b
commit 9a25d70f77
5 files changed
+105 -12

No files matched your search

@@ -3,6 +3,7 @@ import {
"chandra/desktop/interface/chandra/desktop/theme" @theme,
"chandra/desktop/interface/chandra/desktop/windows" @windows,
"chandra/desktop/lib/ui" @ui,
"chandra/desktop/lib/dock" @dock,
}
warnings = "-44"
@@ -1,7 +1,9 @@
///| Implementation of `chandra:desktop/plasmoid` for the task manager: one pill per open
/// window, in the order the windows were opened (so the bar doesn't reshuffle when focus changes).
/// Each pill starts with the app's icon (the same coloured tile the dock shows for that app id).
/// The focused window's pill is lit, a minimized window's is dimmed; a click focuses the window and
/// restores it if it was minimized. When the bar is too narrow the pills shrink to fit.
/// restores it if it was minimized. When the bar is too narrow the pills shrink to fit, and below
/// `icon_only_w` they show just the icon.
///| Widest a pill gets, the gap between pills, and the narrowest before titles stop being readable.
let pill_max : Int = 140
@@ -12,6 +14,25 @@ let gap : Int = 6
///|
let pill_min : Int = 56
///| Pills narrower than this drop the title and show only the centred icon.
let icon_only_w : Int = 72
///| Edge of the icon tile in a bar `h` pixels tall.
fn icon_size(h : Int) -> Int {
let s = h - 12
if s < 14 { 14 } else if s > 22 { 22 } else { s }
}
///| App id of every window, by window id, from the richer `windows.all` view (the task-bar
/// rows carry only titles).
fn app_ids() -> Map[UInt, String] {
let m : Map[UInt, String] = Map([])
for d in @windows.all() {
m.set((d.id & 0xFFFFFFFFUL).to_uint(), d.app_id)
}
m
}
///| The width the module was last drawn at, and the pill the pointer is over (-1: none).
let last_w : Ref[Int] = { val: 300 }
@@ -96,6 +117,7 @@ pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
let fs = t.font_size.reinterpret_as_int()
let ws = windows_sorted()
let pw = pill_w(ws.length(), w)
let ids = app_ids()
let ops : Array[@types.DrawOp] = []
for i = 0; i < ws.length(); i = i + 1 {
let x = i * (pw + gap)
@@ -124,7 +146,18 @@ pub fn render(size : @types.Size) -> Array[@types.DrawOp] {
ops.push(@ui.stroke_rect(@ui.rect(x, 0, pw, h), t.palette.border, width=1, radius=r))
}
let title = if win.title.length() > 0 { win.title } else { "(untitled)" }
ops.push(@ui.text(x + 10, h / 2, fit_text(title, fs, pw - 20), fs, fg, bold=focused))
let app = ids.get(win.id).unwrap_or("")
let glyph = @dock.app_glyph(app, title)
// Windows without an app id still get a stable colour, keyed by their title.
let key = if app.length() > 0 { app } else { title }
let isz = icon_size(h)
if pw < icon_only_w {
ops.append(@dock.app_icon(x + pw / 2, h / 2, isz, key, glyph))
} else {
ops.append(@dock.app_icon(x + 6 + isz / 2, h / 2, isz, key, glyph))
let tx = x + 6 + isz + 6
ops.push(@ui.text(tx, h / 2, fit_text(title, fs, x + pw - 8 - tx), fs, fg, bold=focused))
}
}
ops
}