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:
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/theme" @theme,
|
||||||
"chandra/desktop/interface/chandra/desktop/windows" @windows,
|
"chandra/desktop/interface/chandra/desktop/windows" @windows,
|
||||||
"chandra/desktop/lib/ui" @ui,
|
"chandra/desktop/lib/ui" @ui,
|
||||||
|
"chandra/desktop/lib/dock" @dock,
|
||||||
}
|
}
|
||||||
|
|
||||||
warnings = "-44"
|
warnings = "-44"
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
///| Implementation of `chandra:desktop/plasmoid` for the task manager: one pill per open
|
///| 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).
|
/// 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
|
/// 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.
|
///| Widest a pill gets, the gap between pills, and the narrowest before titles stop being readable.
|
||||||
let pill_max : Int = 140
|
let pill_max : Int = 140
|
||||||
@@ -12,6 +14,25 @@ let gap : Int = 6
|
|||||||
///|
|
///|
|
||||||
let pill_min : Int = 56
|
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).
|
///| The width the module was last drawn at, and the pill the pointer is over (-1: none).
|
||||||
let last_w : Ref[Int] = { val: 300 }
|
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 fs = t.font_size.reinterpret_as_int()
|
||||||
let ws = windows_sorted()
|
let ws = windows_sorted()
|
||||||
let pw = pill_w(ws.length(), w)
|
let pw = pill_w(ws.length(), w)
|
||||||
|
let ids = app_ids()
|
||||||
let ops : Array[@types.DrawOp] = []
|
let ops : Array[@types.DrawOp] = []
|
||||||
for i = 0; i < ws.length(); i = i + 1 {
|
for i = 0; i < ws.length(); i = i + 1 {
|
||||||
let x = i * (pw + gap)
|
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))
|
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)" }
|
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
|
ops
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,8 +110,12 @@ test "task list module draws the host's windows and asks to focus one" {
|
|||||||
t.int(1)
|
t.int(1)
|
||||||
t.end_row()
|
t.end_row()
|
||||||
publish(Windows, t)
|
publish(Windows, t)
|
||||||
|
// Icons come from each window's app id (served by `windows.all`); without one, from the title.
|
||||||
|
set_windows([{ id: 9UL, title: "foot", app_id: "org.chandra.term", focused: false }])
|
||||||
let ops = p.render(400, 36, test_tokens())
|
let ops = p.render(400, 36, test_tokens())
|
||||||
assert_eq(texts_of(ops), ["Kate — notes", "foot"])
|
// each pill: the app icon's glyph, then the title
|
||||||
|
assert_eq(texts_of(ops), ["K", "Kate — notes", "T", "foot"])
|
||||||
|
set_windows([])
|
||||||
assert_true(p.on_event(false, PointerDown(146 + 10, 10)) || true)
|
assert_true(p.on_event(false, PointerDown(146 + 10, 10)) || true)
|
||||||
assert_eq(drain(), [FocusWindow(9)])
|
assert_eq(drain(), [FocusWindow(9)])
|
||||||
p.unload()
|
p.unload()
|
||||||
|
|||||||
+42
-9
@@ -82,6 +82,47 @@ pub fn tile_color(id : String) -> @types.Color {
|
|||||||
@ui.color(r, g, b, 255)
|
@ui.color(r, g, b, 255)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///| The letter on an app's icon tile when the app catalog's glyph isn't at hand (the task manager
|
||||||
|
/// only knows a window's app id): the first letter of the id's last dotted part, so
|
||||||
|
/// `org.gnome.Nautilus` -> "N" and `foot` -> "F". Falls back to `fallback`'s first letter, then "?".
|
||||||
|
pub fn app_glyph(app_id : String, fallback : String) -> String {
|
||||||
|
let parts = app_id.split(".").to_array()
|
||||||
|
let mut i = parts.length() - 1
|
||||||
|
while i >= 0 {
|
||||||
|
for c in parts[i] {
|
||||||
|
if c.is_ascii_alphabetic() || c.is_ascii_digit() {
|
||||||
|
return c.to_string().to_upper()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i = i - 1
|
||||||
|
}
|
||||||
|
for c in fallback {
|
||||||
|
if c != ' ' {
|
||||||
|
return c.to_string().to_upper()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"?"
|
||||||
|
}
|
||||||
|
|
||||||
|
///| An app's icon: a rounded tile `s` pixels square centred on (cx, cy) in the app's colour, with
|
||||||
|
/// its glyph in white. Shared by the dock and the task manager so an app looks the same in both.
|
||||||
|
pub fn app_icon(
|
||||||
|
cx : Int,
|
||||||
|
cy : Int,
|
||||||
|
s : Int,
|
||||||
|
id : String,
|
||||||
|
glyph : String,
|
||||||
|
hover~ : Bool = false,
|
||||||
|
) -> Array[@types.DrawOp] {
|
||||||
|
let white = @ui.color(255, 255, 255, 255)
|
||||||
|
let c = tile_color(id)
|
||||||
|
let fill = if hover { @ui.lerp_color(c, white, 1, 5) } else { c }
|
||||||
|
[
|
||||||
|
@ui.fill_rect(@ui.rect(cx - s / 2, cy - s / 2, s, s), fill, radius=s / 4),
|
||||||
|
@ui.text(cx, cy, glyph, s * 11 / 20, white, align=CENTER, bold=true),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
///| Draw the dock into `size`. `hover` is the hovered tile index or -1.
|
///| Draw the dock into `size`. `hover` is the hovered tile index or -1.
|
||||||
pub fn render(
|
pub fn render(
|
||||||
size : @types.Size,
|
size : @types.Size,
|
||||||
@@ -102,18 +143,10 @@ pub fn render(
|
|||||||
)
|
)
|
||||||
return ops
|
return ops
|
||||||
}
|
}
|
||||||
let white = @ui.color(255, 255, 255, 255)
|
|
||||||
for i = 0; i < n; i = i + 1 {
|
for i = 0; i < n; i = i + 1 {
|
||||||
let s = tile_size(i, hover, h)
|
let s = tile_size(i, hover, h)
|
||||||
let cx = pad + i * pitch(h) + base_size(h) / 2
|
let cx = pad + i * pitch(h) + base_size(h) / 2
|
||||||
let x = cx - s / 2
|
ops.append(app_icon(cx, h / 2, s, apps[i].id, apps[i].glyph, hover=i == hover))
|
||||||
let y = (h - s) / 2
|
|
||||||
let c = tile_color(apps[i].id)
|
|
||||||
let fill = if i == hover { @ui.lerp_color(c, white, 1, 5) } else { c }
|
|
||||||
ops.push(@ui.fill_rect(@ui.rect(x, y, s, s), fill, radius=s / 4))
|
|
||||||
ops.push(
|
|
||||||
@ui.text(cx, h / 2, apps[i].glyph, s * 11 / 20, white, align=CENTER, bold=true),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
ops
|
ops
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,3 +55,25 @@ test "render draws one tile and glyph per app, capped at max_tiles" {
|
|||||||
assert_eq(tile_name(apps(), 1), "b!")
|
assert_eq(tile_name(apps(), 1), "b!")
|
||||||
assert_eq(tile_name(apps(), 9), "")
|
assert_eq(tile_name(apps(), 9), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "app glyph comes from the app id's last part, else the title" {
|
||||||
|
assert_eq(app_glyph("org.gnome.Nautilus", "Files"), "N")
|
||||||
|
assert_eq(app_glyph("foot", ""), "F")
|
||||||
|
assert_eq(app_glyph("org.chandra.", "x"), "C")
|
||||||
|
assert_eq(app_glyph("", " terminal"), "T")
|
||||||
|
assert_eq(app_glyph("", ""), "?")
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "an app's icon is its coloured tile plus glyph" {
|
||||||
|
let ops = app_icon(20, 17, 22, "foot", "F")
|
||||||
|
assert_eq(ops.length(), 2)
|
||||||
|
match ops[0] {
|
||||||
|
FillRect(f) => {
|
||||||
|
assert_eq(f.rect.x, 9)
|
||||||
|
assert_eq(f.color.r, tile_color("foot").r)
|
||||||
|
}
|
||||||
|
_ => fail("expected a tile")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user