From 6707c9252214a10e48a10091efacc301160f6d17 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Fri, 13 Dec 2024 17:50:03 -0800 Subject: [PATCH] toplevel-info: Fix behavior with multiple instances of global Instead of looking for toplevel handles for the client, look for toplevel handles for the specific global instance. --- src/wayland/protocols/toplevel_info.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/wayland/protocols/toplevel_info.rs b/src/wayland/protocols/toplevel_info.rs index 3d4d2538..44db2031 100644 --- a/src/wayland/protocols/toplevel_info.rs +++ b/src/wayland/protocols/toplevel_info.rs @@ -62,7 +62,7 @@ pub struct ToplevelInfoGlobalData { #[derive(Default)] pub(super) struct ToplevelStateInner { foreign_handle: Option, - instances: Vec, + instances: Vec<(Weak, ZcosmicToplevelHandleV1)>, outputs: Vec, workspaces: Vec, pub(super) rectangles: Vec<(Weak, Rectangle)>, @@ -202,7 +202,7 @@ where .lock() .unwrap() .instances - .push(instance); + .push((obj.downgrade(), instance)); } else { let _ = data_init.init(cosmic_toplevel, ToplevelHandleStateInner::empty()); error!(?foreign_toplevel, "Toplevel for foreign-toplevel-list not registered for cosmic-toplevel-info."); @@ -259,7 +259,11 @@ where ) { for toplevel in &state.toplevel_info_state_mut().toplevels { if let Some(state) = toplevel.user_data().get::() { - state.lock().unwrap().instances.retain(|i| i != resource); + state + .lock() + .unwrap() + .instances + .retain(|(_, i)| i != resource); } } } @@ -340,7 +344,7 @@ where pub fn remove_toplevel(&mut self, toplevel: &W) { if let Some(state) = toplevel.user_data().get::() { let mut state_inner = state.lock().unwrap(); - for handle in &state_inner.instances { + for (_info, handle) in &state_inner.instances { // don't send events to stopped instances if handle.version() < zcosmic_toplevel_info_v1::REQ_GET_COSMIC_TOPLEVEL_SINCE && self @@ -386,7 +390,7 @@ where } true } else { - for handle in &state.instances { + for (_info, handle) in &state.instances { // don't send events to stopped instances if handle.version() < zcosmic_toplevel_info_v1::REQ_GET_COSMIC_TOPLEVEL_SINCE && self @@ -442,11 +446,7 @@ where .unwrap() .lock() .unwrap(); - let instance = match state - .instances - .iter() - .find(|i| i.id().same_client_as(&info.id())) - { + let (_info, instance) = match state.instances.iter().find(|(i, _)| i == info) { Some(i) => i, None => { if info.version() < zcosmic_toplevel_info_v1::REQ_GET_COSMIC_TOPLEVEL_SINCE { @@ -459,7 +459,7 @@ where ) { info.toplevel(&toplevel_handle); - state.instances.push(toplevel_handle); + state.instances.push((info.downgrade(), toplevel_handle)); state.instances.last().unwrap() } else { return false;