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.
This commit is contained in:
Ian Douglas Scott 2024-12-13 17:50:03 -08:00 committed by Victoria Brekenfeld
parent 2e1f6a4746
commit 6707c92522

View file

@ -62,7 +62,7 @@ pub struct ToplevelInfoGlobalData {
#[derive(Default)] #[derive(Default)]
pub(super) struct ToplevelStateInner { pub(super) struct ToplevelStateInner {
foreign_handle: Option<ForeignToplevelHandle>, foreign_handle: Option<ForeignToplevelHandle>,
instances: Vec<ZcosmicToplevelHandleV1>, instances: Vec<(Weak<ZcosmicToplevelInfoV1>, ZcosmicToplevelHandleV1)>,
outputs: Vec<Output>, outputs: Vec<Output>,
workspaces: Vec<WorkspaceHandle>, workspaces: Vec<WorkspaceHandle>,
pub(super) rectangles: Vec<(Weak<WlSurface>, Rectangle<i32, Logical>)>, pub(super) rectangles: Vec<(Weak<WlSurface>, Rectangle<i32, Logical>)>,
@ -202,7 +202,7 @@ where
.lock() .lock()
.unwrap() .unwrap()
.instances .instances
.push(instance); .push((obj.downgrade(), instance));
} else { } else {
let _ = data_init.init(cosmic_toplevel, ToplevelHandleStateInner::empty()); let _ = data_init.init(cosmic_toplevel, ToplevelHandleStateInner::empty());
error!(?foreign_toplevel, "Toplevel for foreign-toplevel-list not registered for cosmic-toplevel-info."); 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 { for toplevel in &state.toplevel_info_state_mut().toplevels {
if let Some(state) = toplevel.user_data().get::<ToplevelState>() { if let Some(state) = toplevel.user_data().get::<ToplevelState>() {
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) { pub fn remove_toplevel(&mut self, toplevel: &W) {
if let Some(state) = toplevel.user_data().get::<ToplevelState>() { if let Some(state) = toplevel.user_data().get::<ToplevelState>() {
let mut state_inner = state.lock().unwrap(); 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 // don't send events to stopped instances
if handle.version() < zcosmic_toplevel_info_v1::REQ_GET_COSMIC_TOPLEVEL_SINCE if handle.version() < zcosmic_toplevel_info_v1::REQ_GET_COSMIC_TOPLEVEL_SINCE
&& self && self
@ -386,7 +390,7 @@ where
} }
true true
} else { } else {
for handle in &state.instances { for (_info, handle) in &state.instances {
// don't send events to stopped instances // don't send events to stopped instances
if handle.version() < zcosmic_toplevel_info_v1::REQ_GET_COSMIC_TOPLEVEL_SINCE if handle.version() < zcosmic_toplevel_info_v1::REQ_GET_COSMIC_TOPLEVEL_SINCE
&& self && self
@ -442,11 +446,7 @@ where
.unwrap() .unwrap()
.lock() .lock()
.unwrap(); .unwrap();
let instance = match state let (_info, instance) = match state.instances.iter().find(|(i, _)| i == info) {
.instances
.iter()
.find(|i| i.id().same_client_as(&info.id()))
{
Some(i) => i, Some(i) => i,
None => { None => {
if info.version() < zcosmic_toplevel_info_v1::REQ_GET_COSMIC_TOPLEVEL_SINCE { if info.version() < zcosmic_toplevel_info_v1::REQ_GET_COSMIC_TOPLEVEL_SINCE {
@ -459,7 +459,7 @@ where
) )
{ {
info.toplevel(&toplevel_handle); info.toplevel(&toplevel_handle);
state.instances.push(toplevel_handle); state.instances.push((info.downgrade(), toplevel_handle));
state.instances.last().unwrap() state.instances.last().unwrap()
} else { } else {
return false; return false;