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

+94 -2
View File
@@ -6,9 +6,8 @@
test "dock screenshots: hover label and an app's menu" {
let socket_path = "/tmp/wayland-moon-dockshot-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
assert_true(comp.shell.load_path("build/components/dock.wasm") is Some(_))
ignore(comp.compose_frame())
let slot = comp.shell.slots().filter(s => comp.shell.slot_module(s).contains("dock"))[0]
let slot = comp.shell.slot_of("dock")
// Room for the dock's running apps on a 1280-wide screen.
for s in comp.shell.slots() {
let m = comp.shell.slot_module(s)
@@ -19,6 +18,8 @@ test "dock screenshots: hover label and an app's menu" {
comp.shell.set_module_setting(
slot, "pinned", "libreoffice-writer;libreoffice-calc;libreoffice-impress;debian-xterm;vim",
)
// Icons only, to see the magnification (titles are the default).
comp.shell.set_module_setting(slot, "titles", "off")
let _a = open_and_configure_client(comp, socket_path, "Report.odt", "libreoffice-writer")
let _b = open_and_configure_client(comp, socket_path, "Notes.odt", "libreoffice-writer")
let _c = open_and_configure_client(comp, socket_path, "Terminal", "xterm")
@@ -39,3 +40,94 @@ test "dock screenshots: hover label and an app's menu" {
assert_true(comp.shell.menu_rows.map(m => m.label).contains("Close 2 windows"))
ignore(@sys.write_file_bytes("_build/dock_menu.png", @renderer.encode_png(comp.compose_frame())))
}
///| Pick row `label` of the open right-click menu (rows: 26px title, then 28px each).
fn dock_pick(comp : @host.ChandraCompositor, label : String, t : UInt) -> Unit raise {
let i = comp.shell.menu_rows.map(r => r.label).search(label).unwrap()
let m = comp.shell.menu_rect
click_at(comp, m.x + m.w / 2, m.y + 26 + 28 * i + 14, t)
}
///| A key pressed and released with Super held (evdev codes).
fn super_key(comp : @host.ChandraCompositor, code : UInt, t : UInt) -> Unit {
comp.handle_input(@nested.InputEvent::Key(125U, true), t)
comp.handle_input(@nested.InputEvent::Key(code, true), t + 1U)
comp.handle_input(@nested.InputEvent::Key(code, false), t + 2U)
comp.handle_input(@nested.InputEvent::Key(125U, false), t + 3U)
ignore(comp.compose_frame())
}
///|
test "the dock is the panel's task manager: empty + opens Applications, pin from there, Super+number" {
let socket_path = "/tmp/wayland-moon-dockbar-" + @sys.getpid().to_string() + ".sock"
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
ignore(comp.compose_frame())
// A fresh panel has the dock where the task list was; the old id is an alias of it.
let slot = comp.shell.slot_of("dock")
assert_true(slot.length() > 0)
assert_eq(comp.shell.slot_of("tasks"), slot)
// It stretches: the clock still packs against the right edge.
let r = comp.shell.slot_rect(slot)
assert_true(r.w > 300)
let clock = comp.shell.slot_rect(comp.shell.slot_of("clock-digital"))
assert_true(clock.x > 900)
// Nothing pinned, nothing running: a "+" that opens the Applications menu.
comp.shell.set_module_setting(slot, "pinned", ";")
ignore(comp.compose_frame())
comp.handle_input(@nested.InputEvent::PointerMove((r.x + 14).to_double(), (r.y + r.h / 2).to_double()), 8U)
ignore(@sys.write_file_bytes("_build/dock_empty.png", @renderer.encode_png(comp.compose_frame())))
click_at(comp, r.x + 14, r.y + r.h / 2, 10U)
let launcher = comp.shell.slot_of("launcher")
let pr = comp.shell.slot_popup_rect(launcher)
assert_true(pr.w > 0)
// Right-click the first app there: Open, Pin to dock. Pinning keeps the menu open.
click_at(comp, pr.x + 40, pr.y + 60, 20U, btn=273U)
assert_true(comp.shell.menu_open)
assert_eq(comp.shell.menu_rows.map(r => r.label), ["Open", "Pin to dock"])
let first = comp.shell.menu_title
ignore(@sys.write_file_bytes("_build/dock_pin_from_menu.png", @renderer.encode_png(comp.compose_frame())))
dock_pick(comp, "Pin to dock", 25U)
assert_true(comp.shell.slot_popup_rect(launcher).w > 0)
let pinned = comp.shell.module_setting("dock", "pinned").unwrap_or("")
assert_true(pinned.length() > 1 && pinned != ";")
// The same app's menu now offers Unpin.
click_at(comp, pr.x + 40, pr.y + 60, 30U, btn=273U)
assert_eq(comp.shell.menu_title, first)
assert_true(comp.shell.menu_rows.map(r => r.label).contains("Unpin from dock"))
comp.handle_input(@nested.InputEvent::Key(1U, true), 35U) // Escape closes the menu
comp.handle_input(@nested.InputEvent::Key(1U, false), 36U)
comp.handle_input(@nested.InputEvent::Key(1U, true), 37U) // and the Applications menu
comp.handle_input(@nested.InputEvent::Key(1U, false), 38U)
// Two running apps pinned in front: Super+2 brings the second one's window forward.
comp.shell.set_module_setting(slot, "pinned", "libreoffice-writer;libreoffice-calc;vim")
let _a = open_and_configure_client(comp, socket_path, "Report.odt", "libreoffice-writer")
let _b = open_and_configure_client(comp, socket_path, "Budget.ods", "libreoffice-calc")
let _c = open_and_configure_client(comp, socket_path, "Notes.odt", "libreoffice-writer")
ignore(comp.compose_frame())
let focused = fn() {
let mut f = ""
for _, w in comp.windows {
if w.focused {
f = w.title
}
}
f
}
super_key(comp, 3U, 40U) // Super+2
assert_eq(focused(), "Budget.ods")
super_key(comp, 2U, 50U) // Super+1: Writer's newest window, then its other one
assert_eq(focused(), "Notes.odt")
super_key(comp, 2U, 60U)
assert_eq(focused(), "Report.odt")
// Writer's menu lists its two windows by title; picking one brings it forward.
let r = comp.shell.slot_rect(slot)
click_at(comp, r.x + 6 + 12, r.y + r.h / 2, 70U, btn=273U)
let labels = comp.shell.menu_rows.map(r => r.label)
assert_true(labels.contains("Report.odt") && labels.contains("Notes.odt"))
ignore(@sys.write_file_bytes("_build/dock_bar_menu.png", @renderer.encode_png(comp.compose_frame())))
dock_pick(comp, "Notes.odt", 80U)
ignore(comp.compose_frame())
assert_eq(focused(), "Notes.odt")
comp.handle_input(@nested.InputEvent::PointerMove((r.x + 6 + 30 + 12).to_double(), (r.y + r.h / 2).to_double()), 90U)
ignore(@sys.write_file_bytes("_build/dock_bar.png", @renderer.encode_png(comp.compose_frame())))
}
+34 -27
View File
@@ -262,8 +262,11 @@ test "title-bar buttons minimize, maximize and close windows" {
click(btn(1UL, 1), 20U)
assert_true(comp.wm.windows.get(1UL).unwrap().minimized)
assert_true(!comp.wm.stacking_order().contains(1UL))
let tasks = rect_of(comp, "tasks")
// pills are in opening order (140 wide, 6 apart): window 1, the minimized one, is first
// The dock with nothing pinned: one titled pill per app, in opening order (150 wide, 6 apart):
// window 1's app, the minimized one, is first.
comp.shell.set_module_setting(comp.shell.slot_of("dock"), "pinned", ";")
ignore(comp.compose_frame())
let tasks = rect_of(comp, "dock")
click((tasks.x + 20, tasks.y + tasks.h / 2), 30U)
assert_true(!comp.wm.windows.get(1UL).unwrap().minimized)
// Close window 2: the client receives xdg_toplevel.close (opcode 1 on its toplevel).
@@ -277,7 +280,7 @@ test "title-bar buttons minimize, maximize and close windows" {
}
///|
test "the task list module focuses the window whose pill is clicked" {
test "the dock focuses the window whose pill is clicked" {
let socket_path = "/tmp/wayland-moon-tasks-" +
@sys.getpid().to_string() +
".sock"
@@ -285,6 +288,7 @@ test "the task list module focuses the window whose pill is clicked" {
let comp = @host.ChandraCompositor::new(socket_path, theme, 1280, 720).unwrap()
let _a = open_and_configure_client(comp, socket_path, "A", "a")
let _b = open_and_configure_client(comp, socket_path, "B", "b")
comp.shell.set_module_setting(comp.shell.slot_of("dock"), "pinned", ";")
ignore(comp.compose_frame())
let focused = fn() {
let mut f = 0UL
@@ -295,18 +299,18 @@ test "the task list module focuses the window whose pill is clicked" {
}
f
}
let tasks = rect_of(comp, "tasks")
let tasks = rect_of(comp, "dock")
assert_true(tasks.w > 300) // the stretching module takes the free space
let first = comp.wm.stacking_order()[0]
click_at(comp, tasks.x + 20, tasks.y + tasks.h / 2, 1U) // pill 0
assert_eq(focused(), first)
let other = comp.wm.stacking_order()
click_at(comp, tasks.x + 146 + 20, tasks.y + tasks.h / 2, 10U) // pill 1
click_at(comp, tasks.x + 156 + 20, tasks.y + tasks.h / 2, 10U) // pill 1
assert_true(focused() != first || other.length() == 1)
}
///|
test "right-click a task-bar pill for the window's menu: Minimize, Maximize, Quit" {
test "right-click an app in the dock for its window's menu: Minimize, Maximize, Quit" {
let socket_path = "/tmp/wayland-moon-taskmenu-" +
@sys.getpid().to_string() +
".sock"
@@ -314,8 +318,9 @@ test "right-click a task-bar pill for the window's menu: Minimize, Maximize, Qui
let comp = @host.ChandraCompositor::new(socket_path, theme, 1280, 720).unwrap()
let (c, _shm, _surf, _xdg, tl, _deco) = open_and_configure_client(comp, socket_path, "A", "a")
let _b = open_and_configure_client(comp, socket_path, "B", "b")
comp.shell.set_module_setting(comp.shell.slot_of("dock"), "pinned", ";")
ignore(comp.compose_frame())
let tasks = rect_of(comp, "tasks")
let tasks = rect_of(comp, "dock")
let cy = tasks.y + tasks.h / 2
let labels = fn() { comp.shell.menu_rows.map(r => r.label) }
// Pick menu row `label` (rows: 26px title, then 28px each).
@@ -324,17 +329,17 @@ test "right-click a task-bar pill for the window's menu: Minimize, Maximize, Qui
let m = comp.shell.menu_rect
click_at(comp, m.x + m.w / 2, m.y + 26 + 28 * i + 14, t)
}
// Pill 0 is window 1 (opening order): its menu, titled with its title.
// Pill 0 is window 1's app (opening order): its menu, titled with the app's name.
click_at(comp, tasks.x + 20, cy, 1U, btn=273U)
assert_true(comp.shell.menu_open)
assert_eq(comp.shell.menu_title, "A")
assert_eq(labels(), ["Minimize", "Maximize", "Quit"])
assert_eq(comp.shell.menu_title, "a")
assert_eq(labels(), ["Pin to dock", "Minimize", "Maximize", "Quit", "Dock settings..."])
// Minimize, then the same pill's menu offers Restore, which brings it back.
pick("Minimize", 10U)
assert_true(!comp.shell.menu_open)
assert_true(comp.wm.windows.get(1UL).unwrap().minimized)
click_at(comp, tasks.x + 20, cy, 20U, btn=273U)
assert_eq(labels(), ["Restore", "Maximize", "Quit"])
assert_eq(labels(), ["Pin to dock", "Restore", "Maximize", "Quit", "Dock settings..."])
pick("Restore", 30U)
assert_true(!comp.wm.windows.get(1UL).unwrap().minimized)
// Maximize, then Restore size.
@@ -343,12 +348,12 @@ test "right-click a task-bar pill for the window's menu: Minimize, Maximize, Qui
pick("Maximize", 50U)
assert_true(comp.windows.get(1UL).unwrap().geometry.w > w0)
click_at(comp, tasks.x + 20, cy, 60U, btn=273U)
assert_eq(labels(), ["Minimize", "Restore size", "Quit"])
assert_eq(labels(), ["Pin to dock", "Minimize", "Restore size", "Quit", "Dock settings..."])
pick("Restore size", 70U)
assert_eq(comp.windows.get(1UL).unwrap().geometry.w, w0)
// Pill 1 is window 2.
click_at(comp, tasks.x + 146 + 20, cy, 80U, btn=273U)
assert_eq(comp.shell.menu_title, "B")
// Pill 1 is window 2's app.
click_at(comp, tasks.x + 156 + 20, cy, 80U, btn=273U)
assert_eq(comp.shell.menu_title, "b")
comp.handle_input(@nested.InputEvent::Key(1U, true), 85U) // Escape
assert_true(!comp.shell.menu_open)
// Quit asks the app to close its window (xdg_toplevel.close, opcode 1 on its toplevel).
@@ -360,9 +365,9 @@ test "right-click a task-bar pill for the window's menu: Minimize, Maximize, Qui
@sys.sleep_ms(2)
}
assert_true(has_msg(drain_msgs(c), tl, 1U))
// Empty task-bar space keeps the module's own menu.
// Empty dock space keeps the module's own menu.
click_at(comp, tasks.x + tasks.w - 10, cy, 110U, btn=273U)
assert_eq(comp.shell.menu_title, "Task Manager")
assert_eq(comp.shell.menu_title, "Dock")
assert_true(labels().contains("Remove widget"))
}
@@ -614,9 +619,9 @@ test "the wasm picker opens the settings module's Panel tab, which loads and unl
assert_true(texts.contains("Browse for a module file..."))
// The Add list leaves out what is already in the panel (but a clock can be added twice) and
// has no cryptic instance counts.
assert_eq(texts.filter(t => t == "Task Manager").length(), 1)
assert_eq(texts.filter(t => t == "Dock").length(), 1)
assert_false(texts.contains("x1"))
assert_true(texts.contains("Pinned apps, one click away")) // the Dock's description
assert_true(texts.contains("The time in binary")) // the Binary Clock's description
let loaded = comp.shell.slots().length()
assert_eq(comp.shell.slot_of("clock-binary"), "")
let by = row_y("Binary Clock", false)
@@ -930,25 +935,24 @@ test "the dock: pinned and running apps, window dots, the hover label and the pe
comp.shell.apps.clear()
for id in ["foot", "firefox", "gimp"] {
comp.shell.apps.push({ id, name: id.to_upper(), comment: "", category: "", glyph: "x" })
comp.shell.exec.set(id, id)
}
comp.shell.apps_dirty = true
assert_true(comp.shell.load_path("build/components/dock.wasm") is Some(_))
ignore(comp.compose_frame())
let slot = comp.shell.slots().filter(s => comp.shell.slot_module(s).contains("dock"))[0]
// The dock is in the default panel; icons only here (titled pills are the default).
let slot = comp.shell.slot_of("dock")
comp.shell.set_module_setting(slot, "titles", "off")
let pinned = fn() {
comp.shell.slot_config(slot).filter(it => it.key == "pinned")[0].value
}
// Nothing chosen yet: the catalog's first apps, saved so launches don't reorder them.
assert_eq(pinned(), "foot;firefox;gimp")
// The pinned list isn't a row of the dock's settings menu.
let w0 = comp.shell.slot_rect(slot).w
// A foot window joins foot's icon; an unknown app gets its own icon after the pinned ones.
let _a = open_and_configure_client(comp, socket_path, "Term", "foot")
let _b = open_and_configure_client(comp, socket_path, "Other", "zzz")
ignore(comp.compose_frame())
ignore(comp.compose_frame())
let r = comp.shell.slot_rect(slot)
assert_true(r.w > w0) // the dock grew for the running app
let cy = r.y + r.h / 2
let pitch = 24 + 6 // medium icons
let x_of = fn(i : Int) { r.x + 6 + i * pitch + 12 + (if i >= 3 { 11 } else { 0 }) }
@@ -968,7 +972,9 @@ test "the dock: pinned and running apps, window dots, the hover label and the pe
click_at(comp, x_of(0), cy, 10U, btn=273U)
assert_true(comp.shell.menu_open)
assert_eq(comp.shell.menu_title, "FOOT")
assert_eq(labels(), ["New window", "Unpin from dock", "Move right", "Quit", "Dock settings..."])
assert_eq(labels(), [
"New window", "Unpin from dock", "Move right", "Minimize", "Maximize", "Quit", "Dock settings...",
])
assert_eq(comp.shell.dock_hover_name(), "") // no label over the menu
pick("Move right", 20U)
assert_eq(pinned(), "firefox;foot;gimp")
@@ -983,7 +989,8 @@ test "the dock: pinned and running apps, window dots, the hover label and the pe
let x2 = r.x + 6 + 2 * pitch + 11 + 12
click_at(comp, x2, cy, 50U, btn=273U)
assert_eq(comp.shell.menu_title, "zzz")
assert_eq(labels(), ["New window", "Pin to dock", "Quit", "Dock settings..."])
// Not in the app catalog: nothing to start a new window with.
assert_eq(labels(), ["Pin to dock", "Minimize", "Maximize", "Quit", "Dock settings..."])
pick("Pin to dock", 60U)
assert_eq(pinned(), "foot;gimp;zzz")
// Dock settings: the visible settings only.
@@ -998,7 +1005,7 @@ test "the dock: pinned and running apps, window dots, the hover label and the pe
pick("Large", 90U)
comp.handle_input(@nested.InputEvent::Key(1U, true), 95U) // Escape
ignore(comp.compose_frame())
assert_true(comp.shell.slot_rect(slot).w > r.w) // bigger icons, wider dock
assert_eq(comp.shell.module_setting("dock", "icon-size"), Some("Large"))
// A left click on a running app's icon focuses its window.
let focused = fn() {
let mut f = 0UL
+26 -2
View File
@@ -84,9 +84,21 @@ fn ChandraCompositor::shortcut_key(self : ChandraCompositor, code : UInt, presse
if @shell.is_modifier_key(code) || self.shell.inspecting() {
return false
}
match self.shell.shortcuts.lookup({ mods: self.held_mods(), key: code }) {
let combo : @shell.KeyCombo = { mods: self.held_mods(), key: code }
match self.shell.shortcuts.lookup(combo) {
// Window switching is the switcher's (switcher_key runs before this).
None | Some(SwitchWindows) => false
Some(SwitchWindows) => false
// Super+2 .. Super+9 aren't in the table: they follow the "Open dock app" combo.
None | Some(DockApps) =>
match self.shell.shortcuts.dock_app(combo) {
Some(n) if self.open_dock_app(n) => {
self.sc_swallow.push(code)
self.super_solo = false
true
}
Some(_) => false
None => false
}
Some(action) => {
self.sc_swallow.push(code)
self.run_shortcut(action)
@@ -117,8 +129,20 @@ pub fn ChandraCompositor::run_shortcut(self : ChandraCompositor, action : @shell
RecordRegion => self.toggle_recording(ShotMode::Region)
RecordScreen => self.toggle_recording(ShotMode::FullScreen)
RecordWindow => self.toggle_recording(ShotMode::WindowUnderCursor)
DockApps => ignore(self.open_dock_app(1))
}
}
///| Super+`n`: the dock's `n`-th app, as if its icon were clicked. False when there is no dock
/// or no such app (the key then goes to the focused window as usual).
fn ChandraCompositor::open_dock_app(self : ChandraCompositor, n : Int) -> Bool {
if self.shell.inspecting() || !self.shell.open_dock_item(n) {
return false
}
self.run_shell_actions()
self.damage.mark_full()
true
}
///| evdev code of Backspace (unbinds while capturing).
let key_backspace : UInt = 14
+1
View File
@@ -34,6 +34,7 @@ test "the default shortcuts are the compositor's long-standing combos" {
("record-region", "Super+Shift+R"),
("record-screen", "Super+Alt+R"),
("record-window", "Super+Ctrl+R"),
("dock-apps", "Super+1"),
]
let sc = @shell.Shortcuts::defaults()
assert_eq(@shell.shortcut_table.length(), want.length())
+210 -6
View File
@@ -26,7 +26,23 @@ fn dock_config(w : Widget) -> @dock.DockConfig {
///| 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 })
self.win_list.map(e => {
id: e.id,
app_id: e.app_id,
focused: e.focused,
title: e.title,
minimized: self.win_info(e.id).map(i => i.minimized).unwrap_or(false),
})
}
///| The window list entry (minimized, maximized) of window `id`.
fn DesktopShell::win_info(self : DesktopShell, id : UInt64) -> WinInfo? {
for w in self.windows {
if w.id == id {
return Some(w)
}
}
None
}
///| The dock in `w`'s settings and icons, as the module computes them.
@@ -163,7 +179,9 @@ fn DesktopShell::open_dock_menu(
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 self.command_for(it.id) is Some(_) {
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()
@@ -176,6 +194,30 @@ fn DesktopShell::open_dock_menu(
} else {
rows.push(dock_row("Pin to dock", 8, it.id))
}
if n == 1 {
// The window's own commands, as the task list had them.
match self.win_info(it.windows[0]) {
Some(win) => {
rows.push(
if win.minimized {
window_row("Restore", win.id, Restore)
} else {
window_row("Minimize", win.id, Minimize)
},
)
rows.push(window_row(if win.maximized { "Restore size" } else { "Maximize" }, win.id, ToggleMaximize))
}
None => ()
}
} else if n > 1 {
// Its windows by title, so one can be picked straight away (a click cycles through them).
rows.push(menu_row("Windows", 5))
for win in it.windows {
let min = self.win_info(win).map(i => i.minimized).unwrap_or(false)
let label = self.window_title(win) + (if min { " (minimized)" } else { "" })
rows.push({ ..menu_row(label, 6), window_id: win, window_cmd: Restore })
}
}
if n == 1 {
rows.push(dock_row("Quit", 10, it.id))
} else if n > 1 {
@@ -185,15 +227,25 @@ fn DesktopShell::open_dock_menu(
self.open_menu(it.name, rows, w.slot, x)
}
///| A dock menu row was chosen for the dock in `slot`.
///| A dock menu row was chosen for the dock in `slot`. "Pin to dock" from the Applications menu
/// when there is no dock yet (`slot` "") puts one in the panel first.
fn DesktopShell::dock_menu_choice(self : DesktopShell, slot : String, row : MenuRow) -> Unit {
match self.widget_by_slot(slot) {
let dock = match self.widget_by_slot(slot) {
Some(w) => Some(w)
None if row.kind == 8 => self.add_dock()
None => None
}
if row.kind == 7 {
self.launch_catalog_app(row.arg)
return
}
match dock {
None => ()
Some(w) => {
let slot = w.slot
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 }
@@ -220,7 +272,10 @@ fn DesktopShell::dock_label(self : DesktopShell) -> (String, Int)? {
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)))
if @dock.titled_at(items, cfg, w.rect.w, w.rect.h, i) {
return None
}
Some((items[i].name, w.rect.x + @dock.item_center(items, cfg, w.rect.w, w.rect.h, i)))
}
None => None
}
@@ -263,3 +318,152 @@ fn DesktopShell::render_dock_label(self : DesktopShell, tokens : @theme.Tokens,
None => ()
}
}
// ---------------------------------------------------------------- pinning from elsewhere
///| The first dock in the panel, if any.
fn DesktopShell::dock_widget(self : DesktopShell) -> Widget? {
for w in self.widgets {
if w.is_dock() {
return Some(w)
}
}
None
}
///| A window's title ("Window" when it has none).
fn DesktopShell::window_title(self : DesktopShell, id : UInt64) -> String {
for e in self.win_list {
if e.id == id && e.title.length() > 0 {
return e.title
}
}
"Window"
}
///| Put a dock into the panel, just after the Applications button (or first), with its
/// first pins settled. None when the dock module can't be found or loaded.
fn DesktopShell::add_dock(self : DesktopShell) -> Widget? {
self.name_catalog()
match self.find_module("dock") {
None => {
self.say("Dock module not found (build it with scripts/build-modules.sh)")
None
}
Some(c) =>
match self.load_path(c.path) {
None => None
Some(w) => {
let mut at = 0
for i = 0; i < self.widgets.length(); i = i + 1 {
if self.widgets[i].module_id == launcher_module {
at = i + 1
}
}
self.widgets.retain(x => x.slot != w.slot)
self.widgets.insert(at, w)
self.settle_dock_pins()
self.save_panel_config()
Some(w)
}
}
}
}
///| "Pin to dock" or "Unpin from dock" for app `id` (a catalog or window app id) as a row of
/// another menu, and the dock's slot that row acts on ("" when there is no dock yet: pinning
/// then adds one).
fn DesktopShell::pin_row(self : DesktopShell, id : String) -> (MenuRow, String) {
match self.dock_widget() {
Some(w) => {
let pinned = dock_config(w).pins(self.apps).contains(id)
(dock_row(if pinned { "Unpin from dock" } else { "Pin to dock" }, 8, id), w.slot)
}
None => (dock_row("Pin to dock", 8, id), "")
}
}
///| The right-click menu of an app in the Applications menu: Open, and Pin to dock / Unpin.
fn DesktopShell::open_app_menu(self : DesktopShell, app : @types.AppEntry, x : Int) -> Unit {
let (pin, slot) = self.pin_row(app.id)
self.open_menu(app.name, [dock_row("Open", 7, app.id), pin], slot, x)
}
///| The app under (x, y) in the Applications menu's popup, if it is open there.
fn DesktopShell::launcher_app_at(self : DesktopShell, x : Int, y : Int) -> @types.AppEntry? {
match self.popup_at(x, y) {
Some(w) if w.module_id == launcher_module => {
let shown = @launcher.filter(self.apps, self.launcher_state.query)
let i = @launcher.row_at(self.apps, self.launcher_state, { x: x - w.popup_rect.x, y: y - w.popup_rect.y })
if i >= 0 && i < shown.length() {
Some(shown[i])
} else {
None
}
}
_ => None
}
}
///| Follow an event the launcher module was handed, so the shell knows what its popup lists
/// (its search text) for the right-click menu. The module's own state stays the truth for
/// whether it is open.
fn DesktopShell::follow_launcher(self : DesktopShell, w : Widget, popup : Bool, ev : @wasm.PlasmoidEvent) -> Unit {
let st = self.launcher_state
let e : @types.InputEvent = match ev {
PointerMove(x, y) => PointerMove({ x, y })
PointerDown(x, y) => PointerDown({ x, y })
PointerUp(x, y) => PointerUp({ x, y })
PointerLeave => PointerLeave
FocusLost => FocusLost
KeyDown(k) => KeyDown(k)
}
ignore(@launcher.handle_event(self.apps, st, if popup { Popup } else { Widget }, e, _ => Ok(())))
if w.popup_rect.w == 0 {
@launcher.close(st)
} else if !st.open {
// Open in the module (its launch failed and kept it open): open here too.
ignore(@launcher.handle_event(self.apps, st, Widget, PointerDown({ x: 0, y: 0 }), _ => Ok(())))
}
}
///| Super+`n` (1-based): what a click on the dock's `n`-th icon does, start the app or bring its
/// windows forward. False when there is no dock or no such icon.
pub fn DesktopShell::open_dock_item(self : DesktopShell, n : Int) -> Bool {
self.ensure_booted()
match self.dock_widget() {
None => false
Some(w) => {
let (_, items) = self.dock_state(w)
if n < 1 || n > items.length() {
return false
}
let mut focused : UInt64? = None
for e in self.win_list {
if e.focused {
focused = Some(e.id)
}
}
match @dock.activate(items[n - 1], focused) {
Launch(id) => self.launch_catalog_app(id)
Focus(win) => self.actions.push(FocusWindow(win))
Nothing => ()
}
true
}
}
}
///| A left click on the dock in `w` at (x, y): the empty dock's "+" opens the Applications menu,
/// where right-clicking an app pins it. True when the shell took the click.
fn DesktopShell::dock_click(self : DesktopShell, w : Widget) -> Bool {
if !w.is_dock() {
return false
}
let (_, items) = self.dock_state(w)
if items.length() > 0 {
return false
}
self.toggle_launcher()
true
}
+8
View File
@@ -351,6 +351,9 @@ pub(all) struct DesktopShell {
wit_cache : Map[String, String]
/// Most-recently-launched app ids, newest first (persisted).
recents : Array[String]
/// The launcher module's state as the shell follows it (dock.mbt `follow_launcher`): what its
/// popup lists, for the right-click "Pin to dock" menu.
launcher_state : @launcher.State
}
///|
@@ -459,6 +462,7 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
comps: [],
wit_cache: {},
recents: [],
launcher_state: @launcher.State::new(),
}
sh.order_apps()
sh
@@ -634,6 +638,9 @@ fn DesktopShell::deliver(self : DesktopShell, w : Widget, popup : Bool, ev : @wa
// The module may have unloaded itself (or been replaced) while handling the event.
if self.widget_by_slot(w.slot) is Some(_) {
self.refresh_popup(w)
if w.module_id == launcher_module {
self.follow_launcher(w, popup, ev)
}
}
changed
}
@@ -780,6 +787,7 @@ pub fn DesktopShell::pointer_up(self : DesktopShell) -> Bool {
self.save_panel_config()
} else {
match self.widget_by_slot(slot) {
Some(w) if self.dock_click(w) => ()
Some(w) => ignore(self.deliver(w, false, PointerDown(self.drag_x0 - w.rect.x, self.drag_y0 - w.rect.y)))
None => ()
}
+44
View File
@@ -50,6 +50,10 @@ pub(all) enum ShortcutAction {
RecordRegion
RecordScreen
RecordWindow
/// The dock's apps by number: the combo opens the first, the same modifiers with 2 .. 9 the
/// second to ninth (when the combo's key is 1). Like clicking the icon: start the app or bring
/// its windows forward. See `Shortcuts::dock_app`.
DockApps
} derive(Eq, Debug)
///| One row of the shortcut table.
@@ -77,6 +81,7 @@ pub let shortcut_table : Array[ShortcutDef] = [
{ id: "record-region", label: "Record a region", action: RecordRegion, default_text: "Super+Shift+R" },
{ id: "record-screen", label: "Record the screen", action: RecordScreen, default_text: "Super+Alt+R" },
{ id: "record-window", label: "Record a window", action: RecordWindow, default_text: "Super+Ctrl+R" },
{ id: "dock-apps", label: "Open dock app 1-9", action: DockApps, default_text: "Super+1" },
]
///| evdev code -> key name, for the keys a combo can end in (US layout names).
@@ -487,3 +492,42 @@ pub fn DesktopShell::publish_shortcuts(self : DesktopShell) -> Unit {
}
@wasm.publish(Shortcuts, t)
}
///| evdev codes of the 1 and 9 keys (the row above the letters).
let key_1 : UInt = 2
///|
let key_9 : UInt = 10
///| Which of the dock's apps (1-9) `combo` opens: the "Open dock app" combo itself is the first,
/// and when that combo ends in 1, the same modifiers with 2 .. 9 open the second to ninth.
pub fn Shortcuts::dock_app(self : Shortcuts, combo : KeyCombo) -> Int? {
let mods = combo.mods & combo_mods
for i = 0; i < self.bindings.length(); i = i + 1 {
if shortcut_table[i].action == DockApps {
match self.bindings[i] {
Some(c) if c.mods == mods => {
if c.key == key_1 && combo.key >= key_1 && combo.key <= key_9 {
return Some((combo.key - key_1).reinterpret_as_int() + 1)
}
if same_key(c.key, combo.key) {
return Some(1)
}
}
_ => ()
}
}
}
None
}
///|
test "Super+1 .. Super+9 open the dock's apps" {
let sc = Shortcuts::defaults()
assert_eq(sc.dock_app({ mods: mod_logo, key: 2 }), Some(1))
assert_eq(sc.dock_app({ mods: mod_logo, key: 6 }), Some(5))
assert_eq(sc.dock_app({ mods: mod_logo, key: 10 }), Some(9))
assert_eq(sc.dock_app({ mods: mod_logo, key: 11 }), None) // 0
assert_eq(sc.dock_app({ mods: mod_logo | mod_shift, key: 3 }), None)
assert_eq(sc.dock_app({ mods: 0, key: 3 }), None)
}
+40 -51
View File
@@ -11,9 +11,10 @@
/// and opens that tab. A module may also export `module-config`: its own settings, listed under
/// "Module settings..." in its right-click menu and remembered in state.edn (module_config.mbt).
///| Modules loaded into a fresh panel, in order. `tasks` stretches, so what follows it packs right.
///| Modules loaded into a fresh panel, in order. The dock (pinned and running apps, the task
/// manager) stretches, so what follows it packs right.
let default_panel : Array[String] = [
"launcher", "inspector", "layout", "tasks", "moon-disc", "network", "clock-digital", "screenshot",
"launcher", "inspector", "layout", "dock", "moon-disc", "network", "clock-digital", "screenshot",
"session-settings",
]
@@ -47,9 +48,13 @@ test "a fresh panel gets the battery module only on a machine with a battery" {
/// - logout, the Log out button, is the Application Launcher's session row (Reload, Log out,
/// Suspend, Restart, Power off). A saved panel drops it, or gets the launcher in its place when
/// it had none (migrate_panel).
/// - tasks, the Task Manager's window pills, is the dock: pinned and running apps, titled pills
/// when there is room, each window's menu. A saved panel with both keeps one dock, where the
/// task list was (migrate_panel); the dock's pins carry over (they are the dock's own setting).
let retired_modules : Map[String, String] = {
"clock-digital12": "clock-digital",
"logout": "launcher",
"tasks": "dock",
}
///| The id a module goes by now ("clock-digital12" -> "clock-digital").
@@ -105,7 +110,7 @@ fn stem(path : String) -> String {
}
}
///| The WIT world ("clock-widget", "taskbar-widget", ...) a module was built for, read from the
///| The WIT world ("clock-widget", "dock-widget", ...) a module was built for, read from the
/// `<name>.meta.json` that build-modules.sh writes next to it; "" when unknown (a module loaded
/// from elsewhere). Two modules are interchangeable only when their worlds match.
fn module_world(path : String) -> String {
@@ -222,12 +227,21 @@ fn wall_secs() -> Int {
/// module list "wallpaper" or "module-manager": the settings module takes the first one's place
/// (a panel that already has it just drops them). The Log out button moved into the launcher the
/// same way: "logout" becomes the launcher when the panel has none, else it is dropped. Other
/// retired modules (clock-digital12) become the module that replaced them.
/// retired modules (clock-digital12) become the module that replaced them; the task list and the
/// dock become one dock, in the task list's place.
fn migrate_panel(entries : Array[String]) -> Array[String] {
let has_settings = entries.contains("session-settings")
let has_launcher = entries.contains("launcher")
// One dock, where the task list was when there was one (it sat in the stretching place).
let dock_at = match entries.search("tasks") {
Some(i) => i
None => entries.search("dock").unwrap_or(-1)
}
let out : Array[String] = []
for e in entries {
for i, e in entries {
if (e == "tasks" || e == "dock") && i != dock_at {
continue
}
if e == "wallpaper" || e == "module-manager" {
if !has_settings && !out.contains("session-settings") {
out.push("session-settings")
@@ -251,9 +265,17 @@ test "a saved panel's wallpaper button becomes the settings module" {
assert_eq(migrate_panel(["clock"]), ["clock"])
}
///|
test "a saved panel's task list and dock become one dock, in the task list's place" {
assert_eq(migrate_panel(["launcher", "tasks", "clock-digital", "dock"]), ["launcher", "dock", "clock-digital"])
assert_eq(migrate_panel(["dock", "launcher", "tasks"]), ["launcher", "dock"])
assert_eq(migrate_panel(["launcher", "dock", "clock-digital"]), ["launcher", "dock", "clock-digital"])
assert_eq(current_module_id("tasks"), "dock")
}
///|
test "a saved panel's 12-hour clock becomes the digital clock" {
assert_eq(migrate_panel(["tasks", "clock-digital12", "logout"]), ["tasks", "clock-digital", "launcher"])
assert_eq(migrate_panel(["tasks", "clock-digital12", "logout"]), ["dock", "clock-digital", "launcher"])
assert_eq(current_module_id("clock-digital12"), "clock-digital")
assert_eq(current_module_id("clock-binary"), "clock-binary")
}
@@ -262,10 +284,10 @@ test "a saved panel's 12-hour clock becomes the digital clock" {
test "a saved panel's Log out button folds into the launcher" {
// The launcher's session row has Log out now: the old button is dropped...
assert_eq(migrate_panel(["launcher", "tasks", "session-settings", "logout"]), [
"launcher", "tasks", "session-settings",
"launcher", "dock", "session-settings",
])
// ...or becomes the launcher on a panel without one, so Log out stays reachable.
assert_eq(migrate_panel(["tasks", "logout"]), ["tasks", "launcher"])
assert_eq(migrate_panel(["tasks", "logout"]), ["dock", "launcher"])
assert_eq(migrate_panel(["logout", "launcher"]), ["launcher"])
assert_false(default_panel.contains("logout"))
}
@@ -945,8 +967,8 @@ let menu_w : Int = 250
///| Most "Replace with" rows listed.
let max_replace_rows : Int = 8
///| Right-click: on a window's pill in the task manager that window's menu (Minimize or Restore,
/// Maximize, Quit); on a module its menu (Module settings, System settings, replace, remove); on
///| Right-click: on an app in the open Applications menu its Open / Pin to dock menu; on an app in
/// the dock its menu (dock.mbt); on a module its menu (Module settings, System settings, replace, remove); on
/// empty panel space System settings (whose Panel tab adds modules). True when consumed.
pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool {
self.ensure_booted()
@@ -955,12 +977,16 @@ pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool
}
let was_open = self.menu_open
self.menu_open = false
// An app in the open Applications menu: Open, Pin to dock. The menu stays open behind it.
match self.launcher_app_at(x, y) {
Some(app) => {
self.open_app_menu(app, x)
return true
}
None => ()
}
self.dismiss_popups("")
match self.widget_at(x, y) {
Some(w) if self.task_at(w, x, y) is Some(win) => {
self.open_window_menu(win, x)
true
}
Some(w) if self.dock_item_at(w, x, y) is Some((items, i)) => {
self.open_dock_menu(w, items, i, x)
true
@@ -1002,43 +1028,6 @@ pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool
}
}
///| The task manager module's id: its pills are hit-tested here (lib/panel/tasks.mbt) so a
/// right-click on one opens that window's menu.
let tasks_module_id : String = "org.chandra.tasks"
///| The window whose task-bar pill is under (x, y) when `w` is the task manager. The pills are
/// the windows in opening order (by id, as the module sorts them).
fn DesktopShell::task_at(self : DesktopShell, w : Widget, x : Int, y : Int) -> WinInfo? {
if w.pl.id != tasks_module_id || !inside(w.rect, x, y) {
return None
}
// The module sorts by the 32-bit id it is handed through `windows.list-windows`.
let key = (win : WinInfo) => win.id.to_int().reinterpret_as_uint()
let wins = self.windows.copy()
wins.sort_by((a, b) => key(a).compare(key(b)))
let i = @panel.task_pill_at(x - w.rect.x, wins.length(), w.rect.w)
if i >= 0 {
Some(wins[i])
} else {
None
}
}
///| The window menu of a task-bar pill, titled with the window's title.
fn DesktopShell::open_window_menu(self : DesktopShell, win : WinInfo, x : Int) -> Unit {
let rows = [
if win.minimized {
window_row("Restore", win.id, Restore)
} else {
window_row("Minimize", win.id, Minimize)
},
window_row(if win.maximized { "Restore size" } else { "Maximize" }, win.id, ToggleMaximize),
window_row("Quit", win.id, Close),
]
let title = if win.title.length() > 0 { win.title } else { "Window" }
self.open_menu(title, rows, "", x)
}
///| The module's own settings as menu rows: an on/off setting is one row, ticked when on; a
/// setting with choices is a heading and one row per choice, the current one ticked.
fn config_rows(items : Array[@wasm.ConfigItem]) -> Array[MenuRow] {
-66
View File
@@ -122,72 +122,6 @@ test "a module's own settings (module-config) are listed and set through wasmer"
l.unload()
}
///|
test "task list module draws the host's windows and asks to focus one" {
let p = load_module("tasks")
assert_true(p.stretch)
assert_true(p.imports().contains("windows") && p.imports().contains("theme"))
let t = Table::new()
t.int(7)
t.str("Kate — notes")
t.int(1)
t.int(0)
t.end_row()
t.int(9)
t.str("foot")
t.int(0)
t.int(1)
t.end_row()
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())
// 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_eq(drain(), [FocusWindow(9)])
p.unload()
}
///|
test "task list draws the host's icon for an app it has one for, the letter tile otherwise" {
let p = load_module("tasks")
assert_true(p.imports().contains("icons"))
let t = Table::new()
for w in [(3, "Firefox"), (4, "foot")] {
t.int(w.0)
t.str(w.1)
t.int(0)
t.int(0)
t.end_row()
}
publish(Windows, t)
set_windows([
{ id: 3UL, title: "Firefox", app_id: "firefox", focused: false },
{ id: 4UL, title: "foot", app_id: "foot", focused: false },
])
let icons = Table::new()
icons.str("firefox")
icons.int(42)
icons.end_row()
publish(Icons, icons)
let ops = p.render(400, 36, test_tokens())
let images = ops.filter_map(op => match op {
Image(i) => Some(i)
_ => None
})
// Firefox: the icon (handle 42, a 22px square centred in the bar), no glyph; foot: the tile.
assert_eq(images.length(), 1)
assert_eq(images[0].image, 42U)
assert_eq((images[0].rect.w, images[0].rect.h), (22U, 22U))
assert_eq(images[0].rect.y, 7)
assert_eq(texts_of(ops), ["Firefox", "F", "foot"])
publish(Icons, Table::new())
set_windows([])
p.unload()
}
///|
test "layout module is a tile/float toggle" {
let p = load_module("layout")