ipc: Wait until action is processed before returning
Browse files at this commitc61940c40eff7a4b2a237429e0ff2c352c41d68dParent: ed2b6d31 changed file +13 -2
- src/ipc/server.rs +13 -2
src/ipc/server.rsmodified+13 -2
| @@ -120,7 +120,10 @@ async fn handle_client(ctx: ClientCtx, stream: Async<'_, UnixStream>) -> anyhow: | ||
| 120 | 120 | .map_err(|err| err.to_string()); |
| 121 | 121 | let requested_error = matches!(request, Ok(Request::ReturnError)); |
| 122 | 122 | |
| 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 | + }; | |
| 124 | 127 | |
| 125 | 128 | if let Err(err) = &reply { |
| 126 | 129 | if !requested_error { |
| @@ -134,7 +137,7 @@ async fn handle_client(ctx: ClientCtx, stream: Async<'_, UnixStream>) -> anyhow: | ||
| 134 | 137 | Ok(()) |
| 135 | 138 | } |
| 136 | 139 | |
| 137 | -fn process(ctx: &ClientCtx, request: Request) -> Reply { | |
| 140 | +async fn process(ctx: &ClientCtx, request: Request) -> Reply { | |
| 138 | 141 | let response = match request { |
| 139 | 142 | Request::ReturnError => return Err(String::from("example compositor error")), |
| 140 | 143 | Request::Version => Response::Version(version()), |
| @@ -163,10 +166,18 @@ fn process(ctx: &ClientCtx, request: Request) -> Reply { | ||
| 163 | 166 | Response::FocusedWindow(window) |
| 164 | 167 | } |
| 165 | 168 | Request::Action(action) => { |
| 169 | + let (tx, rx) = async_channel::bounded(1); | |
| 170 | + | |
| 166 | 171 | let action = niri_config::Action::from(action); |
| 167 | 172 | ctx.event_loop.insert_idle(move |state| { |
| 168 | 173 | state.do_action(action, false); |
| 174 | + let _ = tx.send_blocking(()); | |
| 169 | 175 | }); |
| 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; | |
| 170 | 181 | Response::Handled |
| 171 | 182 | } |
| 172 | 183 | Request::Output { output, action } => { |