ipc: Write some more docs
Browse files at this commit6c4e4b374a48a5d3d46a7b7e9fded128232ccfbeParent: 9ab887b2 changed files +26 -0
- niri-ipc/src/lib.rs +20 -0
- niri-ipc/src/state.rs +6 -0
niri-ipc/src/lib.rsmodified+20 -0
| @@ -1,4 +1,24 @@ | |||
| 1 | //! Types for communicating with niri via IPC. | 1 | //! Types for communicating with niri via IPC. |
| 2 | +//! | ||
| 3 | +//! After connecting to the niri socket, you can send a single [`Request`] and receive a single | ||
| 4 | +//! [`Reply`], which is a `Result` wrapping a [`Response`]. If you requested an event stream, you | ||
| 5 | +//! can keep reading [`Event`]s from the socket after the response. | ||
| 6 | +//! | ||
| 7 | +//! 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, | ||
| 9 | +//! you are encouraged to communicate with the socket manually. | ||
| 10 | +//! | ||
| 11 | +//! 1. Read the socket filesystem path from [`socket::SOCKET_PATH_ENV`] (`$NIRI_SOCKET`). | ||
| 12 | +//! 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. | ||
| 14 | +//! 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, | ||
| 16 | +//! on a single line each. | ||
| 17 | +//! | ||
| 18 | +//! ## Backwards compatibility | ||
| 19 | +//! | ||
| 20 | +//! This crate follows the niri version. It is **not** API-stable in terms of the Rust semver. In | ||
| 21 | +//! particular, expect new struct fields and enum variants to be added in patch version bumps. | ||
| 2 | #![warn(missing_docs)] | 22 | #![warn(missing_docs)] |
| 3 | 23 | ||
| 4 | use std::collections::HashMap; | 24 | use std::collections::HashMap; |
niri-ipc/src/state.rsmodified+6 -0
| @@ -1,4 +1,10 @@ | |||
| 1 | //! Helpers for keeping track of the event stream state. | 1 | //! Helpers for keeping track of the event stream state. |
| 2 | +//! | ||
| 3 | +//! 1. Create an [`EventStreamState`] using `Default::default()`, or any individual state part if | ||
| 4 | +//! you only care about part of the state. | ||
| 5 | +//! 2. Connect to the niri socket and request an event stream. | ||
| 6 | +//! 3. Pass every [`Event`] to [`EventStreamStatePart::apply`] on your state. | ||
| 7 | +//! 4. Read the fields of the state as needed. | ||
| 2 | 8 | ||
| 3 | use std::collections::hash_map::Entry; | 9 | use std::collections::hash_map::Entry; |
| 4 | use std::collections::HashMap; | 10 | use std::collections::HashMap; |