///| fn apps() -> Array[@types.AppEntry] { ["foot", "firefox", "org.gnome.Nautilus", "gimp", "org.kde.kate", "vlc"].map(id => { id, name: id + "!", comment: "", category: "", glyph: id.to_upper(), }) } ///| fn win(id : Int, app : String, focused? : Bool = false) -> DockWindow { { id: id.to_uint64(), app_id: app, focused } } ///| fn tokens() -> @theme.Tokens { { name: "t", palette: { desktop_top: @ui.color(0, 0, 0, 255), desktop_bottom: @ui.color(0, 0, 0, 255), surface: @ui.color(30, 30, 30, 255), surface_hover: @ui.color(40, 40, 40, 255), surface_popup: @ui.color(30, 30, 30, 255), foreground: @ui.color(255, 255, 255, 255), foreground_muted: @ui.color(150, 150, 150, 255), accent: @ui.color(60, 120, 220, 255), accent_foreground: @ui.color(255, 255, 255, 255), border: @ui.color(60, 60, 60, 255), }, font_size: 14U, radius: 6U, spacing: 6U, panel_height: 44U, } } ///| 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"]) } ///| 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") } }