# Center canvas layout

Each layout occupies one top-level tab. Any tab content fits a pane: chat, web page, terminal, file preview, program view. The real limit on panes is [their minimum size](#dividers). Floating windows belong to picture-in-picture; a pane is never shared across windows.

## Layout tree

```
type LayoutNode =
  | { kind: "pane";  id: string; content: string | null }   // null = empty pane
  | { kind: "split"; id: string; dir: "row" | "col";
      children: LayoutNode[]; sizes: number[] };

type CanvasLayout = { root: LayoutNode; focusedPaneId: string; zoomedPaneId?: string };
```

| Rule | Detail |
| --- | --- |
| Normalisation, after each change | A split with one child becomes that child; a split with its parent's direction merges into it, weights multiplied; weights rescale and clamp to minimum size |
| Content | Appears once in a layout |
| Migration | A two-pane group becomes a row split with its saved ratio |
| Empty pane | Lists the strip's content; a click fills it |
| Focus | One pane; keyboard input, close, tiling shortcuts and right-sidebar context follow it |
| Fill | Stretches a pane over the canvas; others stay mounted, hidden |

Code: `apps/web/lib/tabs/canvas/canvas-layout.ts`.

## Pane grip

No persistent toolbar and no title bar. A `•••` grip sits top centre, with an 88×22px hit area. Pressing it never selects text and only prepares a drag: no store commit, focus or route change. A click focuses.

| Button | Click | Extra |
| --- | --- | --- |
| Red | Closes the tab through the strip's close | No menu |
| Yellow | Puts the pane back in the strip as its own tab; the session stays | No menu |
| Green | Opens the tab on its own | Rest 250ms: attached tiling menu, folds when the pointer leaves. `↓` on green or right-click on the grip: pinned menu. |

A press on a button that moves 6px becomes a drag and never clicks; pointer capture starts only with the drag. A closed pane leaves the layout in the click's frame and folds away as its neighbour grows into the space ([Closing](#closing)).

**Grip motion**

| Part | Motion |
| --- | --- |
| Sheet | Under the pointer the grip drops a grey sheet from the top edge, shoulders flaring into it, growing from a sliver with a slight spring |
| Dots | The window buttons at rest: they spread, grow one after another into red, yellow and green, then their glyphs fade in |
| Leaving | Runs it backwards |
| Menu | Grows out of the sheet as the grip widens; closing, it stays drawn 200ms to fold up before the grip narrows |

## Tiling menu

Mirrors the macOS green-button menu with small layout glyphs. A hint line names the glyph under the pointer, otherwise says to hold Option for quarters. On macOS it also names the shortcut; on Windows and Linux the tiling keys do not exist, the line names none, and Option reads Alt.

| Group | Items |
| --- | --- |
| Move and resize, this pane | Left, right, top, bottom halves; four quarters while Option is held. Others keep their order in the other half; a quarter fully held by another pane trades places. |
| Fill and arrange | Fill; left and right; left and stacked right; quarters. This pane first, contents in reading order, overflow to the strip, spare panes empty. |
| Return to previous layout | Leaves Fill, then steps back past the last tile, arrange, drop, equalize, close or divider drag. Entries are found by any tab or group involved, so a pane pulled out can be put back. |
| Equalize sizes | Panes take equal sizes |
| More layouts | Top and bottom, single, nine, sixteen, saved layouts, Save layout… |

## Shortcuts

| Keys | Action |
| --- | --- |
| `⌃⌥` + arrow | Tile the focused pane to a half. Control + Option because Fn + Control is macOS's. |
| `⌃⌥⇧` + arrow | Arrange left and right or top and bottom, focused pane on the arrow's side; alone, the other side is empty |
| `⌃⌥F`, `⌘⇧↩` | Toggle Fill |
| `⌃⌥R` | Return to previous layout |
| `⌘\`, `⌘⇧\` | Split right, split below |
| `⌘W` | Close the focused pane in a multi-pane layout |
| `⌥⌘` + arrow | Move spatial focus |

`⌘` is Control on Windows and Linux.

## Dividers

| Aspect | Behaviour |
| --- | --- |
| Look | Nothing until the pointer rests on the gap, then a short grey pill in its middle. The whole gap drags. |
| Minimum | Stops where a pane would drop below 240×160px; a smaller pane is never squeezed further |
| Snap | Within 10px of a third, half or two thirds; shows the ratio |
| Equalize | Double-click, adjacent pair |
| Keyboard | Arrows on a focused divider, 2% a step |
| Drag cost | `previewCanvas` repaints at most once a frame, in memory only; `setCanvas` commits once on release |
| Below 900px | While split, collapsed rails keep their columns so they never cover a pane |

## The split in the strip

A split window is one tab, as wide as any other, like Chrome's and Arc's split views: the focused pane's icon and title, a miniature of the split with that pane filled, and the pane count. Its close acts on the whole window.

A pane closed from a split that stays leaves the split's tab in the same tick as the click. When focus changes or a merge just formed the split, icon and name rise in over 200ms.

## Window overview

Modelled on Mission Control and the iPad app switcher. The center area recedes to the page colour and every window in the strip becomes a card on a grid, as large as fits, never wider than half the area.

A card keeps its window's split, drawn from the same tree and geometry. Panes have no drop zones: on a visible canvas the bottom half and corners were hard to tell apart.

| Opened by | Mode |
| --- | --- |
| A tab of the window on screen dragged out of the strip over that window (it cannot dock beside itself; back in the strip the overview closes), a grip starting to move | Drag |
| The button beside the main menu, pinching in on the center area or strip | Browse |

Any other tab dragged out of the strip keeps the window on screen and docks beside it there (`liveCanvasDropAt`), with the same zones as a card below.

| Pointer over | Result |
| --- | --- |
| Left or right quarter | Tab beside the whole window |
| Middle half | Above or below, by the half under the pointer |

| Release on | Result |
| --- | --- |
| The strip | Reorder; a pane returns to a standalone tab, with the same blue rounded preview as docking, following the strip's bounds |
| A card's zone | Merge with `dockCanvas(sources, card tab, "root", side)`. A pane on its own window's card moves to that half. The card grows, the half highlights, a hint names window and side. |
| Empty space | Opens on its own in the gap |
| Resources view | Binds the web page as a session resource |
| Beyond the window | Detaches into a new window |
| Escape, or back to the strip | Cancels; a plain reorder |

| Input | Result |
| --- | --- |
| Click a card | Switches to that window before the zoom, so the live window is ready underneath |
| Escape, pinch out | Zooms the current window back |
| Click outside | Closes |
| Click between cards | Nothing |
| Press and move 6px on a card, browsing | Picks up that window, or one pane of a split card, as a same-size copy; see-through over a card |
| Pinch on content that zooms | The context graph keeps the gesture |
| Pinch in on a web page | `main/web-views/webtab-preload.js` (isolated world, exposes nothing) opens the overview only if the gesture starts at `visualViewport.scale` 1. Pinching out magnifies natively, 1× to 3×; pinching in on a magnified page only zooms it back. |

The overview covers only the center area and is a native-view occluder. As in Mission Control nothing marks the current window. Browsing keeps the hint's room, hidden.

**Pictures on the cards**

| Aspect | Behaviour |
| --- | --- |
| Store | Per tab, in memory and IndexedDB (`lib/tabs/canvas/window-snapshots.ts`), one theme only: a theme change drops them all and other-theme ones are not restored, since a card flashed against the live window. An empty tab list while the store loads never prunes. |
| Taken | Before any overview opens, the dragged tab's pane included (its preview hides); 900ms after a switch or layout change; when the App loses focus or hides; every 30s after 5s with no input |
| Page panes | `window:capture-region` IPC, a window's main page capturing itself only; JPEG at most 720px wide |
| Web panes | From their own views, so off-screen ones stay current. A view holds the page only, so an on-screen pane is pictured as its region with the page drawn into `[data-web-frame]`; the toolbar band is kept and frames off-screen pages, keeping the pane's proportions. |
| Card shape | Its window shrunk whole: a lone pane flush (1rem corners), split panes 1px inside their slots (16px corners), all at the card's scale so nothing jumps on landing |
| Clean content | Grips are hidden for the two frames before a capture |
| Never pictured | Only the tab's icon, centred; the name is the card's caption |

**Dragging over the overview**

| Part | Behaviour |
| --- | --- |
| Source tab's slot | `data-drag-out` closes it by width (flex-basis, width, padding to 0, 8px gap taken back) in 160ms, so later tabs and + slide over. It stays closed through a merge or a move to another window; reopens with `data-slot-reopen` only when the tab stays. |
| Dragged tab | A small window under the pointer: tab on top, last picture below, 240px wide, 110 to 190px tall, opening in 200ms, folding back in 140ms over the strip. Never pictured: stays a tab, opens if a picture arrives. |
| Cards | The tab leaves its own card; a card with no tab disappears; the card under the pointer grows slightly |
| Gap | `slot` in the overview store, where the tab would stand alone. Starts at the dragged window, or just after the window a pane leaves. Cards are sized for cards plus gap, so a pick-up resizes nothing. Off the cards it stays while nearer than any card, else goes beside the nearest card on the pointer's side; distances use layout offsets, without framer-motion transforms. Outlined over empty space. |
| Drop in the gap | Carries `before`; `commitCanvasDrop` calls `moveTab` (after ungrouping a pane) or `moveGroup`, so the strip takes the overview's order. Only a pane out of a split is activated. The overview stays open browsing: `holdOverviewLanding`, then `sourceIds` clears and the tab's card returns. |
| Dragging a card | Goes through `overviewDropAt` like any drag: a card's side merges, empty space moves the window to its gap (a pane gets its own window), anything but a merge browses on (`browseOverview`); Escape cancels. |
| Modes | Same area and buttons, so pictures survive a switch; no replayed fade (`data-opened-as`); empty space tints only the hint |
| Motion | Open or close zoom is a framer-motion layout animation, 340ms, a placeholder holding the slot; drag overviews fade in. Grid changes use a layout spring; new cards grow in where they land, only on mount. |
| Strip after a merge | `placeDockedTabs` moves docked tabs before the window they join, so the split keeps that window's slot |

**Landing a merge**

One zoom, begun at the release. The commit waits on the desktop shell's transfer cancel (about 50ms) and a render of the split (about 40ms), so waiting would show a gone window and an unchanged card for some 90ms.

1. The release holds the overview, notes the drop and tabs, and sets `landing`. The target card grows from its grid place over the center area in 340ms, one uniform-scale transform that plays through the wait. Its window activates underneath, so panes are loaded by the time they make room.
2. `commitCanvasDrop` hands the merge to `landOverview`, which holds it and marks `landed`.
3. Landed and under way (about a tenth of a second in), the overview reads each pane's rect in the zooming card, converts to the canvas's unscaled frame, and passes rects plus zoom start, curve and progress to `captureCanvasLanding`.
4. It closes, applying the merge in the same tick. A fallback timer applies it too, unanimated.
5. The shell plays the capture: panes animate real geometry into the split; the docked tab enters from the drop side at final size, translated out and clipped at the canvas edge (`clip-path`), same 300ms, so the seam moves as one and content never re-wraps.
6. Measured unscaled first, the canvas root takes over the zoom with the same keyframes and the card animation's own `startTime`, one clock, on live content rather than blurry JPEGs.

| Detail | Rule |
| --- | --- |
| `startTime` | Set explicitly at creation: a compositor animation otherwise stays pending to the main thread |
| `data-canvas-landing` | Keeps the centre column open page meanwhile |
| Other cards | Fade in 80ms; the hint fades but keeps its room, so the grid does not re-centre |
| Failed merge | The shell keeps the tab: the overview closes at once |

## Layout animation

Rearranging animates as macOS moves windows: green, the tiling menu, Fill, Return to previous layout and a drop (`lib/tabs/canvas/canvas-transition.ts`). Closing a pane animates too ([Closing](#closing)). Reduce Motion skips it; divider drags do not animate.

| Pane | Animation |
| --- | --- |
| Stays | Real geometry (`left`, `top`, `width`, `height`) through Web Animations, 300ms, so text re-wraps; inline `calc()` untouched |
| Arrives | Fades in |
| Hidden | A pane that green, Fill or an arrangement with fewer panes hides fades under the one growing over it |
| Closed | Folds toward the side it stood on, clipped (`clip-path`) on the same 300ms curve as the pane growing into its room, so the edge between them moves as one |

**How it plays**

| Part | Detail |
| --- | --- |
| Record | Just before a change the canvas records each pane's rect by tab id and keeps a still copy. The shell plays it in the layout effect of the committing render, before paint. A record no commit follows lapses after 1.5s. |
| Matching | By tab id, so a session moving from peer pane to lone chat shell still animates. The hidden shell switches to the remaining session in the layout's tick, not renders later. |
| Transcripts | Fade in only when rows arrive after a switch; a message row's appear animation runs only within a second of arrival, so remounts show as they are |
| During the move | Counts as dragging: web panes show snapshots, chats re-wrap rows in view only; frames and dividers fade out and back |

## Closing

Red and yellow change the layout in the click's frame: the tab, the strip and the focus are final at once. On the canvas the closed pane then folds away while its neighbours grow into its room. Nothing waits for the animation, and nothing waits for a save.

| Part | Detail |
| --- | --- |
| Layout | One store commit removes the pane. The capture taken just before it copies only the closing pane, never the chat beside it. |
| Fold | Toward the side away from the pane that takes the room: a right pane folds to the right edge, a bottom pane to the bottom. A pane nobody grows into fades instead. |
| Web panes | Show snapshots for the 300ms, as in any layout animation. The closed tab's view is destroyed after the commit (`destroyStaleWebViews`). |
| Files | The tab goes at once whatever the document needs. Its pane stays mounted out of sight (`lib/tabs/panes/held-file-panes.ts`), folding first where it stood, until the document is saved and its editor closed. |
| A save that fails | Shows a toast with **Open** and never brings the pane back by itself: the file may have moved or changed on disk. The edit stays in the draft store and is offered when the file opens. |
| Unchanged files | Closing writes only changes the editor reported. A file nobody changed is closed without writing anything back over it. |
| Unsaved changes | Edits the file does not hold yet (a draft, an Office edit not yet exported, a failed save) are asked about first, as PowerPoint asks: **Save**, **Don't Save** or **Cancel**. One question covers every file the close takes. |
| Don't Save | Drops the draft and the editor's edits; nothing is written. Cancel keeps the tab. |
| Reopened meanwhile | The same file opened again while that release runs gets a fresh document, which the release never closes |
| Programs | The application's close request is sent without waiting for it |
| Chat beside it | Moves from its peer pane to the chat shell under the same tab id, so it grows from where it stood |

Why a save never holds the close: an Office deck is exported whole and uploaded on close, which takes seconds, and a file that an agent moved or rewrote meanwhile cannot be saved at all, which left a pane that could not be closed.

## Drag lifecycle

The canvas will host many small app windows, so every drag ends cleanly and leaves other panes alone.

| Case | Handling |
| --- | --- |
| Any end | Release, Escape, pointercancel, window blur or a drop-lookup error run one cleanup once: label and cue go, grip returns, capture released, `data-canvas-dragging` cleared. A failed lookup is no drop. |
| Missed release | Over the window-drag strip, a native view or another app the page gets no pointerup. Each drag registers with `setCanvasDragging(true, owner)`; the first pointermove with no button down is the release; a new press cancels the old drag. No `-webkit-app-region: drag` while dragging. |
| Grip state | `data-pane-dragging` hides it through CSS, never inline; a new drag clears any stale one |
| Native web view | Captured first, hidden on arrival or after 160ms, so no paused card flashes |
| Drop cue | No backdrop blur; 120ms ease-out with no overshoot |

## Rendering and native views

- Recursive geometry feeds stable content hosts: tree edits and zoom do not reparent file editors, terminals or sessions.
- A pane under 150×110px shows its title and type with a zoom action.
- Each web pane reports its own bounds (`registerVisibleWebTabBounds`). While dragging, undersized, or beyond eight visible native views, a pane shows its captured image. Selecting a paused view gives it priority. Hidden views stay alive; no process ends.

## Persistence

The window's tab payload stores each group's tree, focus and zoom, with tab references only. Missing references become empty panes. Cross-window payload validation bounds tree depth, node count and serialized size independently of the layout editor. Resources attachment uses its existing backend ownership operation.

## Implementation status

Implemented: everything above.
