Next: , Previous: , Up: API  


1.10 (maak niri)

Helpers for talking to a running niri compositor through ‘niri msg’. A task that changes the session – focus a workspace, spawn a program, put a window on another output – can do it in a line rather than in a shell string, and a task that reads the session can ask for JSON and parse it.

Two families are exported. The queries (‘niri-outputs‘, ‘niri-workspaces‘, ‘niri-windows’, ...) are ordinary commands; ‘niri-capture‘ runs any of them and returns what niri printed, which is what a task needs for a decision. The actions (‘niri-focus-workspace‘, ‘niri-spawn‘, ...) are thin wrappers over ‘niri msg action’.

Every helper has an ‘-argv‘ builder where the command has options worth asserting on. The builders are what ‘–dry-run‘ prints and what the tests exercise; no compositor is needed to check the command line.

‘niri msg’ is deliberately not started when this module loads. A task that needs niri checks ‘niri-available?’ first, or lets the missing program be reported by ‘run’ as exit code 127.

1.10.1 Procedures

Procedure: niri arguments KEY: #:json? #:allow-failure? #:verbose?

Send ARGUMENTS to ‘niri msg’.

This is the escape hatch for subcommands and flags without a wrapper. Nothing is handed to a shell, so a program name or a workspace name with a space in it reaches niri as one argument.

A command that exits non-zero raises a maak error, unless ALLOW-FAILURE? is #t, in which case the call answers #f – the usual ‘run’ contract.

Procedure: niri-action arguments KEY: #:json? #:allow-failure? #:verbose?

Perform an action with ARGUMENTS, through ‘niri msg action’.

A bare action name is enough for the ones that take no argument, such as close-window; the others take their reference after it.

(niri-action (list "focus-workspace" "2"))
(niri-action (list "spawn" "--" "foot" "-e" "htop"))
Procedure: niri-action-argv arguments KEY: #:json?

Return the argv that performs an action with its ARGUMENTS.

The action name comes first and its own flags follow, so ("focus-workspace" "2") is the argv for ‘focus-workspace 2’.

Procedure: niri-argv arguments KEY: #:json?

Return the argv that sends ARGUMENTS to ‘niri msg‘.

With JSON? the global --json flag is inserted before the subcommand, which is where niri expects it. ARGUMENTS is the subcommand and its flags: ("outputs"), ("action" "close-window"), and so on.

Procedure: niri-available?

Return #t when the niri program can be found on PATH.

Procedure: niri-capture arguments KEY: #:json? #:allow-failure?

Send ARGUMENTS to ‘niri msg’ and return what it printed.

This is the query form: the output is a string a task can trim, split or hand to a JSON parser, rather than a line on the terminal. In dry-run mode nothing runs, the command is printed, and the empty string comes back.

Procedure: niri-casts KEY: #:json? #:allow-failure?

List the screencasts.

Procedure: niri-close-window KEY: #:json? #:allow-failure?

Close the focused window.

Procedure: niri-focus-column index KEY: #:json? #:allow-failure?

Focus the column at INDEX.

Procedure: niri-focus-monitor name KEY: #:json? #:allow-failure?

Focus the monitor NAME.

Procedure: niri-focus-window id KEY: #:json? #:allow-failure?

Focus the window with ID.

Procedure: niri-focus-window-previous KEY: #:json? #:allow-failure?

Focus the previously focused window.

Procedure: niri-focus-workspace reference KEY: #:json? #:allow-failure?

Focus the workspace REFERENCE, an index or a name.

Procedure: niri-focus-workspace-previous KEY: #:json? #:allow-failure?

Focus the previous workspace.

Procedure: niri-focused-output KEY: #:json? #:allow-failure?

Print information about the focused output.

Procedure: niri-focused-window KEY: #:json? #:allow-failure?

Print information about the focused window.

Procedure: niri-fullscreen-window KEY: #:json? #:allow-failure?

Toggle fullscreen on the focused window.

Procedure: niri-keyboard-layouts KEY: #:json? #:allow-failure?

Print the configured keyboard layouts.

Procedure: niri-layers KEY: #:json? #:allow-failure?

List the open layer-shell surfaces.

Procedure: niri-move-column-to-monitor name KEY: #:json? #:allow-failure?

Move the focused column to the monitor NAME.

Procedure: niri-move-column-to-workspace reference KEY: #:json? #:allow-failure?

Move the focused column to the workspace REFERENCE.

Procedure: niri-move-window-to-monitor name KEY: #:json? #:allow-failure?

