diff --git a/libwayshot/src/lib.rs b/libwayshot/src/lib.rs index e2d430a3..3cd7d280 100644 --- a/libwayshot/src/lib.rs +++ b/libwayshot/src/lib.rs @@ -100,8 +100,8 @@ impl WayshotConnection { } /// Fetch all accessible wayland outputs. - pub fn get_all_outputs(&self) -> &Vec { - &self.output_infos + pub fn get_all_outputs(&self) -> &[OutputInfo] { + self.output_infos.as_slice() } /// refresh the outputs, to get new outputs @@ -388,37 +388,32 @@ impl WayshotConnection { pub fn capture_frame_copies( &self, - output_capture_regions: &Vec<(OutputInfo, Option)>, + output_capture_regions: &[(OutputInfo, Option)], cursor_overlay: bool, ) -> Result> { let frame_copies = thread::scope(|scope| -> Result<_> { let join_handles = output_capture_regions - .into_iter() + .iter() .map(|(output_info, capture_region)| { scope.spawn(move || { - self.capture_frame_copy( - cursor_overlay, - &output_info, - capture_region.clone(), - ) - .map(|(frame_copy, frame_guard)| { - (frame_copy, frame_guard, output_info.clone()) - }) + self.capture_frame_copy(cursor_overlay, output_info, *capture_region) + .map(|(frame_copy, frame_guard)| { + (frame_copy, frame_guard, output_info.clone()) + }) }) }) .collect::>(); join_handles .into_iter() - .map(|join_handle| join_handle.join()) - .flatten() + .flat_map(|join_handle| join_handle.join()) .collect::>() })?; Ok(frame_copies) } - fn overlay_frames(&self, frames: &Vec<(FrameCopy, FrameGuard, OutputInfo)>) -> Result<()> { + fn overlay_frames(&self, frames: &[(FrameCopy, FrameGuard, OutputInfo)]) -> Result<()> { let mut state = LayerShellState { configured_outputs: HashSet::new(), }; @@ -506,15 +501,15 @@ impl WayshotConnection { region_capturer: RegionCapturer, cursor_overlay: bool, ) -> Result { - let outputs_capture_regions: &Vec<(OutputInfo, Option)> = - &match region_capturer { + let outputs_capture_regions: Vec<(OutputInfo, Option)> = + match region_capturer { RegionCapturer::Outputs(ref outputs) => outputs - .into_iter() + .iter() .map(|output_info| (output_info.clone(), None)) .collect(), RegionCapturer::Region(capture_region) => self .get_all_outputs() - .into_iter() + .iter() .filter_map(|output_info| { tracing::span!( tracing::Level::DEBUG, @@ -541,15 +536,15 @@ impl WayshotConnection { .collect(), RegionCapturer::Freeze(_) => self .get_all_outputs() - .into_iter() + .iter() .map(|output_info| (output_info.clone(), None)) .collect(), }; - let frames = self.capture_frame_copies(outputs_capture_regions, cursor_overlay)?; + let frames = self.capture_frame_copies(&outputs_capture_regions, cursor_overlay)?; let capture_region: LogicalRegion = match region_capturer { - RegionCapturer::Outputs(ref outputs) => outputs.try_into()?, + RegionCapturer::Outputs(outputs) => outputs.as_slice().try_into()?, RegionCapturer::Region(region) => region, RegionCapturer::Freeze(callback) => { self.overlay_frames(&frames).and_then(|_| callback())? @@ -565,7 +560,7 @@ impl WayshotConnection { .map(|(output_info, _)| output_info.scale()) .fold(1.0, f64::max); - tracing::Span::current().record("max_scale", &max_scale); + tracing::Span::current().record("max_scale", max_scale); let rotate_join_handles = frames .into_iter() @@ -587,8 +582,7 @@ impl WayshotConnection { rotate_join_handles .into_iter() - .map(|join_handle| join_handle.join()) - .flatten() + .flat_map(|join_handle| join_handle.join()) .fold( None, |composite_image: Option>, image: Result<_>| { @@ -666,14 +660,14 @@ impl WayshotConnection { /// Take a screenshot from all of the specified outputs. pub fn screenshot_outputs( &self, - outputs: &Vec, + outputs: &[OutputInfo], cursor_overlay: bool, ) -> Result { if outputs.is_empty() { return Err(Error::NoOutputs); } - self.screenshot_region_capturer(RegionCapturer::Outputs(outputs.clone()), cursor_overlay) + self.screenshot_region_capturer(RegionCapturer::Outputs(outputs.to_owned()), cursor_overlay) } /// Take a screenshot from all accessible outputs. diff --git a/libwayshot/src/region.rs b/libwayshot/src/region.rs index 394e1fb3..6813ded2 100644 --- a/libwayshot/src/region.rs +++ b/libwayshot/src/region.rs @@ -116,7 +116,7 @@ impl EmbeddedRegion { }; Some(Self { - relative_to: relative_to, + relative_to, inner: Region { position: Position { x: x1, y: y1 }, size: Size { width, height }, @@ -195,10 +195,10 @@ impl From<&OutputInfo> for LogicalRegion { } } -impl TryFrom<&Vec> for LogicalRegion { +impl TryFrom<&[OutputInfo]> for LogicalRegion { type Error = Error; - fn try_from(output_info: &Vec) -> std::result::Result { + fn try_from(output_info: &[OutputInfo]) -> std::result::Result { let x1 = output_info .iter() .map(|output| output.logical_region.inner.position.x) diff --git a/wayshot/src/wayshot.rs b/wayshot/src/wayshot.rs index a1c8ac0d..1a2ca746 100644 --- a/wayshot/src/wayshot.rs +++ b/wayshot/src/wayshot.rs @@ -72,7 +72,7 @@ fn main() -> Result<()> { Box::new(move || { || -> Result { let slurp_output = Command::new("slurp") - .args(slurp_region.split(" ")) + .args(slurp_region.split(' ')) .output()? .stdout; @@ -91,9 +91,9 @@ fn main() -> Result<()> { } } else if cli.choose_output { let outputs = wayshot_conn.get_all_outputs(); - let output_names: Vec = outputs + let output_names: Vec<&str> = outputs .iter() - .map(|display| display.name.to_string()) + .map(|display| display.name.as_str()) .collect(); if let Some(index) = select_ouput(&output_names) { wayshot_conn.screenshot_single_output(&outputs[index], cli.cursor)?