Skip to main content

Module ipc

Module ipc 

Source
Expand description

Single-instance IPC for tree-space.

Launching tree-space while an instance is already running must hand the new invocation’s intent to that instance (toggle visibility, open a pane, choose a dock side) rather than starting a second panel. GApplication’s own single-instance machinery can’t carry our --side flag or directory arguments through the freshly-launched process cleanly, so we use a small Unix domain socket under the runtime directory:

  • The first instance binds the socket and runs an accept thread that decodes each incoming line into a Command and hands it to the app.
  • Later instances try to connect; on success they write their serialized Command and exit without ever touching the GUI.
  • A stale socket (crashed instance) is detected by a failed connect and removed before re-binding.

Functions§

bind
Bind the instance socket as the (single) server.
bind_at
Bind the instance socket at an explicit path (see bind).
deliver
Try to deliver cmd to a running instance. Returns true when a server accepted the request; false when no server is listening.
deliver_at
Deliver cmd to the server listening on path.
socket_path
Path of the instance socket for the current environment.
spawn_listener
Spawn a thread that accepts instance connections and forwards every decoded Command to deliver (which must hop onto the UI thread itself, e.g. via MainContext::invoke).