Move the focused window to the monitor NAME.

Procedure: niri-move-window-to-workspace reference KEY: #:window-id #:focus #:json? #:allow-failure?

Move the focused window, or WINDOW-ID, to the workspace REFERENCE.

FOCUS is default unless given: with #t the focus follows the window, and with #f it stays on the original workspace, which niri spells as --focus true and --focus false.

Procedure: niri-output output action . arguments

Change OUTPUT with ACTION and ARGUMENTS; see ‘niri-output-argv’.

The change is temporary and is not written to niri’s configuration file.

Procedure: niri-output-argv output action . arguments

Return the argv that changes OUTPUT with ACTION and ARGUMENTS.

The output name comes first and the action after it, which is the order ‘niri msg output’ requires: niri msg output DP-1 mode 1920x1080@60.

(niri-output-argv "DP-1" "scale" "1.5")
Procedure: niri-output-mode output mode KEY: #:allow-failure?

Set OUTPUT’s mode, such as 1920x1080@60.

Procedure: niri-output-off output KEY: #:allow-failure?

Turn OUTPUT off.

Procedure: niri-output-on output KEY: #:allow-failure?

Turn OUTPUT on.

Procedure: niri-output-position output x y KEY: #:allow-failure?

Set OUTPUT’s position on the desktop to X and Y.

Procedure: niri-output-scale output scale KEY: #:allow-failure?

Set OUTPUT’s scale, such as 1.5.

Procedure: niri-output-transform output transform KEY: #:allow-failure?

Set OUTPUT’s transform, such as 90 or flipped-180.

Procedure: niri-outputs KEY: #:json? #:allow-failure?

List the connected outputs.

Procedure: niri-overview-state KEY: #:json? #:allow-failure?

Print the overview state.

Procedure: niri-pick-color KEY: #:json? #:allow-failure?

Pick a color from the screen with the mouse.

Procedure: niri-pick-window KEY: #:json? #:allow-failure?

Pick a window with the mouse and print information about it.

Procedure: niri-power-off-monitors KEY: #:json? #:allow-failure?

Power off all monitors via DPMS.

Procedure: niri-power-on-monitors KEY: #:json? #:allow-failure?

Power on all monitors via DPMS.

Procedure: niri-quit KEY: #:skip-confirmation? #:json? #:allow-failure?

Exit niri.

SKIP-CONFIRMATION? is the default because a task that asks niri to quit is not sitting at a keyboard to press Enter.

Procedure: niri-request-error KEY: #:json? #:allow-failure?

Ask niri to return an error, which is useful for checking a client’s error handling against a live compositor.

Procedure: niri-screenshot KEY: #:json? #:allow-failure?

Open the screenshot UI.

Procedure: niri-screenshot-screen KEY: #:json? #:allow-failure?

Screenshot the focused screen.

Procedure: niri-screenshot-window KEY: #:json? #:allow-failure?

Screenshot the focused window.

Procedure: niri-set-column-width change KEY: #:json? #:allow-failure?

Change the width of the focused column by CHANGE.

Procedure: niri-set-window-width change KEY: #:id #:json? #:allow-failure?

Change the width of the focused window, or of window ID, by CHANGE.

CHANGE is a string such as +10% or 500, exactly as niri’s command line takes it.

Procedure: niri-set-workspace-name name KEY: #:json? #:allow-failure?

Set the name of the focused workspace to NAME.

Procedure: niri-spawn command KEY: #:json? #:allow-failure?

Spawn COMMAND, a list of strings, without a shell.

The -- that separates niri’s own flags from the program is added here, so a program with a flag that looks like niri’s is still passed through.

Procedure: niri-spawn-sh command KEY: #:json? #:allow-failure?

Spawn COMMAND through the shell.

Use ‘niri-spawn’ when the program and its arguments are already separate strings; this one is for a line that needs a shell.

Procedure: niri-toggle-overview KEY: #:json? #:allow-failure?

Toggle the overview.

Procedure: niri-toggle-windowed-fullscreen KEY: #:json? #:allow-failure?

Toggle windowed (fake) fullscreen on the focused window.

Procedure: niri-unset-workspace-name KEY: #:json? #:allow-failure?

Unset the name of the focused workspace.

Procedure: niri-version KEY: #:json? #:allow-failure?

Print the version of the running niri instance.

Procedure: niri-windows KEY: #:json? #:allow-failure?

List the open windows.

Procedure: niri-workspaces KEY: #:json? #:allow-failure?

List the workspaces.


Next: (maak nix), Previous: (maak net), Up: API