diff --git a/src/wayland/handlers/image_copy_capture/mod.rs b/src/wayland/handlers/image_copy_capture/mod.rs index 85a01c9a5..3ab2b407d 100644 --- a/src/wayland/handlers/image_copy_capture/mod.rs +++ b/src/wayland/handlers/image_copy_capture/mod.rs @@ -401,7 +401,8 @@ fn constraints_for_output(output: &Output, backend: &mut BackendData) -> Option< kms.target_node_for_output(output) .or(*kms.primary_node.read().unwrap()) }) - .unwrap(); + .inspect_err(|err| tracing::warn!(?err, "Couldn't use node for screencopy")) + .ok()?; Some(constraints_for_renderer(mode, renderer.as_mut())) } @@ -423,7 +424,8 @@ fn constraints_for_toplevel( dma_node.or(*kms.primary_node.read().unwrap()) }) - .unwrap(); + .inspect_err(|err| tracing::warn!(?err, "Couldn't use node for screencopy")) + .ok()?; Some(constraints_for_renderer(size, renderer.as_mut())) } diff --git a/src/wayland/handlers/image_copy_capture/render.rs b/src/wayland/handlers/image_copy_capture/render.rs index f8b308e29..2df95518b 100644 --- a/src/wayland/handlers/image_copy_capture/render.rs +++ b/src/wayland/handlers/image_copy_capture/render.rs @@ -305,7 +305,7 @@ pub fn render_workspace_to_buffer( return; }; - let mut output = workspace.output().clone(); + let output = workspace.output().clone(); let idx = shell.workspaces.idx_for_handle(&output, &handle).unwrap(); std::mem::drop(shell); @@ -317,7 +317,17 @@ pub fn render_workspace_to_buffer( let buffer_size = buffer_dimensions(&buffer).unwrap(); if mode != Some(buffer_size) { let Some(constraints) = constraints_for_output(&output, &mut state.backend) else { - output.remove_session(session); + // Drop the workspace's owned Session so the client receives `stopped`. + if let Some(workspace) = state + .common + .shell + .write() + .workspaces + .space_for_handle_mut(&handle) + { + workspace.remove_session(session); + } + frame.fail(CaptureFailureReason::Stopped); return; }; session.update_constraints(constraints); diff --git a/src/wayland/handlers/image_copy_capture/user_data.rs b/src/wayland/handlers/image_copy_capture/user_data.rs index e9f3623ec..e03c9ca99 100644 --- a/src/wayland/handlers/image_copy_capture/user_data.rs +++ b/src/wayland/handlers/image_copy_capture/user_data.rs @@ -70,12 +70,9 @@ impl SessionHolder for Output { } fn remove_session(&mut self, session: &SessionRef) { - self.user_data() - .get::() - .unwrap() - .borrow_mut() - .sessions - .retain(|s| s != session); + if let Some(sessions) = self.user_data().get::() { + sessions.borrow_mut().sessions.retain(|s| s != session); + } } fn sessions(&self) -> Vec { @@ -103,12 +100,12 @@ impl SessionHolder for Output { } fn remove_cursor_session(&mut self, session: &CursorSessionRef) { - self.user_data() - .get::() - .unwrap() - .borrow_mut() - .cursor_sessions - .retain(|s| s != session); + if let Some(sessions) = self.user_data().get::() { + sessions + .borrow_mut() + .cursor_sessions + .retain(|s| s != session); + } } fn cursor_sessions(&self) -> Vec { @@ -194,12 +191,9 @@ impl SessionHolder for CosmicSurface { } fn remove_session(&mut self, session: &SessionRef) { - self.user_data() - .get::() - .unwrap() - .borrow_mut() - .sessions - .retain(|s| s != session); + if let Some(sessions) = self.user_data().get::() { + sessions.borrow_mut().sessions.retain(|s| s != session); + } } fn sessions(&self) -> Vec { self.user_data() @@ -226,12 +220,12 @@ impl SessionHolder for CosmicSurface { } fn remove_cursor_session(&mut self, session: &CursorSessionRef) { - self.user_data() - .get::() - .unwrap() - .borrow_mut() - .cursor_sessions - .retain(|s| s != session); + if let Some(sessions) = self.user_data().get::() { + sessions + .borrow_mut() + .cursor_sessions + .retain(|s| s != session); + } } fn cursor_sessions(&self) -> Vec {