Shell: send niri commands over the IPC socket #38
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
The shell already reads niri's event stream over the IPC socket (
shell/Niri.qml, theSocketat the bottom). Commands still go the slow way:Niri.action()starts aniri msg action …process for every command.That is fine for a click in the sidebar, but not for the spaces map (#36), where H/J/K/L moves are fired as fast as you press keys and some moves are sequences (focus a window, move it, give focus back):
niri msgcosts about 24 ms per command. Over a socket that is already open, a request takes about 0.4 ms (measured: three"Version"requests on one connection, 0.49 / 0.35 / 0.35 ms).execDetachedthrows away niri's reply, so a rejected command fails silently.What niri accepts on the socket
Measured on niri 26.04:
{"Action":{"focus-window":{"id":1}}}gives{"Err":"error parsing request"}.{"Ok":"Handled"}.{"Ok":"Handled"}. niri doesn't report it, so the shell can't rely on the reply to notice a stale id.{"Action":{"FocusWorkspace":{"reference":{"Id":1}}}}works.niri msgonly takes a name or an index, which is whyfollowTo()looks the workspace up by name or index today. The socket removes the need for that lookup.Work
All in
shell/Niri.qml:Socketfor commands, next to the event stream socket. The event stream connection can't be reused, because once it has sent"EventStream"it only streams events.action()take a request object and write it as one JSON line, with a queue of commands still waiting for a reply.SplitParser, matching each reply to the oldest command waiting for one. Log anything that isn't{"Ok":…}with the request that caused it.focusWorkspace(ref):{"Action":{"FocusWorkspace":{"reference":{"Index":n}}}}for a number,{"Name":…}otherwise. Callers inStatus.qmlandSidebar.qmlstay the same.{"Action":{"FocusWindow":{"id":…}}}.followTo():{"Action":{"MoveWindowToWorkspace":{"window_id":…,"reference":{"Id":wsId},"focus":false}}}. The name/index lookup and the comment above it go away.Power.qmlrunsniri msg action quitthroughexecDetached. Leave it as it is: it runs once, and niri exits before any reply would arrive.Out of scope
Done when
grep -n '"niri", "msg"' shell/matches onlyPower.qml.nix fmtandnix flake checkpass.Notes
active_window_id, whichNiri.qmlalready tracks for each workspace) both rely on it.