From 7e81b64ed26c37044b6ed59eac261f6be5d361a7 Mon Sep 17 00:00:00 2001 From: CheerfulPianissimo Date: Thu, 28 Mar 2024 12:20:51 +0530 Subject: [PATCH 1/2] feat(clipboard): fix interaction with freeze and select feature: Issue #109 --- libwayshot/src/lib.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libwayshot/src/lib.rs b/libwayshot/src/lib.rs index 3cd7d280..7ef81e19 100644 --- a/libwayshot/src/lib.rs +++ b/libwayshot/src/lib.rs @@ -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 Result>, + ) -> Result<(LogicalRegion)> { let mut state = LayerShellState { configured_outputs: HashSet::new(), }; @@ -491,7 +497,10 @@ impl WayshotConnection { Ok(()) })?; } - Ok(()) + let region = callback()?; + layer_shell.destroy(); + event_queue.blocking_dispatch(&mut state)?; + Ok(region) } /// Take a screenshot from the specified region. @@ -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)? } }; From 82693142ed0506c94064f3dd54a32a47ccfaa93c Mon Sep 17 00:00:00 2001 From: CheerfulPianissimo Date: Tue, 2 Apr 2024 18:30:24 +0530 Subject: [PATCH 2/2] feat(clipboard): handle callback fails --- libwayshot/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libwayshot/src/lib.rs b/libwayshot/src/lib.rs index 7ef81e19..35a7b0d1 100644 --- a/libwayshot/src/lib.rs +++ b/libwayshot/src/lib.rs @@ -419,7 +419,7 @@ impl WayshotConnection { &self, frames: &[(FrameCopy, FrameGuard, OutputInfo)], callback: Box Result>, - ) -> Result<(LogicalRegion)> { + ) -> Result { let mut state = LayerShellState { configured_outputs: HashSet::new(), }; @@ -497,10 +497,10 @@ impl WayshotConnection { Ok(()) })?; } - let region = callback()?; + let callback_result = callback(); layer_shell.destroy(); event_queue.blocking_dispatch(&mut state)?; - Ok(region) + callback_result } /// Take a screenshot from the specified region.