forge
Explore
Log in

Don't you dare go Hollow

ipc: Wait until action is processed before returning

Browse files at this commit

c61940c40eff7a4b2a237429e0ff2c352c41d68dIvan MolodetskikhParent: ed2b6d3
src/ipc/server.rsmodified+13 -2
@@ -120,7 +120,10 @@ async fn handle_client(ctx: ClientCtx, stream: Async<'_, UnixStream>) -> anyhow:
120120 .map_err(|err| err.to_string());
121121 let requested_error = matches!(request, Ok(Request::ReturnError));
122122
123- let reply = request.and_then(|request| process(&ctx, request));
123+ let reply = match request {
124+ Ok(request) => process(&ctx, request).await,
125+ Err(err) => Err(err),
126+ };
124127
125128 if let Err(err) = &reply {
126129 if !requested_error {
@@ -134,7 +137,7 @@ async fn handle_client(ctx: ClientCtx, stream: Async<'_, UnixStream>) -> anyhow:
134137 Ok(())
135138 }
136139
137-fn process(ctx: &ClientCtx, request: Request) -> Reply {
140+async fn process(ctx: &ClientCtx, request: Request) -> Reply {
138141 let response = match request {
139142 Request::ReturnError => return Err(String::from("example compositor error")),
140143 Request::Version => Response::Version(version()),
@@ -163,10 +166,18 @@ fn process(ctx: &ClientCtx, request: Request) -> Reply {
163166 Response::FocusedWindow(window)
164167 }
165168 Request::Action(action) => {
169+ let (tx, rx) = async_channel::bounded(1);
170+
166171 let action = niri_config::Action::from(action);
167172 ctx.event_loop.insert_idle(move |state| {
168173 state.do_action(action, false);
174+ let _ = tx.send_blocking(());
169175 });
176+
177+ // Wait until the action has been processed before returning. This is important for a
178+ // few actions, for instance for DoScreenTransition this wait ensures that the screen
179+ // contents were sampled into the texture.
180+ let _ = rx.recv().await;
170181 Response::Handled
171182 }
172183 Request::Output { output, action } => {