diff --git a/src/backend/render/mod.rs b/src/backend/render/mod.rs index c824494d..5c999d31 100644 --- a/src/backend/render/mod.rs +++ b/src/backend/render/mod.rs @@ -506,6 +506,7 @@ where if current.0 != desc.handle { state .shell + .workspaces .space_for_handle(&desc.handle) .map(|w| w.tiling_layer.tree()) } else { @@ -532,6 +533,7 @@ where let workspace = state .shell + .workspaces .space_for_handle(¤t.0) .ok_or(OutputNoMode)?; @@ -563,6 +565,7 @@ where let workspace = state .shell + .workspaces .space_for_handle(&previous) .ok_or(OutputNoMode)?; let has_fullscreen = workspace.fullscreen.is_some(); diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 37c33b09..cf3b7c2f 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -944,6 +944,14 @@ impl Workspaces { self.sets.values().flat_map(|set| set.workspaces.iter()) } + pub fn space_for_handle(&self, handle: &WorkspaceHandle) -> Option<&Workspace> { + self.spaces().find(|w| &w.handle == handle) + } + + pub fn space_for_handle_mut(&mut self, handle: &WorkspaceHandle) -> Option<&mut Workspace> { + self.spaces_mut().find(|w| &w.handle == handle) + } + pub fn spaces_for_output(&self, output: &Output) -> impl Iterator { self.sets .get(output) @@ -1236,14 +1244,6 @@ impl Shell { .find(|workspace| workspace.mapped().any(|m| m == mapped)) } - pub fn space_for_handle(&self, handle: &WorkspaceHandle) -> Option<&Workspace> { - self.workspaces.spaces().find(|w| &w.handle == handle) - } - - pub fn space_for_handle_mut(&mut self, handle: &WorkspaceHandle) -> Option<&mut Workspace> { - self.workspaces.spaces_mut().find(|w| &w.handle == handle) - } - pub fn outputs(&self) -> impl DoubleEndedIterator { self.workspaces.sets.keys().chain( self.workspaces @@ -1439,16 +1439,21 @@ impl Shell { previous_workspace: &WorkspaceHandle, target_layer: ManagedLayer, ) { - if self.space_for_handle(previous_workspace).is_none() { + if self + .workspaces + .space_for_handle(previous_workspace) + .is_none() + { return; } { - let Some(workspace) = self.space_for_handle_mut(¤t_workspace) else { return }; + let Some(workspace) = self.workspaces.space_for_handle_mut(¤t_workspace) else { return }; let _ = workspace.unmap(&mapped); } let new_workspace_output = self + .workspaces .space_for_handle(&previous_workspace) .unwrap() .output() @@ -1460,7 +1465,10 @@ impl Shell { .toplevel_enter_workspace(&window, &previous_workspace); } - let new_workspace = self.space_for_handle_mut(&previous_workspace).unwrap(); + let new_workspace = self + .workspaces + .space_for_handle_mut(&previous_workspace) + .unwrap(); match target_layer { ManagedLayer::Floating => new_workspace.floating_layer.map(mapped, None), ManagedLayer::Tiling => { @@ -1522,6 +1530,7 @@ impl Shell { let new_workspace_handle = state .common .shell + .workspaces .space_for_handle(&previous_workspace) .is_some() .then_some(previous_workspace) @@ -1745,6 +1754,7 @@ impl Shell { let new_workspace_handle = state .common .shell + .workspaces .space_for_handle(&previous_workspace) .is_some() .then_some(previous_workspace) diff --git a/src/wayland/handlers/screencopy.rs b/src/wayland/handlers/screencopy.rs index e2dd4443..44731ed5 100644 --- a/src/wayland/handlers/screencopy.rs +++ b/src/wayland/handlers/screencopy.rs @@ -144,7 +144,7 @@ impl ScreencopyHandler for State { } }; - let workspace = match self.common.shell.space_for_handle_mut(&handle) { + let workspace = match self.common.shell.workspaces.space_for_handle_mut(&handle) { Some(workspace) => workspace, None => { session.failed(FailureReason::InvalidWorkspace); @@ -343,7 +343,7 @@ impl ScreencopyHandler for State { .push((session, params)); } SessionType::Workspace(_output, handle) => { - match self.common.shell.space_for_handle_mut(&handle) { + match self.common.shell.workspaces.space_for_handle_mut(&handle) { Some(workspace) => workspace.pending_buffers.push((session, params)), None => session.failed(FailureReason::InvalidWorkspace), }; @@ -422,7 +422,8 @@ impl ScreencopyHandler for State { } } SessionType::Workspace(_, handle) => { - if let Some(workspace) = self.common.shell.space_for_handle_mut(&handle) { + if let Some(workspace) = self.common.shell.workspaces.space_for_handle_mut(&handle) + { workspace.pending_buffers.retain(|(s, _)| s != &session); workspace.screencopy_sessions.retain(|s| s != &session); } @@ -1092,7 +1093,7 @@ impl Common { } } SessionType::Workspace(_output, handle) => { - if let Some(space) = self.shell.space_for_handle_mut(&handle) { + if let Some(space) = self.shell.workspaces.space_for_handle_mut(&handle) { if space.screencopy_sessions.iter().any(|s| s == &session) { space.pending_buffers.push((session, params)); } @@ -1247,7 +1248,12 @@ impl State { .map(|o| (o.clone(), self.common.shell.active_space(o).handle.clone())) .collect::>(); if let Some((handle, output)) = self.common.shell.workspace_for_surface(surface) { - let workspace = self.common.shell.space_for_handle_mut(&handle).unwrap(); + let workspace = self + .common + .shell + .workspaces + .space_for_handle_mut(&handle) + .unwrap(); if !workspace.pending_buffers.is_empty() { // TODO: replace with drain_filter.... let mut i = 0; diff --git a/src/wayland/handlers/xdg_shell/mod.rs b/src/wayland/handlers/xdg_shell/mod.rs index ca15441c..70b1bbec 100644 --- a/src/wayland/handlers/xdg_shell/mod.rs +++ b/src/wayland/handlers/xdg_shell/mod.rs @@ -289,6 +289,7 @@ impl XdgShellHandler for State { let new_workspace_handle = self .common .shell + .workspaces .space_for_handle(&previous_workspace) .is_some() .then_some(previous_workspace)