Dock: pinned and running apps with real icons, window dots, hover names and a per-app menu
CI / test (push) Failing after 17s
CI / test (push) Failing after 17s
The dock showed the first eight catalog apps as letter tiles, and that list reshuffled after every launch (the catalog puts recent apps first). Now: - Pinned apps first, in the order you set, then the other running apps after a thin divider (like macOS). Windows find their app by desktop id, case, the last dotted part, or the app's name (xterm -> debian-xterm.desktop "XTerm"); windows without an app id stay out. - Real icons from the icon theme (the `icons` capability, as in the task manager), with the letter tile as fallback. The shell publishes icons for pinned apps that aren't running too. - A dot under an icon per open window (up to three), a longer accent bar when the app has focus. - Click: start the app if it isn't running, otherwise bring its newest window forward (restoring it if minimized); click a focused app again to step through its windows. - Hover: the icon grows (neighbours a little) on a light highlight, and the shell draws the app's name in a label above it. - Right-click an icon (drawn by the shell, like the task manager's window menu): Open / New window, Pin to dock / Unpin from dock, Move left / Move right, Quit or Close N windows, and Dock settings. - Dock settings (module-config): Icon size (Small/Medium/Large), Magnify icons under the pointer, Show running apps that aren't pinned. The pinned list is a hidden setting (empty label: the shell's settings menu skips it), saved in state.edn's :module-config. Until it is set the dock pins the catalog's first five, and the shell saves that once so launches don't move them. - The panel sizes the dock from its current items (a module's preferred width is read once). Plumbing: new WIT world dock-widget (app-catalog, app-launch, windows, icons, exports module-config); no new interfaces, so both hosts load it as is. lib/dock holds the items, layout, hit-testing, drawing and pin edits, shared by the module and compositor/shell/dock.mbt. The shell's Launch handling moved into launch_catalog_app so the menu can use it. Also: DesktopShell::pointer_move delivered every hover move twice (a duplicated block). Tests: lib/dock (settings round trip, app matching, item order, hit-testing with the divider, clicks and window cycling, drawing, pin edits), compositor/host input_test (the dock in a real compositor: saved default pins, growing for running apps, hover label, the menu's rows and actions, settings menu without the pinned row, focusing by click), dock_test (screenshots in _build/dock_hover.png and dock_menu.png). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hkmB8pJF5ckPeecFxL
This commit is contained in:
29 files changed
+1497
-176
No files matched your search
+149
-30
@@ -1,36 +1,22 @@
|
||||
///|
|
||||
fn apps() -> Array[@types.AppEntry] {
|
||||
["a", "b", "c"].map(id => { id, name: id + "!", comment: "", category: "", glyph: id.to_upper() })
|
||||
["foot", "firefox", "org.gnome.Nautilus", "gimp", "org.kde.kate", "vlc"].map(id => {
|
||||
id,
|
||||
name: id + "!",
|
||||
comment: "",
|
||||
category: "",
|
||||
glyph: id.to_upper(),
|
||||
})
|
||||
}
|
||||
|
||||
///|
|
||||
test "tiles hit-test by slot and grow around the hovered one" {
|
||||
let h = 34
|
||||
assert_eq(tile_at(3, h, 0, 10), -1)
|
||||
assert_eq(tile_at(3, h, 12, 10), 0)
|
||||
assert_eq(tile_at(3, h, 12 + pitch(h), 10), 1)
|
||||
assert_eq(tile_at(3, h, 12 + 5 * pitch(h), 10), -1)
|
||||
assert_true(tile_size(1, 1, h) > tile_size(0, 1, h))
|
||||
assert_eq(tile_size(2, 0, h), base_size(h))
|
||||
fn win(id : Int, app : String, focused? : Bool = false) -> DockWindow {
|
||||
{ id: id.to_uint64(), app_id: app, focused }
|
||||
}
|
||||
|
||||
///|
|
||||
test "click launches the app under the pointer; move sets hover" {
|
||||
let a = apps()
|
||||
let (hv, redraw, launch) = handle(a, -1, 34, PointerMove({ x: 12, y: 10 }))
|
||||
assert_eq(hv, 0)
|
||||
assert_true(redraw)
|
||||
assert_true(launch is None)
|
||||
let (_, _, launch) = handle(a, hv, 34, PointerDown({ x: 12 + pitch(34), y: 10 }))
|
||||
assert_eq(launch, Some("b"))
|
||||
let (hv, redraw, _) = handle(a, 0, 34, PointerLeave)
|
||||
assert_eq(hv, -1)
|
||||
assert_true(redraw)
|
||||
}
|
||||
|
||||
///|
|
||||
test "render draws one tile and glyph per app, capped at max_tiles" {
|
||||
let t : @theme.Tokens = {
|
||||
fn tokens() -> @theme.Tokens {
|
||||
{
|
||||
name: "t",
|
||||
palette: {
|
||||
desktop_top: @ui.color(0, 0, 0, 255),
|
||||
@@ -49,11 +35,144 @@ test "render draws one tile and glyph per app, capped at max_tiles" {
|
||||
spacing: 6U,
|
||||
panel_height: 44U,
|
||||
}
|
||||
assert_eq(render(@ui.size(preferred_width(3), 34), t, apps(), -1).length(), 1 + 3 * 2)
|
||||
let many = Array::makei(20, i => ({ id: i.to_string(), name: "n", comment: "", category: "", glyph: "x" } : @types.AppEntry))
|
||||
assert_eq(render(@ui.size(300, 34), t, many, 2).length(), 1 + max_tiles * 2)
|
||||
assert_eq(tile_name(apps(), 1), "b!")
|
||||
assert_eq(tile_name(apps(), 9), "")
|
||||
}
|
||||
|
||||
///|
|
||||
test "without a choice the dock pins the catalog's first apps; the choice round-trips" {
|
||||
let c = DockConfig::new()
|
||||
assert_eq(c.pins(apps()), ["foot", "firefox", "org.gnome.Nautilus", "gimp", "org.kde.kate"])
|
||||
assert_eq(c.items()[3].value, "")
|
||||
assert_true(c.set("pinned", "vlc;foot"))
|
||||
assert_eq(c.pins(apps()), ["vlc", "foot"])
|
||||
assert_eq(c.items()[3], { key: "pinned", label: "", choices: [], value: "vlc;foot" })
|
||||
// Unpinning everything is a choice too, not "back to the defaults".
|
||||
assert_true(c.set("pinned", encode_pins([])))
|
||||
assert_eq(c.pins(apps()), [])
|
||||
assert_eq(decode_pins(""), None)
|
||||
assert_eq(decode_pins("a;;b;a"), Some(["a", "b"]))
|
||||
// The other settings.
|
||||
assert_false(c.set("icon-size", "Huge"))
|
||||
assert_true(c.set("icon-size", "Large"))
|
||||
assert_true(c.set("magnify", "off"))
|
||||
assert_false(c.set("magnify", "off"))
|
||||
let d = DockConfig::from_pairs([("icon-size", "Small"), ("running", "off")])
|
||||
assert_eq(d.size, "Small")
|
||||
assert_false(d.running)
|
||||
}
|
||||
|
||||
///|
|
||||
test "windows find their app by id, case, or the last dotted part" {
|
||||
let ids = ["foot", "org.gnome.Nautilus", "firefox"]
|
||||
assert_eq(match_app("foot", ids), Some("foot"))
|
||||
assert_eq(match_app("FOOT", ids), Some("foot"))
|
||||
assert_eq(match_app("nautilus", ids), Some("org.gnome.Nautilus"))
|
||||
assert_eq(match_app("org.mozilla.firefox", ids), Some("firefox"))
|
||||
assert_eq(match_app("gimp", ids), None)
|
||||
assert_eq(match_app("", ids), None)
|
||||
// By the app's name: xterm's windows belong to debian-xterm.desktop ("XTerm").
|
||||
let xterm : Array[@types.AppEntry] = [{ id: "debian-xterm", name: "XTerm", comment: "", category: "", glyph: "X" }]
|
||||
assert_eq(match_name("xterm", xterm), Some("debian-xterm"))
|
||||
assert_eq(match_name("vim", xterm), None)
|
||||
assert_eq(items(DockConfig::new(), xterm, [win(1, "xterm")]).map(i => i.windows.length()), [1])
|
||||
}
|
||||
|
||||
///|
|
||||
test "pinned apps come first in their order, then running ones, with their windows" {
|
||||
let c = DockConfig::from_pairs([("pinned", "firefox;foot")])
|
||||
let its = items(c, apps(), [
|
||||
win(7, "foot", focused=true),
|
||||
win(3, "foot"),
|
||||
win(5, "vlc"),
|
||||
win(9, "unknown.app"),
|
||||
win(2, ""),
|
||||
])
|
||||
assert_eq(its.map(i => i.id), ["firefox", "foot", "vlc", "unknown.app"])
|
||||
assert_eq(its.map(i => i.pinned), [true, true, false, false])
|
||||
assert_eq(its[1].windows, [3UL, 7UL]) // oldest first
|
||||
assert_true(its[1].focused)
|
||||
assert_false(its[0].focused)
|
||||
assert_eq(its[0].windows.length(), 0)
|
||||
// Not in the catalog: named after the id's last part, with a letter for its tile.
|
||||
assert_eq(its[3].name, "app")
|
||||
assert_eq(its[3].glyph, "A")
|
||||
// Running apps can be hidden.
|
||||
assert_true(c.set("running", "off"))
|
||||
assert_eq(items(c, apps(), [win(5, "vlc"), win(7, "foot")]).map(i => i.id), ["firefox", "foot"])
|
||||
}
|
||||
|
||||
///|
|
||||
test "items are hit-tested by slot, with a divider before the running apps" {
|
||||
let c = DockConfig::from_pairs([("pinned", "foot;firefox")])
|
||||
let its = items(c, apps(), [win(1, "vlc")])
|
||||
let h = 36
|
||||
let w = preferred_width(its, c, h)
|
||||
let p = icon_size(c, h) + 6
|
||||
assert_eq(item_at(its, c, w, h, 6, 10), 0)
|
||||
assert_eq(item_at(its, c, w, h, 6 + p, 10), 1)
|
||||
// The divider shifts the running app right.
|
||||
assert_eq(item_center(its, c, h, 2) - item_center(its, c, h, 1), p + 11)
|
||||
assert_eq(item_at(its, c, w, h, item_center(its, c, h, 2), 10), 2)
|
||||
assert_eq(item_at(its, c, w, h, w + 5, 10), -1)
|
||||
assert_eq(item_at(its, c, w, h, 6, -1), -1)
|
||||
// Too narrow for all of them: the ones that don't fit can't be hit.
|
||||
assert_eq(item_at(its, c, w - 10, h, item_center(its, c, h, 2), 10), -1)
|
||||
// Bigger icons, wider dock; magnification grows the hovered one most.
|
||||
let big = DockConfig::from_pairs([("pinned", "foot;firefox"), ("icon-size", "Large")])
|
||||
assert_true(preferred_width(items(big, apps(), []), big, 44) > preferred_width(items(c, apps(), []), c, 44))
|
||||
assert_true(item_size(c, 1, 1, h) > item_size(c, 0, 1, h))
|
||||
assert_true(item_size(c, 0, 1, h) > item_size(c, 3, 1, h))
|
||||
assert_true(c.set("magnify", "off"))
|
||||
assert_eq(item_size(c, 1, 1, h), icon_size(c, h))
|
||||
}
|
||||
|
||||
///|
|
||||
test "a click starts an app that isn't running and walks through a running app's windows" {
|
||||
let c = DockConfig::from_pairs([("pinned", "foot;firefox")])
|
||||
let its = items(c, apps(), [win(3, "foot"), win(8, "foot")])
|
||||
let h = 36
|
||||
let w = preferred_width(its, c, h)
|
||||
let x0 = item_center(its, c, h, 0)
|
||||
let x1 = item_center(its, c, h, 1)
|
||||
let (hv, redraw, act) = handle(its, c, -1, w, h, None, PointerMove({ x: x1, y: 10 }))
|
||||
assert_eq((hv, redraw, act), (1, true, Nothing))
|
||||
assert_eq(handle(its, c, 1, w, h, None, PointerMove({ x: x1, y: 10 })).1, false)
|
||||
assert_eq(handle(its, c, 1, w, h, None, PointerDown({ x: x1, y: 10 })).2, Launch("firefox"))
|
||||
// Not focused: its newest window comes forward.
|
||||
assert_eq(handle(its, c, 0, w, h, Some(99UL), PointerDown({ x: x0, y: 10 })).2, Focus(8UL))
|
||||
// Focused: the next of its windows, round and round.
|
||||
let its = items(c, apps(), [win(3, "foot"), win(8, "foot", focused=true)])
|
||||
assert_eq(handle(its, c, 0, w, h, Some(8UL), PointerDown({ x: x0, y: 10 })).2, Focus(3UL))
|
||||
let its = items(c, apps(), [win(3, "foot", focused=true)])
|
||||
assert_eq(handle(its, c, 0, w, h, Some(3UL), PointerDown({ x: x0, y: 10 })).2, Nothing)
|
||||
let (hv, redraw, _) = handle(its, c, 0, w, h, None, PointerLeave)
|
||||
assert_eq((hv, redraw), (-1, true))
|
||||
}
|
||||
|
||||
///|
|
||||
test "render draws each icon (theme image or letter tile), a dot per window and the divider" {
|
||||
let c = DockConfig::from_pairs([("pinned", "foot;firefox")])
|
||||
let its = items(c, apps(), [win(3, "foot", focused=true), win(4, "vlc"), win(5, "vlc")])
|
||||
let h = 36
|
||||
let w = preferred_width(its, c, h)
|
||||
let ops = render(@ui.size(w, h), tokens(), c, its, -1, id => if id == "firefox" { 42U } else { 0U })
|
||||
let images = ops.filter(op => op is Image(_))
|
||||
assert_eq(images.length(), 1)
|
||||
let texts = ops.filter(op => op is Text(_))
|
||||
assert_eq(texts.length(), 2) // foot's and vlc's letter tiles
|
||||
// background + divider + foot (tile, glyph, 1 dot) + firefox (image) + vlc (tile, glyph, 2 dots)
|
||||
assert_eq(ops.length(), 1 + 1 + 3 + 1 + 4)
|
||||
// Nothing to show.
|
||||
let none = DockConfig::from_pairs([("pinned", ";")])
|
||||
assert_eq(render(@ui.size(80, h), tokens(), none, [], -1, _ => 0U).length(), 2)
|
||||
}
|
||||
|
||||
///|
|
||||
test "pins are toggled and moved within bounds" {
|
||||
assert_eq(toggle_pin(["a", "b"], "b"), ["a"])
|
||||
assert_eq(toggle_pin(["a"], "c"), ["a", "c"])
|
||||
assert_eq(move_pin(["a", "b", "c"], "b", -1), ["b", "a", "c"])
|
||||
assert_eq(move_pin(["a", "b", "c"], "c", 1), ["a", "b", "c"])
|
||||
assert_eq(move_pin(["a", "b", "c"], "x", 1), ["a", "b", "c"])
|
||||
}
|
||||
|
||||
///|
|
||||
|
||||
Reference in new issue
Block a user