Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Add logical size to display info and improve screenshot debug

Richie McIlroy9776ecd8cd24
diff --git a/apps/desktop/src-tauri/src/target_select_overlay.rs b/apps/desktop/src-tauri/src/target_select_overlay.rs
index d52424235..1ea7a0642 100644
--- a/apps/desktop/src-tauri/src/target_select_overlay.rs
+++ b/apps/desktop/src-tauri/src/target_select_overlay.rs
@@ -15,7 +15,7 @@ use crate::{
};
use scap_targets::{
Display, DisplayId, Window, WindowId,
- bounds::{LogicalBounds, PhysicalSize},
+ bounds::{LogicalBounds, LogicalSize, PhysicalSize},
};
use serde::Serialize;
use specta::Type;
@@ -42,6 +42,7 @@ pub struct WindowUnderCursor {
pub struct DisplayInformation {
name: Option<String>,
physical_size: Option<PhysicalSize>,
+ logical_size: Option<LogicalSize>,
refresh_rate: String,
}
@@ -217,6 +218,7 @@ pub async fn display_information(display_id: &str) -> Result<DisplayInformation,
Ok(DisplayInformation {
name: display.name(),
physical_size: display.physical_size(),
+ logical_size: display.logical_size(),
refresh_rate: display.refresh_rate().to_string(),
})
}
diff --git a/apps/desktop/src/routes/target-select-overlay.tsx b/apps/desktop/src/routes/target-select-overlay.tsx
index 1d9455e4f..a9dfab564 100644
--- a/apps/desktop/src/routes/target-select-overlay.tsx
+++ b/apps/desktop/src/routes/target-select-overlay.tsx
@@ -414,6 +414,13 @@ function Inner() {
if (win) setCameraWindow(win);
});
+ const areaDisplayInfo = useQuery(() => ({
+ queryKey: ["areaDisplayInfo", displayId()],
+ queryFn: async () => {
+ return await commands.displayInformation(displayId());
+ },
+ }));
+
const [aspect, setAspect] = createSignal<Ratio | null>(null);
const [snapToRatioEnabled, setSnapToRatioEnabled] =
createSignal(true);
@@ -698,21 +705,36 @@ function Inner() {
if (was && !interacting) {
if (options.mode === "screenshot" && isValid()) {
+ const cropBounds = crop();
+ const displayInfo = areaDisplayInfo.data;
+ console.log("[Screenshot Debug] crop bounds:", cropBounds);
+ console.log("[Screenshot Debug] display info:", displayInfo);
+ console.log(
+ "[Screenshot Debug] window.innerWidth/Height:",
+ window.innerWidth,
+ window.innerHeight,
+ );
+
const target: ScreenCaptureTarget = {
variant: "area",
screen: displayId(),
bounds: {
position: {
- x: crop().x,
- y: crop().y,
+ x: cropBounds.x,
+ y: cropBounds.y,
},
size: {
- width: crop().width,
- height: crop().height,
+ width: cropBounds.width,
+ height: cropBounds.height,
},
},
};
+ console.log(
+ "[Screenshot Debug] target being sent:",
+ JSON.stringify(target, null, 2),
+ );
+
try {
const path = await invoke<string>("take_screenshot", {
target,
diff --git a/crates/recording/src/screenshot.rs b/crates/recording/src/screenshot.rs
index 56adedf4c..f3d1dfee0 100644
--- a/crates/recording/src/screenshot.rs
+++ b/crates/recording/src/screenshot.rs
@@ -149,13 +149,35 @@ fn try_fast_capture(target: &ScreenCaptureTarget) -> Option<RgbImage> {
let display = scap_targets::Display::from_id(screen)?;
let display_id = display.raw_handle().inner().id;
let scale = display.raw_handle().scale().unwrap_or(1.0);
+ let display_bounds = display.raw_handle().logical_bounds();
+ let display_physical = display.physical_size();
+
+ tracing::info!(
+ "Area screenshot debug: display_id={}, display_logical_bounds={:?}, display_physical={:?}",
+ display_id,
+ display_bounds,
+ display_physical,
+ );
+ tracing::info!(
+ "Area screenshot: input logical bounds=({}, {}, {}x{}), scale={}",
+ bounds.position().x(),
+ bounds.position().y(),
+ bounds.size().width(),
+ bounds.size().height(),
+ scale,
+ );
let rect = CGRect::new(
- &CGPoint::new(bounds.position().x() * scale, bounds.position().y() * scale),
- &CGSize::new(
- bounds.size().width() * scale,
- bounds.size().height() * scale,
- ),
+ &CGPoint::new(bounds.position().x(), bounds.position().y()),
+ &CGSize::new(bounds.size().width(), bounds.size().height()),
+ );
+
+ tracing::info!(
+ "Area screenshot: CGRect for capture (logical/points) = origin({}, {}), size({}x{})",
+ rect.origin.x,
+ rect.origin.y,
+ rect.size.width,
+ rect.size.height,
);
let image = unsafe { CGDisplayCreateImageForRect(display_id, rect) };
@@ -170,6 +192,12 @@ fn try_fast_capture(target: &ScreenCaptureTarget) -> Option<RgbImage> {
let height = cg_image.height();
let bytes_per_row = cg_image.bytes_per_row();
+ tracing::info!(
+ "Fast capture result: image dimensions = {}x{}",
+ width,
+ height,
+ );
+
use core_foundation::data::CFData;
let cf_data: CFData = cg_image.data();
let data = cf_data.bytes();