Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toplevel-info: Fix behavior with multiple instances of global #1061

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/wayland/protocols/toplevel_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub struct ToplevelInfoGlobalData {
#[derive(Default)]
pub(super) struct ToplevelStateInner {
foreign_handle: Option<ForeignToplevelHandle>,
instances: Vec<ZcosmicToplevelHandleV1>,
instances: Vec<(Weak<ZcosmicToplevelInfoV1>, ZcosmicToplevelHandleV1)>,
outputs: Vec<Output>,
workspaces: Vec<WorkspaceHandle>,
pub(super) rectangles: Vec<(Weak<WlSurface>, Rectangle<i32, Logical>)>,
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -259,7 +259,11 @@ where
) {
for toplevel in &state.toplevel_info_state_mut().toplevels {
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);
}
}
}
Expand Down Expand Up @@ -340,7 +344,7 @@ where
pub fn remove_toplevel(&mut self, toplevel: &W) {
if let Some(state) = toplevel.user_data().get::<ToplevelState>() {
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
Loading