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
@@ -0,0 +1,41 @@
|
||||
///| The dock drawn in a real frame, for a look at it: writes _build/dock_hover.png (an icon under
|
||||
/// the pointer, magnified, with its name above) and _build/dock_menu.png (an app's right-click
|
||||
/// menu). Uses the machine's own .desktop files and icon theme, so what it shows varies.
|
||||
|
||||
///|
|
||||
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]
|
||||
// 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)
|
||||
if m == "inspector" || m == "layout" || m == "screenshot" {
|
||||
ignore(comp.shell.unload_slot(s))
|
||||
}
|
||||
}
|
||||
comp.shell.set_module_setting(
|
||||
slot, "pinned", "libreoffice-writer;libreoffice-calc;libreoffice-impress;debian-xterm;vim",
|
||||
)
|
||||
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")
|
||||
let _e = open_and_configure_client(comp, socket_path, "Notes 2", "org.example.Notes")
|
||||
let _d = open_and_configure_client(comp, socket_path, "Notes", "org.example.Notes")
|
||||
ignore(comp.compose_frame())
|
||||
ignore(comp.compose_frame())
|
||||
let r = comp.shell.slot_rect(slot)
|
||||
let cy = r.y + r.h / 2
|
||||
// Hover the second icon (Calc).
|
||||
comp.handle_input(@nested.InputEvent::PointerMove((r.x + 6 + 30 + 12).to_double(), cy.to_double()), 1U)
|
||||
let frame = comp.compose_frame()
|
||||
assert_true(comp.shell.dock_hover_name().length() > 0)
|
||||
ignore(@sys.write_file_bytes("_build/dock_hover.png", @renderer.encode_png(frame)))
|
||||
// Right-click the first (Writer, two windows).
|
||||
click_at(comp, r.x + 6 + 12, cy, 10U, btn=273U)
|
||||
assert_true(comp.shell.menu_open)
|
||||
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())))
|
||||
}
|
||||
@@ -907,7 +907,7 @@ test "the dock module magnifies the tile under the pointer and shows nothing whe
|
||||
let comp = new_comp("dock")
|
||||
assert_true(comp.shell.load_path("build/components/dock.wasm") is Some(_))
|
||||
ignore(comp.compose_frame())
|
||||
let slot = comp.shell.slots()[comp.shell.slots().length() - 1]
|
||||
let slot = comp.shell.slots().filter(s => comp.shell.slot_module(s).contains("dock"))[0]
|
||||
let r = comp.shell.slot_rect(slot)
|
||||
assert_true(r.w > 0)
|
||||
let frame = fn() {
|
||||
@@ -922,6 +922,102 @@ test "the dock module magnifies the tile under the pointer and shows nothing whe
|
||||
assert_eq(comp.shell.hover_slot, "")
|
||||
}
|
||||
|
||||
///|
|
||||
test "the dock: pinned and running apps, window dots, the hover label and the per-app menu" {
|
||||
let socket_path = "/tmp/wayland-moon-dock2-" + @sys.getpid().to_string() + ".sock"
|
||||
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
||||
// A known catalog instead of whatever this machine has installed.
|
||||
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.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]
|
||||
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 }) }
|
||||
// Hovering an icon shows its name above it.
|
||||
comp.handle_input(@nested.InputEvent::PointerMove(x_of(1).to_double(), cy.to_double()), 1U)
|
||||
ignore(comp.compose_frame())
|
||||
assert_eq(comp.shell.dock_hover_name(), "FIREFOX")
|
||||
comp.handle_input(@nested.InputEvent::PointerMove(x_of(3).to_double(), cy.to_double()), 2U)
|
||||
assert_eq(comp.shell.dock_hover_name(), "zzz")
|
||||
let labels = fn() { comp.shell.menu_rows.map(r => r.label) }
|
||||
let pick = fn(label : String, t : UInt) raise {
|
||||
let i = labels().search(label).unwrap()
|
||||
let m = comp.shell.menu_rect
|
||||
click_at(comp, m.x + m.w / 2, m.y + 26 + 28 * i + 14, t)
|
||||
}
|
||||
// Right-click foot: it runs, it's pinned first.
|
||||
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(comp.shell.dock_hover_name(), "") // no label over the menu
|
||||
pick("Move right", 20U)
|
||||
assert_eq(pinned(), "firefox;foot;gimp")
|
||||
// Firefox (now first) isn't running.
|
||||
click_at(comp, x_of(0), cy, 30U, btn=273U)
|
||||
assert_eq(labels(), ["Open", "Unpin from dock", "Move right", "Dock settings..."])
|
||||
pick("Unpin from dock", 40U)
|
||||
assert_eq(pinned(), "foot;gimp")
|
||||
// The running app: pin it.
|
||||
ignore(comp.compose_frame())
|
||||
let r = comp.shell.slot_rect(slot)
|
||||
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..."])
|
||||
pick("Pin to dock", 60U)
|
||||
assert_eq(pinned(), "foot;gimp;zzz")
|
||||
// Dock settings: the visible settings only.
|
||||
ignore(comp.compose_frame())
|
||||
let r = comp.shell.slot_rect(slot)
|
||||
click_at(comp, r.x + 6 + 12, cy, 70U, btn=273U)
|
||||
pick("Dock settings...", 80U)
|
||||
assert_eq(comp.shell.menu_title, "Dock settings")
|
||||
assert_true(labels().contains("Icon size"))
|
||||
assert_true(labels().contains("Large"))
|
||||
assert_false(labels().contains(""))
|
||||
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
|
||||
// A left click on a running app's icon focuses its window.
|
||||
let focused = fn() {
|
||||
let mut f = 0UL
|
||||
for id, w in comp.windows {
|
||||
if w.focused {
|
||||
f = id
|
||||
}
|
||||
}
|
||||
f
|
||||
}
|
||||
let r = comp.shell.slot_rect(slot)
|
||||
click_at(comp, r.x + 6 + 2 * 34 + 14, cy, 100U) // zzz, the third icon
|
||||
ignore(comp.compose_frame())
|
||||
assert_eq(focused(), 2UL)
|
||||
click_at(comp, r.x + 6 + 14, cy, 110U) // foot, the first
|
||||
ignore(comp.compose_frame())
|
||||
assert_eq(focused(), 1UL) // foot's window, opened first
|
||||
}
|
||||
|
||||
///| Bind wl_data_device_manager and get a data device; returns (manager, device).
|
||||
fn data_device_for(c : TestWaylandClient) -> (UInt, UInt) {
|
||||
let mgr = bind_global(c, 2U, "wl_data_device_manager", 3U)
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
///| 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 => ()
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,7 @@ pub fn DesktopShell::window_icon(self : DesktopShell, app_id : String) -> UInt {
|
||||
if app_id.length() == 0 { 0U } else { self.app_icon(app_id) }
|
||||
}
|
||||
|
||||
///| Publish the icons table (app id -> image handle) for the windows' apps.
|
||||
///| Publish the icons table (app id -> image handle) for the windows' apps and the dock's.
|
||||
fn DesktopShell::publish_icons(self : DesktopShell) -> Unit {
|
||||
let t = @wasm.Table::new()
|
||||
let seen : Map[String, Bool] = {}
|
||||
@@ -146,6 +146,18 @@ fn DesktopShell::publish_icons(self : DesktopShell) -> Unit {
|
||||
}
|
||||
}
|
||||
}
|
||||
// The dock's apps, running or not.
|
||||
for id in self.dock_app_ids() {
|
||||
if !seen.contains(id) {
|
||||
seen.set(id, true)
|
||||
let h = self.app_icon(id)
|
||||
if h != 0U {
|
||||
t.str(id)
|
||||
t.int(h.reinterpret_as_int())
|
||||
t.end_row()
|
||||
}
|
||||
}
|
||||
}
|
||||
@wasm.publish(Icons, t)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
"chandra/desktop/lib/moon" @moon,
|
||||
"chandra/desktop/lib/timefmt" @timefmt,
|
||||
"chandra/desktop/lib/launcher" @launcher,
|
||||
"chandra/desktop/lib/dock" @dock,
|
||||
"chandra/desktop/compositor/scene" @scene,
|
||||
"jqlssg/moonedn" @edn,
|
||||
"chandra/desktop/compositor/sys" @sys,
|
||||
|
||||
+11
-20
@@ -335,6 +335,9 @@ pub(all) struct DesktopShell {
|
||||
mut drag_x0 : Int
|
||||
mut drag_y0 : Int
|
||||
mut drag_active : Bool
|
||||
/// Where the pointer last was (the dock's hover label follows it).
|
||||
mut ptr_x : Int
|
||||
mut ptr_y : Int
|
||||
// WIT inspector state (see inspector.mbt)
|
||||
mut inspect_on : Bool
|
||||
mut hover_id : String
|
||||
@@ -442,6 +445,8 @@ pub fn DesktopShell::new(display : String) -> DesktopShell {
|
||||
drag_x0: 0,
|
||||
drag_y0: 0,
|
||||
drag_active: false,
|
||||
ptr_x: -1,
|
||||
ptr_y: -1,
|
||||
inspect_on: false,
|
||||
hover_id: "",
|
||||
hover_x: 0,
|
||||
@@ -781,6 +786,8 @@ pub fn DesktopShell::pointer_up(self : DesktopShell) -> Bool {
|
||||
|
||||
///| Pointer motion; returns true when over a popup or the menu (so windows don't see it).
|
||||
pub fn DesktopShell::pointer_move(self : DesktopShell, x : Int, y : Int) -> Bool {
|
||||
self.ptr_x = x
|
||||
self.ptr_y = y
|
||||
if self.desk_drag {
|
||||
self.desk_set = true
|
||||
self.desk_x = x - self.desk_off_x
|
||||
@@ -822,26 +829,6 @@ pub fn DesktopShell::pointer_move(self : DesktopShell, x : Int, y : Int) -> Bool
|
||||
Some(w) => ignore(self.deliver(w, false, PointerMove(x - w.rect.x, y - w.rect.y)))
|
||||
None => ()
|
||||
}
|
||||
// Hover: the widget under the pointer sees moves, the one it left sees a leave.
|
||||
let hovered = match self.widget_at(x, y) {
|
||||
Some(w) if !self.popup_covers(x, y) => Some(w)
|
||||
_ => None
|
||||
}
|
||||
let hslot = match hovered {
|
||||
Some(w) => w.slot
|
||||
None => ""
|
||||
}
|
||||
if hslot != self.hover_slot {
|
||||
match self.widget_by_slot(self.hover_slot) {
|
||||
Some(old) => ignore(self.deliver(old, false, PointerLeave))
|
||||
None => ()
|
||||
}
|
||||
self.hover_slot = hslot
|
||||
}
|
||||
match hovered {
|
||||
Some(w) => ignore(self.deliver(w, false, PointerMove(x - w.rect.x, y - w.rect.y)))
|
||||
None => ()
|
||||
}
|
||||
let mut over = false
|
||||
for w in self.widgets.copy() {
|
||||
if w.popup_rect.w > 0 {
|
||||
@@ -950,6 +937,7 @@ pub fn DesktopShell::render(
|
||||
if self.widgets.iter().any(w => w.has_cap("system") || w.has_cap("windows")) {
|
||||
@wasm.set_windows(self.win_list)
|
||||
}
|
||||
self.settle_dock_pins()
|
||||
if self.widgets.iter().any(w => w.has_cap("icons")) {
|
||||
self.publish_icons()
|
||||
}
|
||||
@@ -977,6 +965,9 @@ pub fn DesktopShell::render(
|
||||
self.refresh_popup(wd)
|
||||
self.draw_popup(wd, panel_ops)
|
||||
}
|
||||
if !self.menu_open && !self.drag_active {
|
||||
self.render_dock_label(tokens, panel_ops)
|
||||
}
|
||||
if self.menu_open {
|
||||
self.render_menu(w, tokens, panel_ops)
|
||||
} else {
|
||||
|
||||
@@ -188,7 +188,7 @@ fn DesktopShell::panel_slots(self : DesktopShell) -> Array[@panel.SlotIn] {
|
||||
let w = self.widgets[i]
|
||||
out.push({
|
||||
id: w.slot,
|
||||
pref_w: w.pl.pref_w,
|
||||
pref_w: self.dock_width(w).unwrap_or(w.pl.pref_w),
|
||||
pref_h: w.pl.pref_h,
|
||||
min_w: w.pl.min_w,
|
||||
stretch: w.pl.stretch,
|
||||
@@ -753,23 +753,26 @@ pub fn DesktopShell::set_power_timeouts(self : DesktopShell, screen_off : Int, s
|
||||
self.save_state()
|
||||
}
|
||||
|
||||
///| Start the catalog app `id` (a desktop file id) and remember it as the latest launch.
|
||||
fn DesktopShell::launch_catalog_app(self : DesktopShell, id : String) -> Unit {
|
||||
match self.command_for(id) {
|
||||
Some(bin) =>
|
||||
if @sys.spawn(bin, self.display) {
|
||||
self.note_recent(id)
|
||||
self.apps_dirty = true
|
||||
} else {
|
||||
self.say("Could not start " + bin)
|
||||
}
|
||||
None => self.say("No executable for " + id)
|
||||
}
|
||||
}
|
||||
|
||||
///| Carry out what modules asked of the host during their last calls.
|
||||
fn DesktopShell::process_requests(self : DesktopShell) -> Unit {
|
||||
while true {
|
||||
match @wasm.next_request() {
|
||||
None => break
|
||||
Some(Launch(id)) => {
|
||||
match self.command_for(id) {
|
||||
Some(bin) =>
|
||||
if @sys.spawn(bin, self.display) {
|
||||
self.note_recent(id)
|
||||
self.apps_dirty = true
|
||||
} else {
|
||||
self.say("Could not start " + bin)
|
||||
}
|
||||
None => self.say("No executable for " + id)
|
||||
}
|
||||
}
|
||||
Some(Launch(id)) => self.launch_catalog_app(id)
|
||||
Some(FocusWindow(n)) => self.actions.push(FocusWindow(n.to_int64().to_uint64()))
|
||||
Some(SetLayout(m)) => self.actions.push(SetLayout(m))
|
||||
Some(Logout) => self.actions.push(Logout)
|
||||
@@ -958,6 +961,10 @@ pub fn DesktopShell::right_click(self : DesktopShell, x : Int, y : Int) -> Bool
|
||||
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
|
||||
}
|
||||
Some(w) => {
|
||||
self.name_catalog()
|
||||
let rows : Array[MenuRow] = []
|
||||
@@ -1037,6 +1044,10 @@ fn DesktopShell::open_window_menu(self : DesktopShell, win : WinInfo, x : Int) -
|
||||
fn config_rows(items : Array[@wasm.ConfigItem]) -> Array[MenuRow] {
|
||||
let rows : Array[MenuRow] = []
|
||||
for it in items {
|
||||
if it.label.length() == 0 {
|
||||
// Kept by the module (e.g. the dock's pinned apps) but not a menu choice.
|
||||
continue
|
||||
}
|
||||
if it.choices.length() == 0 {
|
||||
let on = it.value == "on"
|
||||
rows.push({ ..menu_row(it.label, 4, arg=it.key), value: if on { "off" } else { "on" }, ticked: on })
|
||||
@@ -1141,6 +1152,7 @@ fn DesktopShell::menu_pointer_down(self : DesktopShell, x : Int, y : Int) -> Boo
|
||||
3 => self.open_module_settings(slot)
|
||||
4 => self.choose_module_setting(slot, row.arg, row.value)
|
||||
6 => self.actions.push(Window(row.window_id, row.window_cmd))
|
||||
7 | 8 | 9 | 10 => self.dock_menu_choice(slot, row)
|
||||
// A heading: the menu stays open.
|
||||
_ => self.menu_open = true
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user