Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions src/wayland/handlers/image_copy_capture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't run into a situation where we have an invalid node for a given output since the renderer is created on the main thread. This points to a deeper issue we should fix instead. Ping @ids1024

Some(constraints_for_renderer(mode, renderer.as_mut()))
}

Expand All @@ -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()?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.


Some(constraints_for_renderer(size, renderer.as_mut()))
}
Expand Down
14 changes: 12 additions & 2 deletions src/wayland/handlers/image_copy_capture/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to explicitly call fail, if we drop the session.

return;
};
session.update_constraints(constraints);
Expand Down
42 changes: 18 additions & 24 deletions src/wayland/handlers/image_copy_capture/user_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,9 @@ impl SessionHolder for Output {
}

fn remove_session(&mut self, session: &SessionRef) {
self.user_data()
.get::<ImageCopySessionsData>()
.unwrap()
.borrow_mut()
.sessions
.retain(|s| s != session);
if let Some(sessions) = self.user_data().get::<ImageCopySessionsData>() {
sessions.borrow_mut().sessions.retain(|s| s != session);
}
}

fn sessions(&self) -> Vec<SessionRef> {
Expand Down Expand Up @@ -103,12 +100,12 @@ impl SessionHolder for Output {
}

fn remove_cursor_session(&mut self, session: &CursorSessionRef) {
self.user_data()
.get::<ImageCopySessionsData>()
.unwrap()
.borrow_mut()
.cursor_sessions
.retain(|s| s != session);
if let Some(sessions) = self.user_data().get::<ImageCopySessionsData>() {
sessions
.borrow_mut()
.cursor_sessions
.retain(|s| s != session);
}
}

fn cursor_sessions(&self) -> Vec<CursorSessionRef> {
Expand Down Expand Up @@ -194,12 +191,9 @@ impl SessionHolder for CosmicSurface {
}

fn remove_session(&mut self, session: &SessionRef) {
self.user_data()
.get::<ImageCopySessionsData>()
.unwrap()
.borrow_mut()
.sessions
.retain(|s| s != session);
if let Some(sessions) = self.user_data().get::<ImageCopySessionsData>() {
sessions.borrow_mut().sessions.retain(|s| s != session);
}
}
fn sessions(&self) -> Vec<SessionRef> {
self.user_data()
Expand All @@ -226,12 +220,12 @@ impl SessionHolder for CosmicSurface {
}

fn remove_cursor_session(&mut self, session: &CursorSessionRef) {
self.user_data()
.get::<ImageCopySessionsData>()
.unwrap()
.borrow_mut()
.cursor_sessions
.retain(|s| s != session);
if let Some(sessions) = self.user_data().get::<ImageCopySessionsData>() {
sessions
.borrow_mut()
.cursor_sessions
.retain(|s| s != session);
}
}

fn cursor_sessions(&self) -> Vec<CursorSessionRef> {
Expand Down