From 95f62eb43d1c09f95ad1ccc395a8c1d749feba1e Mon Sep 17 00:00:00 2001 From: Shinyzenith Date: Mon, 20 Jun 2022 15:53:59 +0530 Subject: [PATCH] [region-capture] out of bounds detection added Signed-off-by: Shinyzenith --- Cargo.lock | 8 ++++---- src/wayshot.rs | 29 ++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c04fa8fe..174e036a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -331,18 +331,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" dependencies = [ "proc-macro2", ] diff --git a/src/wayshot.rs b/src/wayshot.rs index d33f7f91..1a65a372 100644 --- a/src/wayshot.rs +++ b/src/wayshot.rs @@ -1,5 +1,5 @@ use std::{ - env, + cmp, env, error::Error, fs::File, io::{stdout, BufWriter}, @@ -69,6 +69,33 @@ fn main() -> Result<(), Box> { let width = slurp[2]; let height = slurp[3]; + let outputs = output::get_all_outputs(display.clone()); + let mut intersecting_outputs: Vec = Vec::new(); + for output in outputs { + let x1: i32 = cmp::max(output.dimensions.x, x_coordinate); + let y1: i32 = cmp::max(output.dimensions.y, y_coordinate); + let x2: i32 = cmp::min( + output.dimensions.x + output.dimensions.width, + x_coordinate + width, + ); + let y2: i32 = cmp::min( + output.dimensions.y + output.dimensions.height, + y_coordinate + height, + ); + + let width = x2 - x1; + let height = y2 - y1; + + if !(width <= 0 || height <= 0) { + intersecting_outputs.push(output); + } + } + if intersecting_outputs.is_empty() { + log::error!("Provided capture region doesn't intersect with any outputs!"); + exit(1); + } + // NOTE: Figure out box bounds for multi monitor screenshot. + backend::capture_output_frame( display, cursor_overlay,