Skip to content

Commit

Permalink
[region-capture] out of bounds detection added
Browse files Browse the repository at this point in the history
Signed-off-by: Shinyzenith <[email protected]>
  • Loading branch information
Shinyzenith committed Jun 20, 2022
1 parent 9c1b380 commit 95f62eb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 28 additions & 1 deletion src/wayshot.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
env,
cmp, env,
error::Error,
fs::File,
io::{stdout, BufWriter},
Expand Down Expand Up @@ -69,6 +69,33 @@ fn main() -> Result<(), Box<dyn Error>> {
let width = slurp[2];
let height = slurp[3];

let outputs = output::get_all_outputs(display.clone());
let mut intersecting_outputs: Vec<output::OutputInfo> = 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,
Expand Down

0 comments on commit 95f62eb

Please sign in to comment.