From 0451452b203abe67a8728d2294033645854215de Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 21 Oct 2024 15:59:26 -0700 Subject: [PATCH] client-toolkit/toplevel_info: Ignore `done` before cosmic events The compositor sends a `done` event for the `ext_foreign_toplevel_handle_v1` before we call `get_cosmic_toplevel`. Ignore that and wait for the `done` that occurs after we get cosmic events. `zcosmic_toplevel_handle_v1::state` seems to be a mandatory event, so it is valid if awkward to use for the purpose. I don't know about a cleaner solution. We could just ignore the first `done`, but technically it could race if the compostior sends a state change before it has processed the `get_cosmic_toplevel`. Maybe a roundtrip/sync could work. --- client-toolkit/src/toplevel_info.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client-toolkit/src/toplevel_info.rs b/client-toolkit/src/toplevel_info.rs index e241957c98..825c34cec5 100644 --- a/client-toolkit/src/toplevel_info.rs +++ b/client-toolkit/src/toplevel_info.rs @@ -37,6 +37,7 @@ pub struct ToplevelInfo { struct ToplevelData { current_info: Option, pending_info: ToplevelInfo, + has_cosmic_info: bool, } #[derive(Debug)] @@ -218,6 +219,7 @@ where data.pending_info.workspace.remove(&workspace); } zcosmic_toplevel_handle_v1::Event::State { state } => { + data.has_cosmic_info = true; data.pending_info.state.clear(); for value in state.chunks_exact(4) { if let Some(state) = zcosmic_toplevel_handle_v1::State::try_from( @@ -340,7 +342,12 @@ where } } ext_foreign_toplevel_handle_v1::Event::Done => { - // XXX + if !data.has_cosmic_info { + // Don't call `new_toplevel` if we have the `ext_foreign_toplevel_handle_v1`, + // but don't have any `zcosmic_toplevel_handle_v1` events yet. + return; + } + let is_new = data.current_info.is_none(); data.current_info = Some(data.pending_info.clone()); let toplevel = toplevel.clone();