forge
Explore
Log in

Don't you dare go Hollow

ipc: document the new socket behavior

Browse files at this commit

3466fc0a66a43bf2f959673ff303e9037488a173Jon HeinritzParent: f917932
niri-ipc/src/lib.rsmodified+21 -4
@@ -1,8 +1,23 @@
1 //! Types for communicating with niri via IPC.1 //! Types for communicating with niri via IPC.
2 //!2 //!
3-//! After connecting to the niri socket, you can send a single [`Request`] and receive a single3+//! After connecting to the niri socket, you can send [`Request`]s. Niri will process them one by
4-//! [`Reply`], which is a `Result` wrapping a [`Response`]. If you requested an event stream, you4+//! one, in order, and to each request it will respond with a single [`Reply`], which is a `Result`
5-//! can keep reading [`Event`]s from the socket after the response.5+//! wrapping a [`Response`].
6+//!
7+//! If you send a [`Request::EventStream`], niri will *stop* reading subsequent [`Request`]s, and
8+//! will start continuously writing compositor [`Event`]s to the socket. If you'd like to read an
9+//! event stream and write more requests at the same time, you need to use two IPC sockets.
10+//!
11+//! <div class="warning">
12+//!
13+//! Requests are *always* processed separately. Time passes between requests, even when sending
14+//! multiple requests to the socket at once. For example, sending [`Request::Workspaces`] and
15+//! [`Request::Windows`] together may not return consistent results (e.g. a window may open on a
16+//! new workspace in-between the two responses). This goes for actions too: sending
17+//! [`Action::FocusWindow`] and <code>[Action::CloseWindow] { id: None }</code> together may close
18+//! the wrong window because a different window got focused in-between these requests.
19+//!
20+//! </div>
6 //!21 //!
7 //! You can use the [`socket::Socket`] helper if you're fine with blocking communication. However,22 //! You can use the [`socket::Socket`] helper if you're fine with blocking communication. However,
8 //! it is a fairly simple helper, so if you need async, or if you're using a different language,23 //! it is a fairly simple helper, so if you need async, or if you're using a different language,
@@ -12,7 +27,9 @@
12 //! 2. Connect to the socket and write a JSON-formatted [`Request`] on a single line. You can follow27 //! 2. Connect to the socket and write a JSON-formatted [`Request`] on a single line. You can follow
13 //! up with a line break and a flush, or just flush and shutdown the write end of the socket.28 //! up with a line break and a flush, or just flush and shutdown the write end of the socket.
14 //! 3. Niri will respond with a single line JSON-formatted [`Reply`].29 //! 3. Niri will respond with a single line JSON-formatted [`Reply`].
15-//! 4. If you requested an event stream, niri will keep responding with JSON-formatted [`Event`]s,30+//! 4. You can keep writing [`Request`]s, each on a single line, and read [`Reply`]s, also each on a
31+//! separate line.
32+//! 5. After you request an event stream, niri will keep responding with JSON-formatted [`Event`]s,
16 //! on a single line each.33 //! on a single line each.
17 //!34 //!
18 //! ## Backwards compatibility35 //! ## Backwards compatibility