Skip to content

Commit

Permalink
feat(clipboard): fix interaction with freeze and select feature: Issue
Browse files Browse the repository at this point in the history
…#109 (#110)

* feat(clipboard): fix interaction with freeze and select feature:  Issue #109

* feat(clipboard): handle callback fails
  • Loading branch information
CheerfulPianissimo authored Apr 6, 2024
1 parent 2cb242c commit 10b748f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions libwayshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,13 @@ impl WayshotConnection {
Ok(frame_copies)
}

fn overlay_frames(&self, frames: &[(FrameCopy, FrameGuard, OutputInfo)]) -> Result<()> {
/// Create a layer shell surface for each output,
/// render the screen captures on them and use the callback to select a region from them
fn overlay_frames_and_select_region(
&self,
frames: &[(FrameCopy, FrameGuard, OutputInfo)],
callback: Box<dyn Fn() -> Result<LogicalRegion, Error>>,
) -> Result<LogicalRegion> {
let mut state = LayerShellState {
configured_outputs: HashSet::new(),
};
Expand Down Expand Up @@ -491,7 +497,10 @@ impl WayshotConnection {
Ok(())
})?;
}
Ok(())
let callback_result = callback();
layer_shell.destroy();
event_queue.blocking_dispatch(&mut state)?;
callback_result
}

/// Take a screenshot from the specified region.
Expand Down Expand Up @@ -547,7 +556,7 @@ impl WayshotConnection {
RegionCapturer::Outputs(outputs) => outputs.as_slice().try_into()?,
RegionCapturer::Region(region) => region,
RegionCapturer::Freeze(callback) => {
self.overlay_frames(&frames).and_then(|_| callback())?
self.overlay_frames_and_select_region(&frames, callback)?
}
};

Expand Down

0 comments on commit 10b748f

Please sign in to comment.