import type { Result } from "@cprussin/option-result"; import type { Gestures } from "./desktop/gestures"; import type { Keyboard } from "./desktop/keyboard"; import type { Processes } from "./desktop/processes"; import type { ShellNamespace } from "./desktop/shell"; import type { KeybindingsByMode, ShellKeybindings } from "./own-keybindings"; import type { CommandRan, ShellBinding, ShellCommandHelp } from "./shell-command"; import type { SystemError } from "./system"; /** Callbacks {@link bindKeys} calls, and the commands the shell runs. */ export type KeyHandlers = { /** * The commands `onCommand` runs, which `domicile list-shell-commands` * prints. */ commands: readonly ShellCommandHelp[]; /** * A `send-shell` binding was pressed, or `domicile send-shell` sent a * command, with its arguments. `Ok({ output })` is printed by * `domicile send-shell`, as a query's answer; `Err` says why the shell did * not run it, which `domicile send-shell` fails with. */ onCommand: (args: readonly string[]) => Result; /** The binding mode changed. */ onModeChanged: (mode: string) => void; /** The page cannot hear `domicile send-shell`. Logs by default. */ report?: (error: SystemError) => void; /** A pressed binding's command was not run, and why. Logs by default. */ reportRefusal?: (why: string) => void; }; /** The handle {@link bindKeys} returns. */ export type KeyBinding = { /** Switch to binding mode `name`; see {@link bindKeys}. */ setMode: (name: string) => void; /** Stop handling keys, and give back every chord and gesture grabbed. */ unbind: () => void; }; /** The part of the desktop that `bindKeys` uses. */ export type KeyDesktop = { readonly gestures: Pick; readonly keyboard: Pick; readonly processes: Pick; readonly shell: Pick; }; /** * Handle the keybindings `own` for a shell. * * - Every chord in every mode is grabbed once, until `unbind`. A key bound in * any mode is grabbed from all clients while bound. * - So is every gesture's kind and count: `swipe:3:left` grabs every * three-finger swipe, whichever way it goes. An edge swipe's side is * grabbed: `edge:left` withholds only fingers landing at the left edge. * - `setMode` syncs the mode across pages without calling `onModeChanged`. An * unknown mode falls back to `default` and is reported. * * @throws for an invalid chord or gesture (see `ownKeybindings`), before anything is * grabbed. A keysym the layout cannot type is logged, so the other keys * still work. */ export declare const bindKeys: (domicile: KeyDesktop, own: ShellKeybindings, { commands: help, onCommand, onModeChanged, report, reportRefusal, }: KeyHandlers) => KeyBinding; /** * Every binding, mode by mode, as `domicile list-bindings` prints it: the * chord in its one spelling and the action as words. */ export declare const describedBindings: (bindings: KeybindingsByMode) => ShellBinding[];