Dock and task manager are one module: titled window pills, pins, Super+1..9
CI / test (push) Failing after 30s

The panel had a task list and, beside it, a dock showing the same running
apps again. They are now one module, the dock, in the task list's place:

- Pinned apps, then running ones; an app with windows is a pill with its
  window's title (or name and window count) while there is room, an icon
  when the panel is crowded ("Show window titles" in Dock settings).
- Its right-click menu has the task list's window commands (Minimize /
  Restore, Maximize) for a single window, or the app's windows by title.
- It stretches like the task list did; new panels get it instead of
  tasks. A saved panel's "tasks" becomes the dock (one dock, where the
  task list was); pins are the dock's own setting, so they carry over.
- An empty dock shows a "+ Add apps" tile that opens the Applications
  menu, where right-clicking an app offers Open and Pin to dock (adding a
  dock to the panel if there is none).
- Super+1 .. Super+9 open the dock's first nine apps like a click
  (shortcut "dock-apps", rebindable in Settings > Shortcuts).
- "New window" / "Open" only for apps the catalog can start.

The tasks component, lib/panel's pill geometry and the taskbar-widget
world are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hiPCFHRxaJQvwex6ry
This commit is contained in:
Claude committed 2026-11-26 00:08:05 +00:00
1 parent 42aa770452
commit 6253371cb3
28 files changed
+801 -1131

No files matched your search

