Async non-blocking communication with the niri IPC socket.
- Two async runtime backends: Supports both
async-netandtokiovia feature flags - Async socket connection: Connect to the niri socket using
Socket::connect()(usesNIRI_SOCKETenv var) orSocket::connect_to()with a custom path - Request/response: Send requests to niri and receive replies via the
send()method - Event streaming: Convert the socket into an infinite [
Event] stream usinginto_event_stream()
use async_niri_socket::NiriSocket;
async fn run() -> Result<(), std::io::Error> {
let mut socket = NiriSocket::connect().await?;
// Send a request and get the reply
let reply = socket
.send(niri_ipc::Request::Workspaces)
.await?;
println!("Workspaces: {reply:?}");
// Or convert into an event stream
let reply = socket.into_event_stream().await;
if let Ok(event_stream) = reply {
let read_event = std::pin::pin!(event_stream);
while let Some(event) = read_event.next().await {
println!("Received event: {event:?}");
}
}
Ok(())
}