mirror of
https://github.com/storytold/wordcraft.git
synced 2026-12-04 22:49:54 +00:00
* Closing document windows: file.close save, ui.closeWindow window, prompt raised on window focus (#7822) Spec rules 3, 5, 6 and 8 of docs/specs/multi-window-close.md that the close-owner work (#8277) left open, with a test each. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx * Review fixes: file.close save keeps the comment-draft refusal; drop redundant focus hunk (#7822) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx * ADR 0001: X11, XWayland and BSD on X11 keep a visible root (amendment) egui's windowless root returns UnsupportedConfiguration there; WordCraft falls back to the windowed root. The close rules still apply. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx * Repin craft-libs to 5299d8d9 (windowless root support, IconPicker previews, CellGrid fix) craft-libs d73e274a -> 5299d8d9 (every craft-libs rev, craft-nightly and the patches), egui 07c20531 -> 399fc6e0, winit 0dfcec0e -> 3fd7ae64, the revs craft-libs main builds with. Cargo.lock updated for those packages only. Adapt to the hosted unsaved-changes question: the dialog host takes HostedUnsavedChangesDialog, not UnsavedChangesDialog. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx * Windowless root: every document window is a child; X11 keeps the visible root (#7822) Use eframe's RootViewportMode::Windowless with InstallSpec::windowless_root unless the session is X11, and fall back to the visible root on UnsupportedConfiguration. active_viewport/viewports no longer fall back to ROOT when windowless; close_decision closes when no documents remain; a window that failed to open is dropped and the user told; ui.closeWindow replies requested:false while a Save prompt is open. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx * Windowless root: save window place every frame, raise Save prompt on sole-window close (#7822) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx * fix(windows): save on window-only file.close; point ui.closeWindow docs at ui.inspect; document save scope (#8624) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx * ADR 0001: X11 keeps #7752; dialogs have no parent under the windowless root Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx * Windowless root: only the first window takes the saved place; a promoted survivor stays put (#7822) Reported on macOS: closing the first window moved the surviving window to the first window's saved place. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx * Windowless root: files dropped on a document window reach the intake (#7822) eframe runs raw_input_hook only for the root and deferred viewports; document windows are immediate viewports, so under the windowless root no drop reached the app. A viewport hook forwards child-window drops. Pointed out by Skylar (windowless/default-on-reference). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
294 lines
28 KiB
Markdown
294 lines
28 KiB
Markdown
# Control protocol
|
||
|
||
> **Last updated:** 2026-11-26 · The methods as the control channel answers them since the craft framework port (#7101): `ui.type`, `ui.click` with `hold`, `ui.release`, the `command` modifier, wheel units `points` and `lines`, the screenshot reply's `base64`, the methods the table was missing, and an idle connection closing after 30 s. Earlier: `wordcraft-cli mcp --connect` is refused for now (#7124); the token section describes the bridge for when it returns. Earlier: The control channel authenticates once per connection with a token (`auth`), replacing the per-request key. Earlier: Correct the force-close request envelope and document the optional command search parameter; command behavior unchanged. #6146: scroll speed preferences (`ui.scrollSpeed`, `ui.touchpadScrollSpeed`); #6159: refuse ui.screenshot on secondary document windows and support root window selection with view.switchWindows.
|
||
|
||
Start the app with a control port: `wordcraft --control 7981` (or `WORDCRAFT_CONTROL_PORT=7981`).
|
||
A missing or invalid port after `--control` (not 1–65535) prints an error and exits with status 2.
|
||
It listens on `127.0.0.1` only. Authenticate once per connection with the window's token (see
|
||
[Token](#token)), then send one JSON object per line; each gets one reply line:
|
||
|
||
```json
|
||
{"id": 1, "method": "auth", "params": {"token": "…"}}
|
||
{"id": 1, "ok": true, "result": {"authenticated": true}}
|
||
{"id": 2, "method": "engine.execute", "params": {"command": "text.insert", "params": {"text": "Hello"}}}
|
||
{"id": 2, "ok": true, "result": {"anchor": {...}, "focus": {...}}}
|
||
```
|
||
|
||
Errors come back as `{"id": …, "ok": false, "error": "message"}`. A failed command leaves the
|
||
document unchanged. Before authentication, a line that isn't a valid `auth` gets
|
||
`authentication required` and the server closes the connection (so an HTTP request sent to the
|
||
port can't run a command). After it, a line that isn't valid JSON gets a `bad JSON` error and the
|
||
connection stays open.
|
||
|
||
## Token
|
||
|
||
Any local program (and possibly a web page) can reach a loopback port, so every connection must
|
||
authenticate with the window's token. Unless a token is supplied (below), once the port is bound
|
||
the app writes a random token (256 bits, as hex) to
|
||
`<settings>/control-key.<instance>` and removes the file when the window closes; a new start
|
||
writes a new token. `WORDCRAFT_PROFILE_DIR` overrides the whole profile folder for isolated runs,
|
||
including recovery copies. See [local recovery](recovery.md). `<settings>` is the folder that holds the preferences: on Linux
|
||
`$XDG_CONFIG_HOME/wordcraft` (by default `~/.config/wordcraft`), on macOS
|
||
`~/Library/Application Support/WordCraft`, on Windows `%APPDATA%\WordCraft`. `<instance>` is the
|
||
Flatpak instance id inside Flatpak, and `local-<port>` otherwise. On Unix the file has mode 0600.
|
||
|
||
```sh
|
||
cat ~/.config/wordcraft/control-key.local-7981 # Linux, outside Flatpak, port 7981
|
||
```
|
||
|
||
To choose the token, pass `--control-token <hex>` or `--control-token-file <path>` (or set
|
||
`WORDCRAFT_CONTROL_TOKEN` or `WORDCRAFT_CONTROL_TOKEN_FILE`; the port is `--control <port>` or
|
||
`WORDCRAFT_CONTROL_PORT`). The two are alternatives, and a token file you name is not removed on
|
||
exit.
|
||
|
||
- Send `{"method": "auth", "params": {"token": "…"}}` as the first line of every connection
|
||
(reply `{"ok": true, "result": {"authenticated": true}}`); later requests carry no token. A
|
||
challenge handshake (`auth.challenge`, then `auth` with a proof) proves the token without
|
||
sending it.
|
||
- Any other first line, or a wrong token, gets `authentication required` and the app closes the
|
||
connection. A second `auth` gets `already authenticated`; the connection keeps serving.
|
||
- A line over 1 MiB gets an error reply, and the app closes the connection.
|
||
- A connection that has not authenticated within 10 s of being accepted is closed, whatever it
|
||
sends. After that, a connection idle for 30 s is closed.
|
||
- At most 16 connections are served at once; the next one gets `connection limit reached`.
|
||
|
||
`wordcraft-cli mcp --connect` is refused for now, until the app confines this channel to automation
|
||
roots (#3695, #5819; see [docs/mcp.md](mcp.md)). When it returns, it takes the token from
|
||
`WORDCRAFT_CONTROL_TOKEN`, or else from the
|
||
token file for the port it connects to, and reads it again on every new connection (the app may
|
||
have restarted). It sends the token only to the app's own address, `127.0.0.1` (`localhost`
|
||
connects there too, never to `::1`): another loopback address such as `::1` or `127.0.0.2` is not
|
||
where the app listens, so whoever listens there gets no token (#3699). For
|
||
any other host it sends nothing and says why: to drive an app on
|
||
another machine, forward its port to `127.0.0.1` (for example `ssh -L 7981:127.0.0.1:7981 host`)
|
||
and set `WORDCRAFT_CONTROL_TOKEN` to that app's token.
|
||
|
||
## Delivery and startup failures
|
||
|
||
If the accept thread cannot start, startup reports that the control server is off and removes
|
||
its newly written token file; it does not report a listening server.
|
||
|
||
A client that encounters a write error or a lost reply must treat delivery as unknown once it
|
||
has attempted to send. The MCP bridge does not replay mutations in this case, or image exports
|
||
with a string `path`; see [delivery failures](mcp.md#delivery-failures).
|
||
|
||
A request that times out while still queued is cancelled and cannot run later. If execution
|
||
has already started, the timeout reports an unknown outcome rather than promising cancellation.
|
||
|
||
## View › Window
|
||
|
||
The app's native windows (one per document, or several on one document) take part in View ›
|
||
Window (#322): `view.arrangeAll` tiles them over the monitor, `view.sideBySide {value?, window?}`
|
||
places this window and another one in the left and right halves and turns on Synchronous
|
||
Scrolling, `view.syncScroll {value?}` turns that on or off, and `view.switchWindows {id?, window?}`
|
||
lists documents and switches documents or windows. For Side by Side, `window` is an id from
|
||
`ui.inspect` → `windows.others` and is optional when only one other window is open. For Switch
|
||
Windows, `window` is an open window's key. A secondary-window screenshot refusal can include
|
||
the root window key in the suggested `view.switchWindows` command. The
|
||
commands are disabled where there is one window (web, CLI, MCP without the app). Wayland doesn't
|
||
let apps move windows, so there Arrange All and Side by Side only resize.
|
||
|
||
## Methods
|
||
|
||
| Method | Params | Result |
|
||
|---|---|---|
|
||
| `engine.execute` | `command`, `params`, `doc?` | the command's result (any id from `engine.commands`, and these UI commands, which it doesn't list: `ui.tab`, `ui.dialog` (`{"name": dialog, "part"?: table style part}`; `part` opens New / Modify Table Style (`newTableStyle` / `modifyTableStyle`) on that part: `wholeTable`, `headerRow`, `firstColumn`, `bandedRows`, `nwCell`… as `table.modifyStyle` names them), `ui.backstage`, `ui.zotero.*` (see `docs/zotero.md`), `ui.language` (`{"value": "auto"\|code}`; no value reads it; the result's `available` lists the codes and names of the interface languages this build has, English only in a build without craft-i18n), `ui.theme` (`{"value": "system"\|"light"\|"dark"}`; `system` follows the OS appearance, light when it reports none), `ui.interfaceSize` (`{"value": "auto"}` or `{"percent": 50–300}`, clamped; no value reads it; `auto` keeps the system display scale, capped so a window of at least 900x460 points fits the screen (#4030), a percentage is absolute, so 100 is one screen pixel per point (#822); the result's `percent` is the size drawn at and `auto` whether it follows the system; document zoom stays `view.zoom`), `ui.animations` (`{"value": "system"\|"on"\|"off"}`; no value reads it; the result's `animations` is the configured choice; `system` is a boolean indicating whether the OS allows animations, read on Windows, macOS, Linux and the BSDs, or from `prefers-reduced-motion` on the web, and defaults to `true` when no preference is reported; `enabled` is the effective animation state. With `animations: "system"`, the desktop app disables animations when it detects a CPU graphics adapter, even when the OS allows them. The result can then be `{"animations":"system","system":true,"enabled":false}`. On the web, System follows the browser's motion preference even if the browser renders in software. Explicit `on` and `off` still apply on both hosts), `ui.fileBrowser` (desktop: `{"purpose": "document"\|"picture"\|"recipients"\|"save"\|"export"}` opens WordCraft's own file browser, for when the system file dialog doesn't show up, #576; `export` offers File › Export's formats as its types, #3535), `ui.saveAsTemplate` (File › Save As › Save as Word Template: the Save dialog for a `.dotx`, starting in the user templates folder; the result's `dir` is that folder, `null` on the web, #2852), `ui.caretAnimation` (`{"value": true\|false}`; no value reads it; off, the caret jumps and blinks on and off instead of gliding and fading), `ui.startScreen` (`{"value": true\|false}`; no value reads it; on, the default, the desktop and web apps start on File › Home when launched with nothing to open, #766), `ui.alignmentGuides` (`{"value": true\|false}`; no value reads it; on, the default, moving a picture or shape snaps it to the page, the margins and other objects, with guide lines while dragging; Alt moves freely), `ui.quickAccessToolbar` (`{"value": true\|false}`; no value toggles it; false takes the Quick Access Toolbar out of the title bar, as its menu's Hide Quick Access Toolbar does, and true brings it back, #1945), `ui.displayServer` (`{"value": "auto"\|"wayland"\|"x11"}`; no value reads it; File › Options › Advanced › Linux display server, which the desktop app reads on Linux and the BSDs at its next launch; `WORDCRAFT_WAYLAND` overrides it, #2184), `ui.scrollSpeed` (`{"value": "slow"\|"normal"\|"fast"}`; no value reads it; mouse-wheel scroll speed, #6146), `ui.touchpadScrollSpeed` (`{"value": "slow"\|"normal"\|"fast"}`; no value reads it; scales touchpad scrolling on Wayland: slow 2×, normal 4×, fast 8×; on macOS: 0.5×, 1×, 2×; File › Options › Advanced › Scrolling › Touchpad scroll speed, #6146), `ui.statusCount` (`{"value": "words"\|"characters"\|"charactersNoSpaces"}`; no value reads it; what the status bar's count shows — words (the default), characters with spaces, or characters without spaces — kept between runs, #2797), `ui.recentRemove` (`{"path": entry}` takes that document off the recent list — `path` must be an entry on the list; on the desktop the new list is saved right away: the result's `saved` is true then, false with `saveError` when the write failed (the removal still holds for this run) and null where the host keeps no preferences (the web app, or preferences switched off), #2716), `ui.recentClear` (`{}` clears the whole list; the result reports `removed`, the new `recent` and `saved` as above), `ui.focusRibbon` (`{"value": true\|false}`; no value toggles it; in Focus, true drops the ribbon down over the page, as the bar's ⋯ does, and false puts it away, as a click on the page does; outside Focus it stays put away, #1678), `ui.contextMenu` (opens the page's context menu below the caret, as Shift+F10 does), `ui.paneDock` (`{"pane": "navigation"\|"clipboard"\|"styles"\|"styleInspector"\|"accessibility"\|"altText"\|"formatShape"\|"restrictEditing"\|"proofing"\|"comments"\|"smartArtText", "dock"?: "left"\|"right"\|"float", "before"?: pane\|null}`; no `dock` reads it; docks or floats a task pane as its menu does, kept between runs; Styles is `view.stylesPaneDock`, #1756; `before` puts the pane directly before that pane in the order, outside it on their edge, as a drop over a docked pane's outer third does, and `null` after every pane; the order is kept between runs)…) |
|
||
| `engine.commands` | `search?` | every command: id, label, location, shortcut, params, enabled |
|
||
| `document.inspect` | `text?`, `doc?` | blocks (text, style, runs, lists, tables), parts, sections, selection, pages |
|
||
| `ui.inspect` | — | UI state, view, window size, page rects on screen, caret, the selected comment balloon (`balloon`), perf; `dialogs`: the open dialogs (`id`, `parent`, `key`, `fields`), the top one last; `windows`: the other windows as the drawn window sees them (`available`, `current`, `others`, `sideBySide`, `syncScroll`); `document`: the active document's id; `documents`: the open documents (`id`, `title`, `path`, `dirty`, `active`) |
|
||
| `ui.click` | `x?`, `y?`, `coordinates?`, `page?`, `control?`, `button?` (`left`, `right`, `secondary`, `middle`), `count?`, `hold?`, modifiers; or the `id` or `label` of a `ui.accessTree` node (with optional `button?`: `left`, `right`, `secondary`) | real pointer input at the target point or node; `hold: true` keeps the button down until `ui.release` |
|
||
| `ui.clickText` | `page` (0-based), `x`, `y` (points from the page's top-left), `count?` | click inside a page; replies at once with `screen`, the window point it clicks (`[x, y]`), before the click is processed |
|
||
| `ui.move` | `x`, `y`, `coordinates?`, `page?`, `rest?` (0–10 s), modifiers; or the `id` or `label` of a `ui.accessTree` node, `rest?`, modifiers | pointer move (to the point, or to the centre of the node's rect); `rest` waits that many seconds before replying; with a button held (`ui.click` with `hold`), a drag you can screenshot halfway |
|
||
| `ui.drag` | `from`, `to` (each `{x?, y?, coordinates?, page?, control?}`), `button?` (`left`, `right`, `middle`), `steps?` (1–200, default 12), modifiers | one-request drag: presses at `from`, moves in even `steps` to `to`, and releases |
|
||
| `ui.release` | `button?` or `key?`, `x?`, `y?`, `coordinates?`, `page?`, `control?` | lets go of what `hold` keeps down (with neither `button` nor `key`, everything, modifiers too). A drag you can pause or screenshot halfway is `ui.click` with `"hold": true`, then `ui.move`, then `ui.release` |
|
||
| `ui.wheel` | `x?`, `y?`, `coordinates?`, `page?`, `control?`, `dy?`, `dx?`, `unit?` (`points`, the default, or `lines`), modifiers | mouse-wheel or trackpad scroll at the target point (`dy` < 0 scrolls down) |
|
||
| `ui.key` | `key` (`B`, `Enter`, `Left`…), `hold?`, modifiers | key press through egui (shortcuts apply); `hold: true` keeps the key down until `ui.release` |
|
||
| `ui.type` | `text` | typed text through egui |
|
||
| `ui.ime` | `preedit` with `cursor?` (`[start, end]` in its characters), or `commit` | input-method composition: the text being composed, or the text it commits |
|
||
| `ui.capsLock` | `on` (`true` or `false`; `null` returns it to the keyboard's own state) | Caps Lock for the input that follows |
|
||
| `ui.drop` | `paths`, `hover_only?`, `x?`, `y?`, `coordinates?`, `page?`, `control?` | files dropped on the window there (where the pointer is without `x`, `y` and `control`), as from a file manager; `hover_only` only holds them over it |
|
||
| `ui.screenshot` | `path?`, `region?` (`[x0, y0, x1, y1]` in points) | PNG of the window (or of `region`) in the root viewport: written to `path` (a `.png` file), or without one returned in the reply as `base64`, with `mime`, `width`, `height` and `pixels_per_point`. Capturing a secondary document window is not supported by the viewport renderer; select the root window with `view.switchWindows {"window": root}` first |
|
||
| `ui.render` | `path?`, `page?` (1-based), `scale?`, `doc?` | PNG of a page, rendered by the engine: written to `path`, or without one returned as base64 `png` in the reply (never a fixed name in the shared temporary folder) |
|
||
| `ui.parity` | — | feature-catalog parity |
|
||
| `ui.resize` | `width`, `height` | asks for that window content size in points; sizes that aren't positive and finite are refused, the rest are clamped to the app's minimum (600 × 480, #5886) and to the largest surface the GPU can draw (at most 16384; that limit wins over the minimum), and the reply's `width` and `height` are the size asked for |
|
||
| `ui.focus` | the `id` or `label` of a `ui.accessTree` node | gives that control keyboard focus |
|
||
| `ui.accessTree` | — | the window's accessibility tree: `nodes` (`id`, `role`, `name`, `value`, `children`…), `focus` and `root` |
|
||
| `ui.dialog.set` | `dialog` (an `id` from `ui.inspect`'s `dialogs`, or `"top"`), `field` and `value`, or `fields` (`[{"field", "value"}]`, all or none) | sets the dialog's fields |
|
||
| `ui.dialog.confirm` | `dialog`, `choice?` (which button of a prompt) | answers OK, as the default button does |
|
||
| `ui.dialog.cancel` | `dialog` | closes the dialog, as Escape does |
|
||
| `ui.closeWindow` | `window?` | the close button of the window with that key (from `ui.inspect` → `windows`: `current`, `others[].id`), the active window by default: unsaved work brings up the Save prompt in that window; the reply's `requested` says whether the close was asked for (false while a Save prompt is already open: answer it first); errors "no document window is open" when only the windowless root remains |
|
||
| `ui.clipboard` | `text?`, `html?`, `rtf?`, `png?` (base64) | puts those flavours on the clipboard; the reply's `offered` lists them |
|
||
| `ui.replayAt` | `at` (0–1) | holds Ink Replay at that fraction of its length, while Ink Replay is on |
|
||
| `app.quit` | `force?` | quits (see [Closing the document](#closing-the-document)) |
|
||
|
||
Pointer positions default to window points (`coordinates: "screen"`). `coordinates: "document"` maps
|
||
page points through the canvas with `page?` (0-based, default `0`). `control` (`{name, role?,
|
||
within?, index?}`) places the pointer at the centre of the matching `ui.accessTree` control plus an
|
||
optional `x`, `y` offset (default `0`), and excludes `coordinates`; `ui.click`, `ui.release`,
|
||
`ui.wheel` and `ui.drop` resolve `control`, whereas `ui.move` requires `x` and `y` when no `id` or
|
||
`label` is given (it allows `control` as a field name, though `x` and `y` still set the point).
|
||
|
||
Modifiers are `shift`, `alt`, `command` (⌘ on macOS, Ctrl elsewhere) and `ctrl` (the Control key on macOS), each `true` or `false`.
|
||
|
||
Any other method name is treated as a command id: `{"method": "format.bold"}` works.
|
||
|
||
**Task pane docking.** `ui.paneDock` and `view.stylesPaneDock` use **physical** `left` / `right`
|
||
(the window's left and right edges), matching Dock Left / Dock Right in the pane menu. That stays
|
||
true in a right-to-left interface language: `{"dock":"left"}` always puts the pane on the physical
|
||
left and the command reports `"left"`. A pane that has never been docked keeps its default
|
||
start-/end-edge role when mirrored: start-default panes (e.g. Navigation) open on the physical
|
||
right in Arabic, end-default panes (e.g. Comments) on the physical left. Saved docks and explicit
|
||
requests are never flipped.
|
||
|
||
Language packs (see [MCP](mcp.md#language-packs)) are commands like any other: `proof.packs`,
|
||
`proof.installPack {"locale": "nl"}` and `proof.removePack {"locale": "nl"}`. Through the control
|
||
channel they act on the running app's packs, and install only while its downloading setting is on;
|
||
they never turn it on, and neither does a `ui.click` or `ui.key` on the app's Install, Add a
|
||
language… or Refresh buttons. An install or a refresh runs in the background
|
||
(`"started": true`); `proof.packs` reports its progress, then the result.
|
||
`ui.dialog {"name": "languageData"}` opens About › Language data.
|
||
|
||
### Open documents
|
||
|
||
Several documents can be open at once. Each has an id, a whole number that stays the same while
|
||
the document is open and is never reused by the running app. On the desktop each open document
|
||
has a native window of its own; the web app shows them one at a time in its one window. One
|
||
document is the active one: on the desktop, the document of the window focused last (the active
|
||
window); in the browser, the one the window shows. Commands work on it unless told otherwise.
|
||
|
||
- `file.new` opens another document in a new window, focused, and makes it active. `file.open`
|
||
does the same with a file; it replaces a blank document nobody has used yet in that document's
|
||
window, and a file that is already open becomes active again and its window comes to the front
|
||
(`"alreadyOpen": true`). Its result carries the document's `id`.
|
||
- `view.switchWindows` lists the open documents (`{"documents": [{"id", "title", "path",
|
||
"dirty", "active"}]}`); with `{"id": n}` it makes that document active and brings its window to
|
||
the front. With `{"window": key}` it selects that window directly and brings it to the front.
|
||
- `file.closeDocument {"id"?, "force"?}` closes a document; its window closes with it unless it
|
||
is the last window.
|
||
- `engine.execute`, `document.inspect` and `ui.render` take `doc`, the id of the document to work
|
||
on, next to their other params. The command runs on that document and the active window stays
|
||
active. A dialog or page the command opens (Save As, Print) opens in that document's window,
|
||
which comes to the front:
|
||
|
||
```json
|
||
{"id": 2, "method": "engine.execute", "params": {"command": "text.insert", "params": {"text": "Hello"}, "doc": 3}}
|
||
```
|
||
|
||
`doc` left out, or `null`, is the active document. An id that names no open document, or a value
|
||
that isn't a whole number from 0 up, is an error and nothing runs. Window commands (`ui.*`) work
|
||
on the active window only: with the id of another document they are an error.
|
||
|
||
### The active window
|
||
|
||
Input and window methods go to the active window, the one focused last: `ui.click`, `ui.key`,
|
||
`ui.type`, `ui.wheel` and the other input methods (coordinates are that window's),
|
||
`ui.screenshot` (a PNG of that window), `ui.inspect` (its size), `ui.resize` and `ui.focus`. To
|
||
work in another window, make its document active first with `view.switchWindows {"id": n}`.
|
||
|
||
`ui.screenshot` is the exception when multiple document windows are open: the desktop renderer
|
||
captures only the window in the root viewport (the first window opened, until that window closes and
|
||
another is adopted in its place). While the active window is a secondary document window in a separate
|
||
native viewport, `ui.screenshot` returns an error directing the caller to select the root window
|
||
instead of hanging for 8 seconds and timing out. Select the root window with
|
||
`view.switchWindows {"window": root}` and request the capture again. The error gives the root
|
||
window key when it is available.
|
||
|
||
The `CharProps` and `ParaProps` that `format.set`, `para.set` and `styles.modify` take are listed
|
||
in [MCP server](mcp.md#character-and-paragraph-properties).
|
||
|
||
Positions are `{"story": "body" | {"part": n}, "path": [block, row, cell, block, …], "off": byteOffset}`.
|
||
|
||
### Keyboard and text input
|
||
|
||
`ui.key` and `ui.type` go to this window's focused widget even when another app is in front
|
||
(#2420). A focused Find field receives the text; a document receives it only while its canvas
|
||
owns keyboard focus. Shortcuts, dialogs and document protection still apply. These methods do
|
||
not activate the native window.
|
||
|
||
`ui.click`, `ui.move`, `ui.drag`, `ui.release`, `ui.wheel`, `ui.key`, `ui.type`, `ui.ime`,
|
||
`ui.capsLock`, `ui.drop` and `ui.focus` defer their successful replies (`"result": null`). The current app
|
||
can send a deferred reply during the final input pass, before the UI has applied that pass.
|
||
`ui.clickText` replies at once with the window point it clicks (`"screen": [x, y]`), before
|
||
the click is processed. `ui.type` sent after it is queued behind the click, but other requests,
|
||
such as `ui.inspect` or `engine.execute`, can run before the click lands. `ui.click` with
|
||
`"coordinates": "document"` and the same `page`, `x` and `y` clicks the same point and defers
|
||
its reply. Check that the resulting document or widget state is the one expected before
|
||
continuing with an operation that depends on it; do not replay an edit merely because its
|
||
effect is not yet visible.
|
||
|
||
### Closing the document
|
||
|
||
`engine.execute` never shows the Save / Don't Save / Cancel prompt, so a command that would
|
||
discard unsaved work is **refused with an error** (the app keeps running and the edits stay);
|
||
save first (`file.save`), or pass `{"force": true}` to discard the changes and go ahead.
|
||
|
||
`file.close` closes the shown document, so it is refused while that document has unsaved
|
||
changes (`unsaved changes: pass save or force`); `{"save": true}` writes it first (a document with no
|
||
file yet is an error, never a prompt) and then closes it; the bare form `{"method": "file.close", "params": {"force": true}}` (a method name that is a
|
||
command id) is guarded the same way, and only a boolean `true` counts as `force`. A document
|
||
without unsaved changes closes at once (#1268). Closing closes the document and its window, and
|
||
the window focused before it becomes the active one. The last window stays open with no page,
|
||
and `file.new` or `file.open` goes on from there (#1712); closing it doesn't quit the app. With
|
||
`doc` naming a document in the background, `file.close` closes that document and its window under
|
||
the same rule (unsaved changes need `{"force": true}`), and the active window stays active.
|
||
|
||
When another window shows the same document, `file.close` closes only the window it is sent to:
|
||
the document and its unsaved work stay open, so nothing is lost and the command is **not**
|
||
refused (#3274).
|
||
|
||
`file.new`, `file.open`, `file.recover` (with `restore`) and the mailings merges open their
|
||
result as **another document beside** the open ones and leave the unsaved one alone, so they
|
||
lose nothing and are never refused.
|
||
|
||
`file.closeDocument` closes the document its `id` names (the active one when the `id` is
|
||
absent), so it is refused while that document has unsaved work: changes that aren't written to
|
||
a file, a save the browser's picker hasn't finished, or a comment still being typed. Pass
|
||
`{"force": true}` to discard that work and close the document; only a boolean `true` counts as
|
||
`force`. The refusal and the Save Changes prompt ask about the same work, so they cannot
|
||
disagree (#3274).
|
||
|
||
`app.quit` closes every open document, so it is refused while any of them has unsaved changes:
|
||
the app keeps running and the work stays. Save first, or pass `{"force": true}` to discard the
|
||
changes and quit. Only a boolean `true` counts as `force`.
|
||
|
||
### Native printing
|
||
|
||
`engine.execute` can call `ui.printSettings` with `{}` to inspect the printer list, selected
|
||
printer, copies, duplex, grayscale, discovery/submission status and backend receipt/error.
|
||
`{"refresh":true}` starts background discovery; poll the same command until `discovering` is
|
||
false. Set `printer` to a discovered name, integer `copies` from 1 to 999, `duplex` to
|
||
`printerDefault`, `off`, `longEdge` or `shortEdge`, and boolean `grayscale`. Invalid updates are
|
||
rejected without changing earlier settings. `ui.printSubmit` explicitly submits the current
|
||
print-ready PDF without opening a dialog; inspect `ui.printSettings` until `busy` becomes false
|
||
and check `status`/`detail`. The browser keeps its own print hook. PDF export remains separate.
|
||
|
||
`ui.printSubmit` / `ui.print` also accept the upstream PDF page settings (`range`, `pages`,
|
||
`parity`, `copies`, `collate`). Native printing renders the selected pages once and passes
|
||
copies/collation to the spooler; the browser and `file.printPdf` keep copies in the PDF.
|
||
Omitting native `copies` uses the configured `ui.printSettings` value. `collate` defaults to
|
||
File › Print's setting; invalid ranges submit no job. `paper` (`none`, or a Layout › Size name
|
||
such as `Letter`, `Legal`, `A4`) is Scale to paper size (#2108): every page is scaled onto that
|
||
paper and centred, and native jobs ask the spooler for that `media`; the document's page size is
|
||
unchanged. `file.printPdf` takes it too; an unknown paper submits no job.
|
||
|
||
`engine.commands {"search":"print"}` lists the engine print commands and the app-owned
|
||
`ui.printSettings`, `ui.printSubmit`, and legacy `ui.print` alias, with current enablement
|
||
and their parameter documentation. Search is case-insensitive across IDs, labels, locations
|
||
and parameter descriptions. Listing commands never discovers printers, submits a job or opens
|
||
a dialog. Settings inspection is always available; submission becomes enabled when the native
|
||
printer is ready, or when the browser host provides its print flow.
|
||
|
||
### Physical print sheet layout
|
||
|
||
`ui.printSubmit`, `ui.print` and `file.printPdf` accept `pagesPerSheet`: the integer
|
||
1 (default), 2, 4, 6, 9 or 16, or `"booklet"` / `"bookletReverse"` for left/right binding.
|
||
These settings change only the print PDF, leaving document Page Setup unchanged.
|
||
Selection/range/parity are applied first. N-up fills cells in row order; booklet mode
|
||
pads the selected pages to a multiple of four and pairs outer/inner pages. Copies
|
||
repeat complete sheet plans, preserving blank slots at copy boundaries. Native copies
|
||
remain a spooler setting. Two-up and booklet sheets are landscape. Use duplex on the
|
||
short edge for folded booklets; this does not configure a printer's duplex capability.
|
||
The preview shows physical sheet sides, before copies, using the same sheet plan.
|
||
Explicit `paper` chooses the physical sheet; otherwise the first selected page supplies
|
||
its size. Independent Page Setup multiple-page modes (#2414) are not required.
|