ipc/socket: Support multiple requests

This commit is contained in:
Ivan Molodetskikh
2025-05-11 10:14:01 +03:00
parent 3466fc0a66
commit 2aff1ec71a
2 changed files with 46 additions and 24 deletions
+4 -6
View File
@@ -35,9 +35,9 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
Msg::OverviewState => Request::OverviewState,
};
let socket = Socket::connect().context("error connecting to the niri socket")?;
let mut socket = Socket::connect().context("error connecting to the niri socket")?;
let (reply, mut read_event) = socket
let reply = socket
.send(request)
.context("error communicating with niri")?;
@@ -45,10 +45,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
Err(_) if !matches!(msg, Msg::Version) => {
// If we got an error, it might be that the CLI is a different version from the running
// niri instance. Request the running instance version to compare and print a message.
Socket::connect()
.and_then(|socket| socket.send(Request::Version))
.ok()
.map(|(reply, _read_event)| reply)
socket.send(Request::Version).ok()
}
_ => None,
};
@@ -392,6 +389,7 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> {
println!("Started reading events.");
}
let mut read_event = socket.read_events();
loop {
let event = read_event().context("error reading event from niri")?;