+222 -57
View File
@@ -36,11 +36,13 @@ pub(all) struct DockConfig {
mut magnify : Bool
/// Show apps that run but aren't pinned.
mut running : Bool
/// Draw apps that have windows as pills with a title, like a task list, when there is room.
mut titles : Bool
}
///|
pub fn DockConfig::new() -> DockConfig {
{ pinned: None, size: "Medium", magnify: true, running: true }
{ pinned: None, size: "Medium", magnify: true, running: true, titles: true }
}
///| A config built from saved key/value pairs (what the shell reads back from the module).
@@ -94,6 +96,7 @@ pub fn DockConfig::items(self : DockConfig) -> Array[ConfigEntry] {
{ key: "icon-size", label: "Icon size", choices: size_choices, value: self.size },
{ key: "magnify", label: "Magnify icons under the pointer", choices: [], value: on_off(self.magnify) },
{ key: "running", label: "Show running apps that aren't pinned", choices: [], value: on_off(self.running) },
{ key: "titles", label: "Show window titles", choices: [], value: on_off(self.titles) },
{
key: "pinned",
label: "",
@@ -131,6 +134,7 @@ pub fn DockConfig::set(self : DockConfig, key : String, value : String) -> Bool
}
"magnify" => flag(self.magnify, b => self.magnify = b)
"running" => flag(self.running, b => self.running = b)
"titles" => flag(self.titles, b => self.titles = b)
"pinned" => {
let p = decode_pins(value)
if p != self.pinned {
@@ -170,6 +174,8 @@ pub(all) struct DockWindow {
id : UInt64
app_id : String
focused : Bool
title : String
minimized : Bool
}
///| One icon in the dock.
@@ -184,6 +190,10 @@ pub(all) struct DockItem {
windows : Array[UInt64]
/// One of its windows has focus.
focused : Bool
/// The title of its newest window ("" without windows).
title : String
/// How many of its windows are minimized.
minimized : Int
}
///| The id among `ids` of the app whose windows carry `app_id`: the same id, the same ignoring
@@ -237,6 +247,29 @@ pub fn match_name(app_id : String, apps : Array[@types.AppEntry]) -> String? {
None
}
///| The dock id of the app whose windows carry `app_id`: a pinned app (`pins`), else a catalog
/// app, by id or by name, else `app_id` itself. None for windows without an app id. The shell
/// uses it to pin a window's app from the task list's menu.
pub fn owner_of(
app_id : String,
pins : Array[String],
apps : Array[@types.AppEntry],
catalog_ids? : Array[String] = apps.map(a => a.id),
) -> String? {
match match_app(app_id, pins) {
Some(id) => Some(id)
None =>
match match_app(app_id, catalog_ids) {
Some(id) => Some(id)
None =>
match match_name(app_id, apps) {
Some(id) => Some(id)
None => if app_id.length() > 0 { Some(app_id) } else { None }
}
}
}
}
///| The dock's icons: the pinned apps in their order, then the other running apps in the order
/// they first opened a window (when `cfg.running`). Windows without an app id aren't shown.
pub fn items(
@@ -256,11 +289,11 @@ pub fn items(
let index : Map[String, Int] = Map([])
let make = fn(id : String, pinned : Bool) -> DockItem {
match by_id.get(id) {
Some(a) => { id, name: a.name, glyph: a.glyph, pinned, windows: [], focused: false }
Some(a) => { id, name: a.name, glyph: a.glyph, pinned, windows: [], focused: false, title: "", minimized: 0 }
None => {
let parts = id.split(".").to_array()
let name = parts[parts.length() - 1].to_string()
{ id, name, glyph: app_glyph(id, id), pinned, windows: [], focused: false }
{ id, name, glyph: app_glyph(id, id), pinned, windows: [], focused: false, title: "", minimized: 0 }
}
}
}
@@ -271,19 +304,7 @@ pub fn items(
}
}
for w in sorted {
let owner = match match_app(w.app_id, pins) {
Some(id) => Some(id)
None =>
match match_app(w.app_id, catalog_ids) {
Some(id) => Some(id)
None =>
match match_name(w.app_id, apps) {
Some(id) => Some(id)
None => if w.app_id.length() > 0 { Some(w.app_id) } else { None }
}
}
}
match owner {
match owner_of(w.app_id, pins, apps, catalog_ids~) {
None => ()
Some(id) => {
let i = match index.get(id) {
@@ -299,8 +320,11 @@ pub fn items(
}
let it = out[i]
it.windows.push(w.id)
if w.focused {
out[i] = { ..it, focused: true }
out[i] = {
..it,
focused: it.focused || w.focused,
title: w.title,
minimized: it.minimized + (if w.minimized { 1 } else { 0 }),
}
}
}
@@ -318,6 +342,10 @@ fn first_running(items : Array[DockItem]) -> Int {
}
// ---------------------------------------------------------------- geometry
//
// Icons sit in a row. With window titles on, an app that has windows gets a pill: its icon and a
// title (its window's, or its name and window count), like the task list's pills. When the row
// doesn't fit the pills shrink, down to `label_min`, then drop their titles.
///| Side padding of the whole dock, and the room between two icons.
let pad : Int = 6
@@ -331,6 +359,12 @@ let divider_w : Int = 11
///| Rows of pixels kept free under the icons for the window dots.
let dots_h : Int = 6
///| Widest and narrowest a titled pill gets (narrower than that: just the icon).
pub let label_max : Int = 150
///|
pub let label_min : Int = 84
///| Icon edge for the chosen size in a dock `h` pixels tall.
pub fn icon_size(cfg : DockConfig, h : Int) -> Int {
let want = match cfg.size {
@@ -347,55 +381,106 @@ pub fn icon_size(cfg : DockConfig, h : Int) -> Int {
}
}
///| Distance between icon centres.
fn pitch(cfg : DockConfig, h : Int) -> Int {
icon_size(cfg, h) + gap
///| Width of every item's slot in a dock `w` wide (`w` < 0: as wide as they like).
fn widths(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int) -> Array[Int] {
let base = icon_size(cfg, h)
let titled = items.map(it => cfg.titles && it.windows.length() > 0)
let n = items.length()
let split = first_running(items)
let fixed = 2 * pad + (if n > 1 { (n - 1) * gap } else { 0 }) +
(if split > 0 && split < n { divider_w } else { 0 })
let mut nt = 0
for t in titled {
if t {
nt = nt + 1
}
}
let icons_w = (n - nt) * base
let lw = if nt == 0 || w < 0 {
label_max
} else {
let fit = (w - fixed - icons_w) / nt
if fit > label_max {
label_max
} else {
fit
}
}
let lw = if lw < label_min { base } else { lw }
titled.map(t => if t { lw } else { base })
}
///| Whether item `i` is drawn as a titled pill in a dock `w` wide (the shell then shows no
/// hover label over it: the pill already says what it is).
pub fn titled_at(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int, i : Int) -> Bool {
widths(items, cfg, w, h)[i] > icon_size(cfg, h)
}
///| Left edge of item `i`'s slot.
fn slot_x(items : Array[DockItem], cfg : DockConfig, h : Int, i : Int) -> Int {
fn slot_x(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int, i : Int) -> Int {
let ws = widths(items, cfg, w, h)
let split = first_running(items)
let extra = if i >= split && split > 0 { divider_w } else { 0 }
pad + i * pitch(cfg, h) + extra
let mut x = pad
for j = 0; j < i; j = j + 1 {
x = x + ws[j] + gap
}
if i >= split && split > 0 {
x = x + divider_w
}
x
}
///| Width that shows every item.
///| Width that shows every item (titles at their widest).
pub fn preferred_width(items : Array[DockItem], cfg : DockConfig, h : Int) -> Int {
let n = items.length()
if n == 0 {
return 80
return empty_width
}
slot_x(items, cfg, h, n - 1) + icon_size(cfg, h) + pad
slot_x(items, cfg, -1, h, n - 1) + widths(items, cfg, -1, h)[n - 1] + pad
}
///| Width of the empty dock: its "+" tile and hint.
let empty_width : Int = 150
///| How many items fit in a dock `w` wide.
fn visible(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int) -> Int {
let ws = widths(items, cfg, w, h)
let mut n = 0
while n < items.length() && slot_x(items, cfg, h, n) + icon_size(cfg, h) + pad <= w {
while n < items.length() && slot_x(items, cfg, w, h, n) + ws[n] + pad <= w {
n = n + 1
}
n
}
///| The item under dock-local (x, y), or -1. The gap after an icon belongs to it, so the pointer
///| The width the row of items takes in a dock `w` wide (its backing is drawn that wide).
fn used_width(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int) -> Int {
let n = visible(items, cfg, w, h)
if n == 0 {
return if items.length() == 0 { empty_width } else { 0 }
}
slot_x(items, cfg, w, h, n - 1) + widths(items, cfg, w, h)[n - 1] + pad
}
///| The item under dock-local (x, y), or -1. The gap after an item belongs to it, so the pointer
/// never drops off the dock between two icons.
pub fn item_at(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int, x : Int, y : Int) -> Int {
if y < 0 || y >= h || x < 0 || x >= w {
return -1
}
let n = visible(items, cfg, w, h)
let ws = widths(items, cfg, w, h)
for i = 0; i < n; i = i + 1 {
let x0 = slot_x(items, cfg, h, i)
if x >= x0 - gap / 2 && x < x0 + pitch(cfg, h) - gap / 2 {
let x0 = slot_x(items, cfg, w, h, i)
if x >= x0 - gap / 2 && x < x0 + ws[i] + gap - gap / 2 {
return i
}
}
-1
}
///| Centre x of item `i`, dock-local (for the shell's hover label and menu).
pub fn item_center(items : Array[DockItem], cfg : DockConfig, h : Int, i : Int) -> Int {
slot_x(items, cfg, h, i) + icon_size(cfg, h) / 2
///| Centre x of item `i` in a dock `w` wide, dock-local (for the shell's hover label and menu).
pub fn item_center(items : Array[DockItem], cfg : DockConfig, w : Int, h : Int, i : Int) -> Int {
slot_x(items, cfg, w, h, i) + widths(items, cfg, w, h)[i] / 2
}
///| Edge of item `i`'s icon with `hover` the item under the pointer (-1: none): the hovered icon
@@ -484,6 +569,26 @@ pub fn app_icon(
// ---------------------------------------------------------------- drawing
///| What the empty dock shows: a "+" tile and a hint. A click on it opens the Applications menu
/// (the shell does that: modules can't open each other), whose right-click menu pins apps.
fn render_empty(t : @theme.Tokens, cfg : DockConfig, h : Int, hot : Bool) -> Array[@types.DrawOp] {
let s = icon_size(cfg, h)
let x = pad
let y = (h - s) / 2
let fg = if hot { t.palette.foreground } else { t.palette.foreground_muted }
let r = t.radius.reinterpret_as_int()
let cx = x + s / 2
let cy = y + s / 2
let arm = s / 4
[
@ui.fill_rect(@ui.rect(x, y, s, s), @ui.with_alpha(t.palette.foreground, if hot { 40 } else { 18 }), radius=r),
@ui.stroke_rect(@ui.rect(x, y, s, s), fg, radius=r),
@ui.line(cx - arm, cy, cx + arm, cy, fg, width=2),
@ui.line(cx, cy - arm, cx, cy + arm, fg, width=2),
@ui.text(x + s + 8, h / 2, "Add apps", t.font_size.reinterpret_as_int() - 2, fg),
]
}
///| Draw the dock into `size`. `hover` is the item under the pointer or -1; `icon` gives an app
/// id's theme icon handle (0: none, a letter tile is drawn).
pub fn render(
@@ -497,33 +602,60 @@ pub fn render(
let w = size.w.reinterpret_as_int()
let h = size.h.reinterpret_as_int()
let r = t.radius.reinterpret_as_int()
// The backing hugs the items, so the rest of the panel stays clear when the dock stretches.
let bw = used_width(items, cfg, w, h)
let ops : Array[@types.DrawOp] = [
@ui.fill_rect(@ui.rect(0, 0, w, h), @ui.with_alpha(t.palette.surface_hover, 150), radius=r + 4),
@ui.fill_rect(@ui.rect(0, 0, if bw < w { bw } else { w }, h), @ui.with_alpha(t.palette.surface_hover, 150), radius=r + 4),
]
if items.length() == 0 {
ops.push(
@ui.text(w / 2, h / 2, "No apps", t.font_size.reinterpret_as_int() - 2, t.palette.foreground_muted, align=CENTER),
)
ops.append(render_empty(t, cfg, h, hover >= 0))
return ops
}
let n = visible(items, cfg, w, h)
let ws = widths(items, cfg, w, h)
let base = icon_size(cfg, h)
let cy = (h - dots_h) / 2 + 2
let fs = t.font_size.reinterpret_as_int() - 3
let split = first_running(items)
if split > 0 && split < n {
let x = slot_x(items, cfg, h, split) - gap / 2 - divider_w / 2 - 1
let x = slot_x(items, cfg, w, h, split) - gap / 2 - divider_w / 2 - 1
ops.push(@ui.fill_rect(@ui.rect(x, 6, 1, h - 12), t.palette.border))
}
for i = 0; i < n; i = i + 1 {
let it = items[i]
let s = item_size(cfg, i, hover, h)
let cx = slot_x(items, cfg, h, i) + base / 2
// Grow upwards from the icons' common baseline so the row doesn't wobble.
let icy = cy + base / 2 - s / 2
if i == hover {
ops.push(
@ui.fill_rect(@ui.rect(cx - s / 2 - 3, icy - s / 2 - 3, s + 6, s + 6), @ui.with_alpha(t.palette.foreground, 36), radius=r),
)
let x0 = slot_x(items, cfg, w, h, i)
let titled = ws[i] > base
let all_min = it.windows.length() > 0 && it.minimized == it.windows.length()
let mut cx = x0 + base / 2
let mut icy = cy
let mut s = base
if titled {
// A pill like the task list's: lit when the app has focus, dim when all its windows are
// minimized. The icon doesn't grow in a pill.
let bg = if it.focused {
@ui.with_alpha(t.palette.accent, 90)
} else if i == hover {
@ui.with_alpha(t.palette.foreground, 36)
} else {
@ui.with_alpha(t.palette.foreground, 14)
}
ops.push(@ui.fill_rect(@ui.rect(x0, 3, ws[i], h - 6), bg, radius=r))
cx = x0 + 6 + base / 2
icy = h / 2
let s2 = h - 14
s = if s2 < base { s2 } else { base }
let tx = cx + s / 2 + 6
let col = if all_min { t.palette.foreground_muted } else { t.palette.foreground }
ops.push(@ui.text(tx, h / 2, fit_text(item_title(it), fs, x0 + ws[i] - 6 - tx), fs, col))
} else {
s = item_size(cfg, i, hover, h)
// Grow upwards from the icons' common baseline so the row doesn't wobble.
icy = cy + base / 2 - s / 2
if i == hover {
ops.push(
@ui.fill_rect(@ui.rect(cx - s / 2 - 3, icy - s / 2 - 3, s + 6, s + 6), @ui.with_alpha(t.palette.foreground, 36), radius=r),
)
}
}
let handle = icon(it.id)
if handle != 0U {
@@ -531,7 +663,7 @@ pub fn render(
} else {
ops.append(app_icon(cx, icy, s, it.id, it.glyph, hover=i == hover))
}
// One dot per window, up to three; lit when the app has focus.
// One dot per window, up to three, under the icon; lit when the app has focus.
let dots = if it.windows.length() > 3 { 3 } else { it.windows.length() }
let col = if it.focused { t.palette.accent } else { t.palette.foreground_muted }
let dw = if it.focused && dots == 1 { 10 } else { 4 }
@@ -544,6 +676,30 @@ pub fn render(
ops
}
///| The title on an app's pill: its one window's title, else its name and how many windows.
pub fn item_title(it : DockItem) -> String {
if it.windows.length() == 1 && it.title.length() > 0 {
it.title
} else if it.windows.length() > 1 {
it.name + " (" + it.windows.length().to_string() + ")"
} else {
it.name
}
}
///| `s` shortened with an ellipsis until it fits `max_w` pixels (at about 0.55em a character).
fn fit_text(s : String, size : Int, max_w : Int) -> String {
let cw = (size * 11 + 19) / 20
if s.length() * cw <= max_w {
return s
}
let mut n = s.length()
while n > 1 && (n + 1) * cw > max_w {
n = n - 1
}
s[:n].to_string() + "…"
}
// ---------------------------------------------------------------- input
///| What a pointer event asks the host to do.
@@ -582,6 +738,19 @@ pub fn click_target(it : DockItem, focused_window : UInt64?) -> UInt64? {
}
}
///| What clicking `it` (or its Super+number shortcut) does: start it when it has no windows,
/// else bring its newest window forward, or step to its next one when it already has focus.
pub fn activate(it : DockItem, focused_window : UInt64?) -> DockAction {
if it.windows.length() == 0 {
Launch(it.id)
} else {
match click_target(it, focused_window) {
Some(win) => Focus(win)
None => Nothing
}
}
}
///| Pointer events -> (new hover, redraw?, action). Pure so it can be tested. `focused_window`
/// is the window with keyboard focus, if any.
pub fn handle(
@@ -595,7 +764,8 @@ pub fn handle(
) -> (Int, Bool, DockAction) {
match event {
PointerMove(p) => {
let i = item_at(items, cfg, w, h, p.x, p.y)
// The empty dock is one target, its "+" tile (hover 0).
let i = if items.length() == 0 { 0 } else { item_at(items, cfg, w, h, p.x, p.y) }
(i, i != hover, Nothing)
}
PointerLeave => (-1, hover != -1, Nothing)
@@ -604,14 +774,9 @@ pub fn handle(
if i < 0 {
return (hover, false, Nothing)
}
let it = items[i]
if it.windows.length() == 0 {
(i, true, Launch(it.id))
} else {
match click_target(it, focused_window) {
Some(win) => (i, true, Focus(win))
None => (i, false, Nothing)
}
match activate(items[i], focused_window) {
Nothing => (i, false, Nothing)
a => (i, true, a)
}
}
_ => (hover, false, Nothing)
+69 -14
View File
@@ -10,8 +10,8 @@ fn apps() -> Array[@types.AppEntry] {
}
///|
fn win(id : Int, app : String, focused? : Bool = false) -> DockWindow {
{ id: id.to_uint64(), app_id: app, focused }
fn win(id : Int, app : String, focused? : Bool = false, minimized? : Bool = false) -> DockWindow {
{ id: id.to_uint64(), app_id: app, focused, title: app + " window", minimized }
}
///|
@@ -41,10 +41,10 @@ fn tokens() -> @theme.Tokens {
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_eq(c.items()[4].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" })
assert_eq(c.items()[4], { 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()), [])
@@ -102,7 +102,7 @@ test "pinned apps come first in their order, then running ones, with their windo
///|
test "items are hit-tested by slot, with a divider before the running apps" {
let c = DockConfig::from_pairs([("pinned", "foot;firefox")])
let c = DockConfig::from_pairs([("pinned", "foot;firefox"), ("titles", "off")])
let its = items(c, apps(), [win(1, "vlc")])
let h = 36
let w = preferred_width(its, c, h)
@@ -110,12 +110,12 @@ test "items are hit-tested by slot, with a divider before the running apps" {
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_center(its, c, w, h, 2) - item_center(its, c, w, h, 1), p + 11)
assert_eq(item_at(its, c, w, h, item_center(its, c, w, 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)
assert_eq(item_at(its, c, w - 10, h, item_center(its, c, w, 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))
@@ -127,12 +127,12 @@ test "items are hit-tested by slot, with a divider before the running apps" {
///|
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 c = DockConfig::from_pairs([("pinned", "foot;firefox"), ("titles", "off")])
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 x0 = item_center(its, c, w, h, 0)
let x1 = item_center(its, c, w, 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)
@@ -150,7 +150,7 @@ test "a click starts an app that isn't running and walks through a running app's
///|
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 c = DockConfig::from_pairs([("pinned", "foot;firefox"), ("titles", "off")])
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)
@@ -161,9 +161,38 @@ test "render draws each icon (theme image or letter tile), a dot per window and
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.
// Nothing to show: a "+" tile (fill, outline, two strokes) and its hint, after the background.
let none = DockConfig::from_pairs([("pinned", ";")])
assert_eq(render(@ui.size(80, h), tokens(), none, [], -1, _ => 0U).length(), 2)
let empty = render(@ui.size(preferred_width([], none, h), h), tokens(), none, [], -1, _ => 0U)
assert_eq(empty.length(), 6)
assert_true(empty.iter().any(op => op is Text(t) && t.text == "Add apps"))
}
///|
test "the empty dock is one target: hovering it lights the + tile, a click is the shell's" {
let none = DockConfig::from_pairs([("pinned", ";")])
let (hv, redraw, act) = handle([], none, -1, 150, 36, None, PointerMove({ x: 10, y: 10 }))
assert_eq((hv, redraw, act), (0, true, Nothing))
let (_, _, act) = handle([], none, 0, 150, 36, None, PointerDown({ x: 10, y: 10 }))
assert_eq(act, Nothing)
}
///|
test "a window's app: a pin, a catalog app, or its own id" {
let a = apps()
assert_eq(owner_of("org.mozilla.firefox", [], a), Some("firefox"))
assert_eq(owner_of("vlc", ["vlc"], a), Some("vlc"))
assert_eq(owner_of("org.example.Notes", [], a), Some("org.example.Notes"))
assert_eq(owner_of("", [], a), None)
}
///|
test "activate starts an app without windows and brings one forward otherwise" {
let c = DockConfig::from_pairs([("pinned", "foot;firefox")])
let its = items(c, apps(), [win(3, "foot", focused=true), win(4, "foot")])
assert_eq(activate(its[1], Some(3UL)), Launch("firefox"))
assert_eq(activate(its[0], None), Focus(4UL))
assert_eq(activate(its[0], Some(3UL)), Focus(4UL))
}
///|
@@ -196,3 +225,29 @@ test "an app's icon is its coloured tile plus glyph" {
_ => fail("expected a tile")
}
}
///|
test "apps with windows are titled pills that shrink, then drop their titles, as room runs out" {
let c = DockConfig::from_pairs([("pinned", "foot;firefox")])
let its = items(c, apps(), [win(3, "foot"), win(4, "vlc", minimized=true), win(5, "vlc")])
let h = 36
let base = icon_size(c, h)
// Room for all: foot and vlc get full pills, firefox (no windows) stays an icon.
assert_eq(widths(its, c, 1000, h), [label_max, base, label_max])
assert_eq(item_title(its[0]), "foot window")
assert_eq(item_title(its[2]), "vlc! (2)")
assert_eq(its[2].minimized, 1)
// Less room: the pills share what's left...
let ws = widths(its, c, 300, h)
assert_true(ws[0] < label_max && ws[0] >= label_min && ws[0] == ws[2])
assert_true(slot_x(its, c, 300, h, 2) + ws[2] + 6 <= 300)
// ...and below label_min they are icons again.
assert_eq(widths(its, c, 150, h), [base, base, base])
// A click anywhere on a pill is that app.
assert_eq(item_at(its, c, 1000, h, 6 + label_max - 10, 10), 0)
let ops = render(@ui.size(1000, h), tokens(), c, its, -1, _ => 0U)
assert_true(ops.iter().any(op => op is Text(t) && t.text == "foot window"))
// Off: icons only.
assert_true(c.set("titles", "off"))
assert_eq(widths(its, c, 1000, h), [base, base, base])
}
+18 -1
View File
@@ -8,6 +8,8 @@ import {
}
// Values
pub fn activate(DockItem, UInt64?) -> DockAction
pub fn app_glyph(String, String) -> String
pub fn app_icon(Int32, Int32, Int32, String, String, hover? : Bool) -> Array[@types.DrawOp]
@@ -28,16 +30,26 @@ pub fn icon_size(DockConfig, Int32) -> Int32
pub fn item_at(Array[DockItem], DockConfig, Int32, Int32, Int32, Int32) -> Int32
pub fn item_center(Array[DockItem], DockConfig, Int32, Int32) -> Int32
pub fn item_center(Array[DockItem], DockConfig, Int32, Int32, Int32) -> Int32
pub fn item_size(DockConfig, Int32, Int32, Int32) -> Int32
pub fn item_title(DockItem) -> String
pub fn items(DockConfig, Array[@types.AppEntry], Array[DockWindow]) -> Array[DockItem]
pub let label_max : Int32
pub let label_min : Int32
pub fn match_app(String, Array[String]) -> String?
pub fn match_name(String, Array[@types.AppEntry]) -> String?
pub fn move_pin(Array[String], String, Int32) -> Array[String]
pub fn owner_of(String, Array[String], Array[@types.AppEntry], catalog_ids? : Array[String]) -> String?
pub fn preferred_width(Array[DockItem], DockConfig, Int32) -> Int32
pub fn render(@types.Size, @theme.Tokens, DockConfig, Array[DockItem], Int32, (String) -> UInt32) -> Array[@types.DrawOp]
@@ -71,6 +83,7 @@ pub(all) struct DockConfig {
mut size : String
mut magnify : Bool
mut running : Bool
mut titles : Bool
}
pub fn DockConfig::from_pairs(Array[(String, String)]) -> Self
pub fn DockConfig::items(Self) -> Array[ConfigEntry]
@@ -86,12 +99,16 @@ pub(all) struct DockItem {
pinned : Bool
windows : Array[UInt64]
focused : Bool
title : String
minimized : Int32
}
pub(all) struct DockWindow {
id : UInt64
app_id : String
focused : Bool
title : String
minimized : Bool
}
// Type aliases