# Desktop follow Link each Herdr space to a macOS desktop (Spaces). Switch spaces in Herdr and the linked desktop comes into view on its own, instantly and without the slide animation, while the cursor and keyboard stay in Herdr. A small block in the status bar shows the linked desktop: click it to pick one, or ⏸ to pause. Uses deskman for the switch. ![Desktop follow](preview.png) ## What you see - **The block**: about 160px wide and 28px high, at the right end of the bottom status bar, beside `workspace-status`. Same `chrome` background and 1px top `border` as the status bar, so the two read as one bar. Left-aligned, 12px side padding, 6px gap: a `🖥` glyph, then the linked desktop's name in 11.8px text, truncated. At the right end, a separate `⏸` button (8px side padding, full height, `dim`, `hover` background with `foreground` text); paused it shows `▶` in `accent`. Label color: `muted` normally, `dim` for `No desktop` / `…` / an unavailable desktop, `blocked` for warnings. Hover: `hover` background. - **The picker** (popup, 320px wide, `popover` background, 6px padding, 13px text): - A semibold title, `Desktop for `. - An optional red (`blocked`) line with the block's last warning. - Desktops grouped under `Display 1`, `Display 2`… (11px, `dim`). Each row: a 14px check column (`✓` on the linked desktop), the index (18px, `dim`), the name (`Desktop N` when unnamed), and `shown` (11px, `dim`) on the desktop each display shows now. Rows are 5px × 10px padded, rounded 4px, `hover` on hover. - `Unlink` at the end, only when the space has a link. ## How it behaves - Switching to a space with a link runs `deskman go --restore-cursor --restore-focus ` at once. The desktop changes with no animation; the cursor and keyboard focus stay in Herdr even when the desktop is on another display. - `⏸` pauses switching (`shared("desktop-follow.paused") = true`, kept across restarts): the label stays but turns `dim`, and space changes don't run deskman. `▶` resumes without jumping; the next space change switches. Errors that replace the label still show while paused. - Spaces without a link do nothing. The first render never switches, and neither does the render where spaces finish loading after "no active space", so opening Herdr or switching layouts moves nothing. - Fast switching: each switch gets a sequence number and only the latest result is shown. deskman itself lets the last request win. - Choosing a desktop in the picker links it to the space and closes the picker. It does not move there. Fullscreen spaces are not listed; a desktop with an empty UUID is listed as `(cannot be linked)` and can't be chosen. `No desktops to link.` when nothing remains. - The block refreshes its desktop list on every space change, when the current space's link changes, when clicked, and every 30 s (deskman doesn't notify renames). - Messages: `No desktop`, ``, ` ⚠` (soft failure: exit 2, 3, 5 or other; or the desktop is absent), `Missing desktop`, `Deskman not running` (exit 7), `No permission` (exit 4), `Update deskman` (exit 64, or exit 2 whose stderr mentions `--restore-focus`), `deskman not found` (exec rejected), `deskman output unreadable` (bad JSON). Clicking shows the detail in the picker. deskman's own stderr is never shown (it is Japanese). ## Built from - Layout: the status bar block becomes `row[ block workspace-status (flex), block desktop-follow (px 160) ]`, 28px high. - One mod, `mods/desktop-follow/`: `main.js` default-exports a `View` that is a `Bar` as a layout block and a `Popup` when `props().overlay` is set. `mod.json`: `{ "place": "none", "title": "Desktop follow", "overlay": { "kind": "popup", "width": 320 } }`. - `logic.js`, pure and tested with `node --test`: `decideSwitch(prev, current, links)`, `withLink`, `pickerGroups`, `barState`, `errorFor`, `parseList` / `listResult` / `goResult`. - `herdr`: `spaces()` (the `active` one), `shared` / `setShared("desktop-follow.links")` for `{spaceId: desktopUUID}`, `exec`, `openOverlay` (popup at the pointer, props `{space, detail}`), `closeOverlay`, `theme()`, `props()`. - Programs: `deskman list --json --all` (array of `{uuid, name?, index, display, visible, active, fullscreen, present}`) and `deskman go --restore-cursor --restore-focus `. ## Watch out - Render runs on every live-data change, and its `cx` must not start work: compare the active space in `render`, then start `deskman go` from `cx.timer.after(0, …)`. Start the `exec` in the timer callback itself, then await it in `cx.spawn`, so nothing delays the switch. - Treat both `undefined` and `null` as "no previous space", or Herdr switches desktops on start when spaces load after the first render. - Use `shared`, not `localStorage`: `localStorage` is per copy, so links would differ between layouts. - Install by copying the folder. Herdr does not reload a mod reached through a symlink. - Every copy of the block switches; put it in a layout once. Without `--restore-focus`, macOS hands focus to the other display's front window about 150–175 ms after the switch. - Same-display switching needs Herdr's window assigned to all desktops. ## Done when - `herdr-app check` passes and `npm test` is green. - The block shows `No desktop`; clicking it lists the desktops by display with `shown` on the visible ones. - After linking space A and space B to two desktops, switching between A and B in Herdr changes the desktop instantly, and typing goes to Herdr right after, also for a desktop on another display. - Restarting Herdr keeps the links and does not move the desktop. - Quitting Deskman.app and switching shows `Deskman not running`.