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
221 lines
7.2 KiB
MoonBit
221 lines
7.2 KiB
MoonBit
///| The shell's half of the dock (components/dock, logic in lib/dock). The module draws the icons
|
|
/// and handles clicks; the shell, which sees right-clicks and can draw outside the panel, adds:
|
|
/// - the per-app right-click menu: Open / New window, Pin to dock / Unpin, Move left / right,
|
|
/// Quit (every window of the app) and Dock settings;
|
|
/// - the app's name in a label above the icon under the pointer;
|
|
/// - the dock's width as its apps come and go (a module's preferred width is read once);
|
|
/// - the icons of pinned apps that aren't running (the icons table otherwise has windows' apps);
|
|
/// - the first pinned list: until one is saved the dock pins the catalog's first apps, and the
|
|
/// shell saves that choice once so later launches (which reorder the catalog) don't move them.
|
|
/// The pinned list is the dock's hidden `pinned` setting, kept in state.edn's :module-config
|
|
/// like any module setting. Both sides call lib/dock's `items` / `item_at`, so they agree on
|
|
/// which app is where.
|
|
|
|
///| The dock module's id.
|
|
let dock_module_id : String = "org.chandra.dock"
|
|
|
|
///|
|
|
fn Widget::is_dock(self : Widget) -> Bool {
|
|
self.pl.id == dock_module_id
|
|
}
|
|
|
|
///| The dock's settings as the module holds them now.
|
|
fn dock_config(w : Widget) -> @dock.DockConfig {
|
|
@dock.DockConfig::from_pairs(w.pl.config_items().map(it => (it.key, it.value)))
|
|
}
|
|
|
|
///| The windows as the dock sees them.
|
|
fn DesktopShell::dock_windows(self : DesktopShell) -> Array[@dock.DockWindow] {
|
|
self.win_list.map(e => { id: e.id, app_id: e.app_id, focused: e.focused })
|
|
}
|
|
|
|
///| The dock in `w`'s settings and icons, as the module computes them.
|
|
fn DesktopShell::dock_state(self : DesktopShell, w : Widget) -> (@dock.DockConfig, Array[@dock.DockItem]) {
|
|
let cfg = dock_config(w)
|
|
(cfg, @dock.items(cfg, self.apps, self.dock_windows()))
|
|
}
|
|
|
|
///| Height the dock is drawn at (before its first layout, the height it asked for).
|
|
fn dock_height(w : Widget) -> Int {
|
|
if w.rect.h > 0 {
|
|
w.rect.h
|
|
} else {
|
|
w.pl.pref_h
|
|
}
|
|
}
|
|
|
|
///| The width the dock in `w` needs for its icons now, or None when `w` isn't the dock.
|
|
fn DesktopShell::dock_width(self : DesktopShell, w : Widget) -> Int? {
|
|
if !w.is_dock() {
|
|
return None
|
|
}
|
|
let (cfg, items) = self.dock_state(w)
|
|
Some(@dock.preferred_width(items, cfg, dock_height(w)))
|
|
}
|
|
|
|
///| The dock's icons and the index of the one under (x, y), when `w` is the dock and one is.
|
|
fn DesktopShell::dock_item_at(
|
|
self : DesktopShell,
|
|
w : Widget,
|
|
x : Int,
|
|
y : Int,
|
|
) -> (Array[@dock.DockItem], Int)? {
|
|
if !w.is_dock() || !inside(w.rect, x, y) {
|
|
return None
|
|
}
|
|
let (cfg, items) = self.dock_state(w)
|
|
let i = @dock.item_at(items, cfg, w.rect.w, w.rect.h, x - w.rect.x, y - w.rect.y)
|
|
if i >= 0 {
|
|
Some((items, i))
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
///| App ids of every dock's icons (for the icons table).
|
|
fn DesktopShell::dock_app_ids(self : DesktopShell) -> Array[String] {
|
|
let out : Array[String] = []
|
|
for w in self.widgets {
|
|
if w.is_dock() {
|
|
let (_, items) = self.dock_state(w)
|
|
for it in items {
|
|
out.push(it.id)
|
|
}
|
|
}
|
|
}
|
|
out
|
|
}
|
|
|
|
///| Save the dock's first pinned list the first time it is seen without one (see the top).
|
|
fn DesktopShell::settle_dock_pins(self : DesktopShell) -> Unit {
|
|
if self.apps.length() == 0 {
|
|
return
|
|
}
|
|
for w in self.widgets.copy() {
|
|
if w.is_dock() {
|
|
let cfg = dock_config(w)
|
|
if cfg.pinned is None {
|
|
self.set_module_setting(w.slot, "pinned", @dock.encode_pins(cfg.pins(self.apps)))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
///| A dock menu row: `kind` 7 starts the app, 8 pins or unpins it, 9 moves its pin by `value`
|
|
/// places, 10 closes its windows. `arg` is the app id.
|
|
fn dock_row(label : String, kind : Int, id : String, value? : String = "") -> MenuRow {
|
|
{ ..menu_row(label, kind, arg=id), value, }
|
|
}
|
|
|
|
///| The right-click menu of dock icon `i`, titled with the app's name.
|
|
fn DesktopShell::open_dock_menu(
|
|
self : DesktopShell,
|
|
w : Widget,
|
|
items : Array[@dock.DockItem],
|
|
i : Int,
|
|
x : Int,
|
|
) -> Unit {
|
|
let it = items[i]
|
|
let rows : Array[MenuRow] = []
|
|
let n = it.windows.length()
|
|
rows.push(dock_row(if n == 0 { "Open" } else { "New window" }, 7, it.id))
|
|
if it.pinned {
|
|
rows.push(dock_row("Unpin from dock", 8, it.id))
|
|
let pinned = items.filter(x => x.pinned).length()
|
|
if i > 0 {
|
|
rows.push(dock_row("Move left", 9, it.id, value="-1"))
|
|
}
|
|
if i < pinned - 1 {
|
|
rows.push(dock_row("Move right", 9, it.id, value="1"))
|
|
}
|
|
} else {
|
|
rows.push(dock_row("Pin to dock", 8, it.id))
|
|
}
|
|
if n == 1 {
|
|
rows.push(dock_row("Quit", 10, it.id))
|
|
} else if n > 1 {
|
|
rows.push(dock_row("Close " + n.to_string() + " windows", 10, it.id))
|
|
}
|
|
rows.push(menu_row("Dock settings...", 3))
|
|
self.open_menu(it.name, rows, w.slot, x)
|
|
}
|
|
|
|
///| A dock menu row was chosen for the dock in `slot`.
|
|
fn DesktopShell::dock_menu_choice(self : DesktopShell, slot : String, row : MenuRow) -> Unit {
|
|
match self.widget_by_slot(slot) {
|
|
None => ()
|
|
Some(w) => {
|
|
let (cfg, items) = self.dock_state(w)
|
|
let pins = cfg.pins(self.apps)
|
|
match row.kind {
|
|
7 => self.launch_catalog_app(row.arg)
|
|
8 => self.set_module_setting(slot, "pinned", @dock.encode_pins(@dock.toggle_pin(pins, row.arg)))
|
|
9 => {
|
|
let delta = if row.value == "-1" { -1 } else { 1 }
|
|
self.set_module_setting(slot, "pinned", @dock.encode_pins(@dock.move_pin(pins, row.arg, delta)))
|
|
}
|
|
10 =>
|
|
for it in items {
|
|
if it.id == row.arg {
|
|
for win in it.windows {
|
|
self.actions.push(Window(win, Close))
|
|
}
|
|
}
|
|
}
|
|
_ => ()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
///| The name of the dock icon under the pointer and that icon's centre x on screen, if any.
|
|
fn DesktopShell::dock_label(self : DesktopShell) -> (String, Int)? {
|
|
match self.widget_by_slot(self.hover_slot) {
|
|
Some(w) if w.is_dock() =>
|
|
match self.dock_item_at(w, self.ptr_x, self.ptr_y) {
|
|
Some((items, i)) => {
|
|
let cfg = dock_config(w)
|
|
Some((items[i].name, w.rect.x + @dock.item_center(items, cfg, w.rect.h, i)))
|
|
}
|
|
None => None
|
|
}
|
|
_ => None
|
|
}
|
|
}
|
|
|
|
///| The name the dock's hover label shows now ("" when none shows).
|
|
pub fn DesktopShell::dock_hover_name(self : DesktopShell) -> String {
|
|
if self.menu_open || self.drag_active {
|
|
return ""
|
|
}
|
|
match self.dock_label() {
|
|
Some((name, _)) => name
|
|
None => ""
|
|
}
|
|
}
|
|
|
|
///| The name of the dock icon under the pointer, in a label above it.
|
|
fn DesktopShell::render_dock_label(self : DesktopShell, tokens : @theme.Tokens, out : Array[@scene.DrawOp]) -> Unit {
|
|
match self.dock_label() {
|
|
Some((name, cx)) => {
|
|
let fs = tokens.font_size.reinterpret_as_int() - 2
|
|
let lw = @ui.text_width(name, fs) + 20
|
|
let lh = 24
|
|
let lx = clamp_menu(cx - lw / 2, 4, self.screen_w - lw - 4)
|
|
let ly = self.panel_rect.y - lh - 6
|
|
let r = tokens.radius.reinterpret_as_int()
|
|
translate(
|
|
[
|
|
@ui.fill_rect(@ui.rect(0, 0, lw, lh), tokens.palette.surface_popup, radius=r),
|
|
@ui.stroke_rect(@ui.rect(0, 0, lw, lh), tokens.palette.border, radius=r),
|
|
@ui.text(lw / 2, lh / 2, name, fs, tokens.palette.foreground, align=CENTER),
|
|
],
|
|
lx,
|
|
ly,
|
|
out,
|
|
)
|
|
}
|
|
None => ()
|
|
}
|
|
}
|