Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Improve camera overlay resizing and editor captions state

Richie McIlroyfe7dd1db71b7
diff --git a/apps/desktop/src-tauri/src/camera.rs b/apps/desktop/src-tauri/src/camera.rs
index 953280711..8ef4c5329 100644
--- a/apps/desktop/src-tauri/src/camera.rs
+++ b/apps/desktop/src-tauri/src/camera.rs
@@ -116,6 +116,16 @@ impl CameraPreviewManager {
self.preview.is_some()
}
+ pub fn notify_window_resized(&self, width: u32, height: u32) {
+ if let Some(preview) = &self.preview {
+ preview
+ .reconfigure
+ .send(ReconfigureEvent::WindowResized { width, height })
+ .map_err(|err| error!("Error notifying camera preview of resize: {err}"))
+ .ok();
+ }
+ }
+
/// Initialize the camera preview for a specific Tauri window
pub async fn init_window(
&mut self,
@@ -169,6 +179,7 @@ impl CameraPreviewManager {
#[derive(Clone)]
enum ReconfigureEvent {
State(CameraPreviewState),
+ WindowResized { width: u32, height: u32 },
Shutdown,
}
@@ -604,6 +615,10 @@ impl Renderer {
self.reconfigure_gpu_surface(width, height);
}
}
+ Err(ReconfigureEvent::WindowResized { width, height }) => {
+ trace!("CameraPreview/ReconfigureEvent.WindowResized({width}x{height})");
+ self.reconfigure_gpu_surface(width, height);
+ }
Err(ReconfigureEvent::Shutdown) => return,
}
}
diff --git a/apps/desktop/src-tauri/src/target_select_overlay.rs b/apps/desktop/src-tauri/src/target_select_overlay.rs
index e41efe5e9..7bb4e31cd 100644
--- a/apps/desktop/src-tauri/src/target_select_overlay.rs
+++ b/apps/desktop/src-tauri/src/target_select_overlay.rs
@@ -9,7 +9,7 @@ use base64::prelude::*;
use cap_recording::screen_capture::ScreenCaptureTarget;
use crate::{
- general_settings,
+ App, ArcLock, general_settings,
window_exclusion::WindowExclusion,
windows::{CapWindowId, ShowCapWindow},
};
@@ -163,10 +163,13 @@ pub async fn update_camera_overlay_bounds(
.get_webview_window("camera")
.ok_or("Camera window not found")?;
+ let width_u32 = width as u32;
+ let height_u32 = height as u32;
+
window
.set_size(tauri::Size::Physical(tauri::PhysicalSize {
- width: width as u32,
- height: height as u32,
+ width: width_u32,
+ height: height_u32,
}))
.map_err(|e| e.to_string())?;
window
@@ -176,6 +179,16 @@ pub async fn update_camera_overlay_bounds(
}))
.map_err(|e| e.to_string())?;
+ let scale_factor = window.scale_factor().unwrap_or(1.0);
+ let logical_width = (width / scale_factor) as u32;
+ let logical_height = (height / scale_factor) as u32;
+
+ let state = app.state::<ArcLock<App>>();
+ let app_state = state.read().await;
+ app_state
+ .camera_preview
+ .notify_window_resized(logical_width, logical_height);
+
Ok(())
}
diff --git a/apps/desktop/src/routes/camera.tsx b/apps/desktop/src/routes/camera.tsx
index ef950cbce..3b72a1f1f 100644
--- a/apps/desktop/src/routes/camera.tsx
+++ b/apps/desktop/src/routes/camera.tsx
@@ -700,6 +700,7 @@ function Canvas(props: {
latestFrame: Accessor<{ width: number; data: ImageData } | null | undefined>;
state: CameraWindowState;
ref: HTMLCanvasElement | undefined;
+ containerSize?: { width: number; height: number };
}) {
const style = () => {
const frame = props.latestFrame();
@@ -707,8 +708,10 @@ function Canvas(props: {
const aspectRatio = frame.data.width / frame.data.height;
- // Use state.size directly for immediate feedback
- const base = props.state.size;
+ // Use container size if available (for external resize), otherwise use state.size
+ const base = props.containerSize
+ ? Math.min(props.containerSize.width, props.containerSize.height)
+ : props.state.size;
// Replicate window size logic synchronously for the canvas
const winWidth =
@@ -741,7 +744,7 @@ function Canvas(props: {
else
return {
width: base,
- height: base * aspectRatio,
+ height: base / aspectRatio,
};
})();
diff --git a/apps/desktop/src/routes/editor/CaptionsTab.tsx b/apps/desktop/src/routes/editor/CaptionsTab.tsx
index 7b6a00327..356bfa493 100644
--- a/apps/desktop/src/routes/editor/CaptionsTab.tsx
+++ b/apps/desktop/src/routes/editor/CaptionsTab.tsx
@@ -150,7 +150,7 @@ function RgbInput(props: { value: string; onChange: (value: string) => void }) {
}
export function CaptionsTab() {
- const { project, setProject, editorInstance, editorState } =
+ const { project, setProject, editorInstance, editorState, setEditorState } =
useEditorContext();
const getSetting = <K extends keyof CaptionSettings>(
@@ -172,12 +172,18 @@ export function CaptionsTab() {
const [selectedLanguage, setSelectedLanguage] = createSignal("auto");
const [downloadedModels, setDownloadedModels] = createSignal<string[]>([]);
- const [isDownloading, setIsDownloading] = createSignal(false);
- const [downloadProgress, setDownloadProgress] = createSignal(0);
- const [downloadingModel, setDownloadingModel] = createSignal<string | null>(
- null,
- );
- const [isGenerating, setIsGenerating] = createSignal(false);
+ const isDownloading = () => editorState.captions.isDownloading;
+ const setIsDownloading = (value: boolean) =>
+ setEditorState("captions", "isDownloading", value);
+ const downloadProgress = () => editorState.captions.downloadProgress;
+ const setDownloadProgress = (value: number) =>
+ setEditorState("captions", "downloadProgress", value);
+ const downloadingModel = () => editorState.captions.downloadingModel;
+ const setDownloadingModel = (value: string | null) =>
+ setEditorState("captions", "downloadingModel", value);
+ const isGenerating = () => editorState.captions.isGenerating;
+ const setIsGenerating = (value: boolean) =>
+ setEditorState("captions", "isGenerating", value);
const [hasAudio, setHasAudio] = createSignal(false);
createEffect(
diff --git a/apps/desktop/src/routes/editor/context.ts b/apps/desktop/src/routes/editor/context.ts
index 80295b0ff..1c6bec435 100644
--- a/apps/desktop/src/routes/editor/context.ts
+++ b/apps/desktop/src/routes/editor/context.ts
@@ -612,6 +612,12 @@ export const [EditorContextProvider, useEditorContext] = createContextProvider(
previewTime: null as number | null,
playbackTime: 0,
playing: false,
+ captions: {
+ isGenerating: false,
+ isDownloading: false,
+ downloadProgress: 0,
+ downloadingModel: null as string | null,
+ },
timeline: {
interactMode: "seek" as "seek" | "split",
selection: null as
diff --git a/apps/desktop/src/routes/target-select-overlay.tsx b/apps/desktop/src/routes/target-select-overlay.tsx
index 638974c36..f341b96b6 100644
--- a/apps/desktop/src/routes/target-select-overlay.tsx
+++ b/apps/desktop/src/routes/target-select-overlay.tsx
@@ -536,23 +536,34 @@ function Inner() {
const originalLogicalSize = original.size.toLogical(scaleFactor);
const padding = 16;
+ const TOOLBAR_HEIGHT = 56;
+ const originalContentWidth = originalLogicalSize.width;
+ const originalContentHeight = Math.max(
+ 0,
+ originalLogicalSize.height - TOOLBAR_HEIGHT,
+ );
+
const selectionMinDim = Math.min(bounds.width, bounds.height);
- const targetMaxDim = Math.max(
- 150,
+ const targetContentMaxDim = Math.max(
+ 100,
Math.min(
- Math.max(originalLogicalSize.width, originalLogicalSize.height),
- selectionMinDim * 0.5,
+ Math.max(originalContentWidth, originalContentHeight),
+ selectionMinDim * 0.5 - TOOLBAR_HEIGHT,
),
);
- const originalMaxDim = Math.max(
- originalLogicalSize.width,
- originalLogicalSize.height,
+ const originalContentMaxDim = Math.max(
+ originalContentWidth,
+ originalContentHeight,
);
- const scale = targetMaxDim / originalMaxDim;
+ const scale =
+ originalContentMaxDim > 0
+ ? targetContentMaxDim / originalContentMaxDim
+ : 1;
- const newWidth = Math.round(originalLogicalSize.width * scale);
- const newHeight = Math.round(originalLogicalSize.height * scale);
+ const newWidth = Math.round(originalContentWidth * scale);
+ const newHeight =
+ Math.round(originalContentHeight * scale) + TOOLBAR_HEIGHT;
if (
bounds.width > newWidth + padding * 2 &&
@@ -580,6 +591,12 @@ function Inner() {
if (original && win) {
await win.setPosition(original.position);
await win.setSize(original.size);
+ await commands.updateCameraOverlayBounds(
+ original.position.x,
+ original.position.y,
+ original.size.width,
+ original.size.height,
+ );
setOriginalCameraBounds(null);
setTargetState(null);
lastApplied = null;
diff --git a/bash.exe.stackdump b/bash.exe.stackdump
new file mode 100644
index 000000000..9c9810c04
--- /dev/null
+++ b/bash.exe.stackdump
@@ -0,0 +1,28 @@
+Stack trace:
+Frame Function Args
+0007FFFFB360 00021005FE8E (000210285F68, 00021026AB6E, 000000000000, 0007FFFFA260) msys-2.0.dll+0x1FE8E
+0007FFFFB360 0002100467F9 (000000000000, 000000000000, 000000000000, 0007FFFFB638) msys-2.0.dll+0x67F9
+0007FFFFB360 000210046832 (000210286019, 0007FFFFB218, 000000000000, 000000000000) msys-2.0.dll+0x6832
+0007FFFFB360 000210068CF6 (000000000000, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x28CF6
+0007FFFFB360 000210068E24 (0007FFFFB370, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x28E24
+0007FFFFB640 00021006A225 (0007FFFFB370, 000000000000, 000000000000, 000000000000) msys-2.0.dll+0x2A225
+End of stack trace
+Loaded modules:
+000100400000 bash.exe
+7FFE664C0000 ntdll.dll
+7FFE65400000 KERNEL32.DLL
+7FFE63610000 KERNELBASE.dll
+7FFE64260000 USER32.dll
+000210040000 msys-2.0.dll
+7FFE64180000 win32u.dll
+7FFE64EE0000 GDI32.dll
+7FFE63B60000 gdi32full.dll
+7FFE641B0000 msvcp_win.dll
+7FFE63A10000 ucrtbase.dll
+7FFE657E0000 advapi32.dll
+7FFE648D0000 msvcrt.dll
+7FFE65A90000 sechost.dll
+7FFE64DC0000 RPCRT4.dll
+7FFE62C40000 CRYPTBASE.DLL
+7FFE64040000 bcryptPrimitives.dll
+7FFE65600000 IMM32.DLL
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs
index 0038cb9b8..b07bffdab 100644
--- a/crates/rendering/src/lib.rs
+++ b/crates/rendering/src/lib.rs
@@ -1368,12 +1368,15 @@ impl ProjectUniforms {
let crop_bounds = match project.camera.shape {
CameraShape::Source => [0.0, 0.0, frame_size[0], frame_size[1]],
- CameraShape::Square => [
- (frame_size[0] - frame_size[1]) / 2.0,
- 0.0,
- frame_size[0] - (frame_size[0] - frame_size[1]) / 2.0,
- frame_size[1],
- ],
+ CameraShape::Square => {
+ if frame_size[0] > frame_size[1] {
+ let offset = (frame_size[0] - frame_size[1]) / 2.0;
+ [offset, 0.0, frame_size[0] - offset, frame_size[1]]
+ } else {
+ let offset = (frame_size[1] - frame_size[0]) / 2.0;
+ [0.0, offset, frame_size[0], frame_size[1] - offset]
+ }
+ }
};
CompositeVideoFrameUniforms {