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 | .map_err(|err| err.to_string()); | 120 | .map_err(|err| err.to_string()); |
| 121 | let requested_error = matches!(request, Ok(Request::ReturnError)); | 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 | if let Err(err) = &reply { | 128 | if let Err(err) = &reply { |
| 126 | if !requested_error { | 129 | if !requested_error { |
| @@ -134,7 +137,7 @@ async fn handle_client(ctx: ClientCtx, stream: Async<'_, UnixStream>) -> anyhow: | |||
| 134 | Ok(()) | 137 | Ok(()) |
| 135 | } | 138 | } |
| 136 | 139 | ||
| 137 | -fn process(ctx: &ClientCtx, request: Request) -> Reply { | 140 | +async fn process(ctx: &ClientCtx, request: Request) -> Reply { |
| 138 | let response = match request { | 141 | let response = match request { |
| 139 | Request::ReturnError => return Err(String::from("example compositor error")), | 142 | Request::ReturnError => return Err(String::from("example compositor error")), |
| 140 | Request::Version => Response::Version(version()), | 143 | Request::Version => Response::Version(version()), |
| @@ -163,10 +166,18 @@ fn process(ctx: &ClientCtx, request: Request) -> Reply { | |||
| 163 | Response::FocusedWindow(window) | 166 | Response::FocusedWindow(window) |
| 164 | } | 167 | } |
| 165 | Request::Action(action) => { | 168 | Request::Action(action) => { |
| 169 | + let (tx, rx) = async_channel::bounded(1); | ||
| 170 | + | ||
| 166 | let action = niri_config::Action::from(action); | 171 | let action = niri_config::Action::from(action); |
| 167 | ctx.event_loop.insert_idle(move |state| { | 172 | ctx.event_loop.insert_idle(move |state| { |
| 168 | state.do_action(action, false); | 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 | Response::Handled | 181 | Response::Handled |
| 171 | } | 182 | } |
| 172 | Request::Output { output, action } => { | 183 | Request::Output { output, action } => { |