Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(recording): use x11_capture_rect for Linux screenshot geometry

Richie McIlroy706ac3dd2123
diff --git a/crates/recording/src/screenshot.rs b/crates/recording/src/screenshot.rs
index 362e1441c..7f7bbe42e 100644
--- a/crates/recording/src/screenshot.rs
+++ b/crates/recording/src/screenshot.rs
@@ -1,6 +1,8 @@
use crate::sources::screen_capture::ScreenCaptureTarget;
#[cfg(target_os = "linux")]
-use crate::sources::screen_capture::{X11InputConfig, frame_from_x11_packet, open_x11_input};
+use crate::sources::screen_capture::{
+ X11InputConfig, frame_from_x11_packet, open_x11_input, x11_capture_rect,
+};
#[cfg(target_os = "macos")]
use anyhow::Context;
#[cfg(target_os = "linux")]
@@ -1264,28 +1266,46 @@ fn linux_capture_geometry(
let size = display
.physical_size()
.ok_or_else(|| anyhow!("Display size unavailable"))?;
- Ok((
- display_name,
- position.x() as i32,
- position.y() as i32,
- size.width().max(1.0) as u32,
- size.height().max(1.0) as u32,
- ))
+ let (x, y, width, height) = x11_capture_rect(
+ position.x(),
+ position.y(),
+ size.width(),
+ size.height(),
+ None,
+ )?;
+ Ok((display_name, x, y, width, height))
}
ScreenCaptureTarget::Window { id } => {
let window =
scap_targets::Window::from_id(id).ok_or_else(|| anyhow!("Window not found"))?;
+ let display = window
+ .display()
+ .ok_or_else(|| anyhow!("Window display unavailable"))?;
+ let display_position = display
+ .raw_handle()
+ .physical_position()
+ .ok_or_else(|| anyhow!("Display position unavailable"))?;
+ let display_size = display
+ .physical_size()
+ .ok_or_else(|| anyhow!("Display size unavailable"))?;
let bounds = window
.raw_handle()
.physical_bounds()
.ok_or_else(|| anyhow!("Window bounds unavailable"))?;
- Ok((
- display_name,
- bounds.position().x() as i32,
- bounds.position().y() as i32,
- bounds.size().width().max(1.0) as u32,
- bounds.size().height().max(1.0) as u32,
- ))
+ let crop = (
+ bounds.position().x() - display_position.x(),
+ bounds.position().y() - display_position.y(),
+ bounds.size().width(),
+ bounds.size().height(),
+ );
+ let (x, y, width, height) = x11_capture_rect(
+ display_position.x(),
+ display_position.y(),
+ display_size.width(),
+ display_size.height(),
+ Some(crop),
+ )?;
+ Ok((display_name, x, y, width, height))
}
ScreenCaptureTarget::Area { screen, bounds } => {
let display = scap_targets::Display::from_id(screen)
@@ -1294,13 +1314,23 @@ fn linux_capture_geometry(
.raw_handle()
.physical_position()
.ok_or_else(|| anyhow!("Display position unavailable"))?;
- Ok((
- display_name,
- position.x() as i32 + bounds.position().x().max(0.0) as i32,
- position.y() as i32 + bounds.position().y().max(0.0) as i32,
- bounds.size().width().max(1.0) as u32,
- bounds.size().height().max(1.0) as u32,
- ))
+ let size = display
+ .physical_size()
+ .ok_or_else(|| anyhow!("Display size unavailable"))?;
+ let crop = (
+ bounds.position().x(),
+ bounds.position().y(),
+ bounds.size().width(),
+ bounds.size().height(),
+ );
+ let (x, y, width, height) = x11_capture_rect(
+ position.x(),
+ position.y(),
+ size.width(),
+ size.height(),
+ Some(crop),
+ )?;
+ Ok((display_name, x, y, width, height))
}
ScreenCaptureTarget::CameraOnly => {
Err(anyhow!("Camera-only not supported for screenshots"))