Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
Improve window positioning and target mode handling
Richie McIlroy9eac7cc6b683
diff --git a/apps/desktop/src-tauri/src/camera.rs b/apps/desktop/src-tauri/src/camera.rsindex 8ef4c5329..ca7864a01 100644--- a/apps/desktop/src-tauri/src/camera.rs+++ b/apps/desktop/src-tauri/src/camera.rs@@ -198,7 +198,7 @@ impl InitializedCameraPreview {1.0};- let size = resize_window(&window, default_state, aspect, true)+ let size = resize_window(&window, default_state, aspect, false).context("Error resizing Tauri window")?;let (tx, rx) = oneshot::channel();diff --git a/apps/desktop/src-tauri/src/fake_window.rs b/apps/desktop/src-tauri/src/fake_window.rsindex 149b0952e..fb99656a2 100644--- a/apps/desktop/src-tauri/src/fake_window.rs+++ b/apps/desktop/src-tauri/src/fake_window.rs@@ -1,9 +1,14 @@-use scap_targets::bounds::LogicalBounds;+use scap_targets::{Display, DisplayId, bounds::LogicalBounds};use std::{collections::HashMap, sync::Arc, time::Duration};use tauri::{AppHandle, Manager, WebviewWindow};use tokio::{sync::RwLock, time::sleep};use tracing::instrument;+const RECORDING_CONTROLS_LABEL: &str = "in-progress-recording";+const RECORDING_CONTROLS_WIDTH: f64 = 320.0;+const RECORDING_CONTROLS_HEIGHT: f64 = 150.0;+const RECORDING_CONTROLS_OFFSET_Y: f64 = 120.0;+pub struct FakeWindowBounds(pub Arc<RwLock<HashMap<String, HashMap<String, LogicalBounds>>>>);#[tauri::command]@@ -45,15 +50,57 @@ pub async fn remove_fake_window(Ok(())}+fn get_display_id_for_cursor() -> Option<DisplayId> {+ Display::get_containing_cursor().map(|d| d.id())+}++fn get_display_by_id(id: &DisplayId) -> Option<Display> {+ Display::list().into_iter().find(|d| &d.id() == id)+}++fn calculate_bottom_center_position(display: &Display) -> Option<(f64, f64)> {+ let bounds = display.raw_handle().logical_bounds()?;+ let x = bounds.position().x();+ let y = bounds.position().y();+ let width = bounds.size().width();+ let height = bounds.size().height();++ let pos_x = x + (width - RECORDING_CONTROLS_WIDTH) / 2.0;+ let pos_y = y + height - RECORDING_CONTROLS_HEIGHT - RECORDING_CONTROLS_OFFSET_Y;+ Some((pos_x, pos_y))+}+pub fn spawn_fake_window_listener(app: AppHandle, window: WebviewWindow) {window.set_ignore_cursor_events(true).ok();+ let is_recording_controls = window.label() == RECORDING_CONTROLS_LABEL;+tokio::spawn(async move {let state = app.state::<FakeWindowBounds>();+ let mut current_display_id: Option<DisplayId> = get_display_id_for_cursor();loop {sleep(Duration::from_millis(1000 / 20)).await;+ if is_recording_controls {+ if let Some(cursor_display_id) = get_display_id_for_cursor() {+ let display_changed = current_display_id+ .as_ref()+ .map_or(true, |id| id != &cursor_display_id);++ if display_changed {+ if let Some(display) = get_display_by_id(&cursor_display_id) {+ if let Some((pos_x, pos_y)) = calculate_bottom_center_position(&display)+ {+ let _ =+ window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));+ current_display_id = Some(cursor_display_id);+ }+ }+ }+ }+ }+let map = state.0.read().await;let Some(windows) = map.get(window.label()) else {@@ -86,7 +133,6 @@ pub fn spawn_fake_window_listener(app: AppHandle, window: WebviewWindow) {&& mouse_position.y <= y_max{ignore = false;- // ShowCapturesPanel.emit(&app).ok();break;}}diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rsindex 502fad337..77071fb0c 100644--- a/apps/desktop/src-tauri/src/lib.rs+++ b/apps/desktop/src-tauri/src/lib.rs@@ -901,6 +901,12 @@ pub struct RequestOpenRecordingPicker {pub target_mode: Option<RecordingTargetMode>,}+#[derive(Deserialize, specta::Type, Serialize, tauri_specta::Event, Debug, Clone)]+pub struct RequestSetTargetMode {+ pub target_mode: Option<RecordingTargetMode>,+ pub display_id: Option<String>,+}+#[derive(Deserialize, specta::Type, Serialize, tauri_specta::Event, Debug, Clone)]pub struct RequestOpenSettings {page: String,@@ -2673,6 +2679,7 @@ pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {RecordingStopped,RequestStartRecording,RequestOpenRecordingPicker,+ RequestSetTargetMode,RequestOpenSettings,RequestScreenCapturePrewarm,NewNotification,diff --git a/apps/desktop/src-tauri/src/target_select_overlay.rs b/apps/desktop/src-tauri/src/target_select_overlay.rsindex 7bb4e31cd..05372d9eb 100644--- a/apps/desktop/src-tauri/src/target_select_overlay.rs+++ b/apps/desktop/src-tauri/src/target_select_overlay.rs@@ -43,6 +43,7 @@ pub struct DisplayInformation {name: Option<String>,physical_size: Option<PhysicalSize>,logical_size: Option<LogicalSize>,+ logical_bounds: Option<LogicalBounds>,refresh_rate: String,}@@ -53,17 +54,35 @@ pub async fn open_target_select_overlays(app: AppHandle,state: tauri::State<'_, WindowFocusManager>,focused_target: Option<ScreenCaptureTarget>,+ specific_display_id: Option<String>,) -> Result<(), String> {- let displays = scap_targets::Display::list()- .into_iter()- .map(|d| d.id())- .collect::<Vec<_>>();- for display_id in displays {- let _ = ShowCapWindow::TargetSelectOverlay { display_id }- .show(&app)- .await;+ let display_id = if let Some(id_str) = specific_display_id {+ id_str+ .parse::<DisplayId>()+ .unwrap_or_else(|_| Display::primary().id())+ } else if let Some(display) = focused_target.as_ref().and_then(|t| t.display()) {+ display.id()+ } else {+ Display::get_containing_cursor()+ .map(|d| d.id())+ .unwrap_or_else(|| Display::primary().id())+ };++ for (id, window) in app.webview_windows() {+ if let Ok(CapWindowId::TargetSelectOverlay {+ display_id: existing_id,+ }) = CapWindowId::from_str(&id)+ {+ if existing_id != display_id {+ let _ = window.close();+ }+ }}+ let _ = ShowCapWindow::TargetSelectOverlay { display_id }+ .show(&app)+ .await;+let window_exclusions = general_settings::GeneralSettingsStore::get(&app).ok().flatten()@@ -232,6 +251,7 @@ pub async fn display_information(display_id: &str) -> Result<DisplayInformation,name: display.name(),physical_size: display.physical_size(),logical_size: display.logical_size(),+ logical_bounds: display.raw_handle().logical_bounds(),refresh_rate: display.refresh_rate().to_string(),})}diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rsindex ecd719f1a..15501da22 100644--- a/apps/desktop/src-tauri/src/windows.rs+++ b/apps/desktop/src-tauri/src/windows.rs@@ -21,7 +21,7 @@ use tokio::sync::RwLock;use tracing::{debug, error, instrument, warn};use crate::{- App, ArcLock, RequestScreenCapturePrewarm,+ App, ArcLock, RequestScreenCapturePrewarm, RequestSetTargetMode,editor_window::PendingEditorInstances,fake_window,general_settings::{self, AppTheme, GeneralSettingsStore},@@ -35,6 +35,96 @@ use cap_recording::feeds;#[cfg(target_os = "macos")]const DEFAULT_TRAFFIC_LIGHTS_INSET: LogicalPosition<f64> = LogicalPosition::new(12.0, 12.0);+const DEFAULT_FALLBACK_DISPLAY_WIDTH: f64 = 1920.0;+const DEFAULT_FALLBACK_DISPLAY_HEIGHT: f64 = 1080.0;++struct CursorMonitorInfo {+ x: f64,+ y: f64,+ width: f64,+ height: f64,+}++impl CursorMonitorInfo {+ fn get() -> Self {+ let display = Display::get_containing_cursor().unwrap_or_else(Display::primary);+ let bounds = display.raw_handle().logical_bounds();+ let (x, y, width, height) = bounds+ .map(|b| {+ (+ b.position().x(),+ b.position().y(),+ b.size().width(),+ b.size().height(),+ )+ })+ .unwrap_or((+ 0.0,+ 0.0,+ DEFAULT_FALLBACK_DISPLAY_WIDTH,+ DEFAULT_FALLBACK_DISPLAY_HEIGHT,+ ));++ Self {+ x,+ y,+ width,+ height,+ }+ }++ fn center_position(&self, window_width: f64, window_height: f64) -> (f64, f64) {+ let pos_x = self.x + (self.width - window_width) / 2.0;+ let pos_y = self.y + (self.height - window_height) / 2.0;+ (pos_x, pos_y)+ }++ fn bottom_center_position(+ &self,+ window_width: f64,+ window_height: f64,+ offset_y: f64,+ ) -> (f64, f64) {+ let pos_x = self.x + (self.width - window_width) / 2.0;+ let pos_y = self.y + self.height - window_height - offset_y;+ (pos_x, pos_y)+ }++ fn from_window(window: &tauri::WebviewWindow) -> Self {+ let window_pos = window+ .outer_position()+ .ok()+ .map(|p| (p.x as f64, p.y as f64))+ .unwrap_or((0.0, 0.0));++ for display in Display::list() {+ if let Some(bounds) = display.raw_handle().logical_bounds() {+ let (x, y, width, height) = (+ bounds.position().x(),+ bounds.position().y(),+ bounds.size().width(),+ bounds.size().height(),+ );++ if window_pos.0 >= x+ && window_pos.0 < x + width+ && window_pos.1 >= y+ && window_pos.1 < y + height+ {+ return Self {+ x,+ y,+ width,+ height,+ };+ }+ }+ }++ Self::get()+ }+}+#[derive(Clone, Deserialize, Type)]pub enum CapWindowId {// Contains onboarding + permissions@@ -262,14 +352,67 @@ impl ShowCapWindow {}if let Some(window) = self.id(app).get(app) {+ let cursor_display_id = if let Self::Main { init_target_mode } = self {+ if init_target_mode.is_some() {+ Display::get_containing_cursor()+ .map(|d| d.id().to_string())+ .or_else(|| Some(Display::primary().id().to_string()))+ } else {+ None+ }+ } else {+ None+ };++ match self {+ Self::Main { .. } => {+ let cursor_monitor = CursorMonitorInfo::get();+ let (pos_x, pos_y) = cursor_monitor.center_position(330.0, 345.0);+ let _ = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));++ if let Some(camera_window) = CapWindowId::Camera.get(app) {+ const WINDOW_SIZE: f64 = 230.0 * 2.0;+ let camera_pos_x =+ cursor_monitor.x + cursor_monitor.width - WINDOW_SIZE - 100.0;+ let camera_pos_y =+ cursor_monitor.y + cursor_monitor.height - WINDOW_SIZE - 100.0;+ let _ = camera_window+ .set_position(tauri::LogicalPosition::new(camera_pos_x, camera_pos_y));+ }+ }+ Self::Camera => {+ const WINDOW_SIZE: f64 = 230.0 * 2.0;+ let camera_monitor = CapWindowId::Main+ .get(app)+ .map(|w| CursorMonitorInfo::from_window(&w))+ .unwrap_or_else(CursorMonitorInfo::get);+ let camera_pos_x =+ camera_monitor.x + camera_monitor.width - WINDOW_SIZE - 100.0;+ let camera_pos_y =+ camera_monitor.y + camera_monitor.height - WINDOW_SIZE - 100.0;+ let _ = window+ .set_position(tauri::LogicalPosition::new(camera_pos_x, camera_pos_y));+ }+ _ => {}+ }+window.show().ok();window.unminimize().ok();window.set_focus().ok();++ if let Self::Main { init_target_mode } = self {+ let _ = RequestSetTargetMode {+ target_mode: *init_target_mode,+ display_id: cursor_display_id,+ }+ .emit(app);+ }+return Ok(window);}let _id = self.id(app);- let monitor = app.primary_monitor()?.unwrap();+ let cursor_monitor = CursorMonitorInfo::get();let window = match self {Self::Setup => {@@ -279,20 +422,22 @@ impl ShowCapWindow {.min_inner_size(600.0, 600.0).resizable(false).maximized(false)- .center().focused(true).maximizable(false).shadow(true).build()?;+ let (pos_x, pos_y) = cursor_monitor.center_position(600.0, 600.0);+ let _ = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));+#[cfg(windows)]{use tauri::LogicalSize;if let Err(e) = window.set_size(LogicalSize::new(600.0, 600.0)) {warn!("Failed to set Setup window size on Windows: {}", e);}- if let Err(e) = window.center() {- warn!("Failed to center Setup window on Windows: {}", e);+ if let Err(e) = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y)) {+ warn!("Failed to position Setup window on Windows: {}", e);}}@@ -325,12 +470,8 @@ impl ShowCapWindow {)).build()?;- #[cfg(target_os = "macos")]- {- if let Err(e) = window.center() {- warn!("Failed to center Main window on macOS: {}", e);- }- }+ let (pos_x, pos_y) = cursor_monitor.center_position(330.0, 345.0);+ let _ = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));#[cfg(target_os = "macos")]crate::platform::set_window_level(window.as_ref().window(), 50);@@ -456,12 +597,8 @@ impl ShowCapWindow {.maximized(false).build()?;- #[cfg(target_os = "macos")]- {- if let Err(e) = window.center() {- warn!("Failed to center Settings window on macOS: {}", e);- }- }+ let (pos_x, pos_y) = cursor_monitor.center_position(600.0, 465.0);+ let _ = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));#[cfg(windows)]{@@ -469,8 +606,8 @@ impl ShowCapWindow {if let Err(e) = window.set_size(LogicalSize::new(600.0, 465.0)) {warn!("Failed to set Settings window size on Windows: {}", e);}- if let Err(e) = window.center() {- warn!("Failed to center Settings window on Windows: {}", e);+ if let Err(e) = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y)) {+ warn!("Failed to position Settings window on Windows: {}", e);}}@@ -496,12 +633,8 @@ impl ShowCapWindow {.focused(true).build()?;- #[cfg(target_os = "macos")]- {- if let Err(e) = window.center() {- warn!("Failed to center Editor window on macOS: {}", e);- }- }+ let (pos_x, pos_y) = cursor_monitor.center_position(1275.0, 800.0);+ let _ = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));#[cfg(windows)]{@@ -509,8 +642,8 @@ impl ShowCapWindow {if let Err(e) = window.set_size(LogicalSize::new(1275.0, 800.0)) {warn!("Failed to set Editor window size on Windows: {}", e);}- if let Err(e) = window.center() {- warn!("Failed to center Editor window on Windows: {}", e);+ if let Err(e) = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y)) {+ warn!("Failed to position Editor window on Windows: {}", e);}}@@ -536,12 +669,8 @@ impl ShowCapWindow {.focused(true).build()?;- #[cfg(target_os = "macos")]- {- if let Err(e) = window.center() {- warn!("Failed to center ScreenshotEditor window on macOS: {}", e);- }- }+ let (pos_x, pos_y) = cursor_monitor.center_position(1240.0, 800.0);+ let _ = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));#[cfg(windows)]{@@ -552,8 +681,11 @@ impl ShowCapWindow {e);}- if let Err(e) = window.center() {- warn!("Failed to center ScreenshotEditor window on Windows: {}", e);+ if let Err(e) = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y)) {+ warn!(+ "Failed to position ScreenshotEditor window on Windows: {}",+ e+ );}}@@ -575,12 +707,8 @@ impl ShowCapWindow {.shadow(true).build()?;- #[cfg(target_os = "macos")]- {- if let Err(e) = window.center() {- warn!("Failed to center Upgrade window on macOS: {}", e);- }- }+ let (pos_x, pos_y) = cursor_monitor.center_position(950.0, 850.0);+ let _ = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));#[cfg(windows)]{@@ -588,8 +716,8 @@ impl ShowCapWindow {if let Err(e) = window.set_size(LogicalSize::new(950.0, 850.0)) {warn!("Failed to set Upgrade window size on Windows: {}", e);}- if let Err(e) = window.center() {- warn!("Failed to center Upgrade window on Windows: {}", e);+ if let Err(e) = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y)) {+ warn!("Failed to position Upgrade window on Windows: {}", e);}}@@ -611,12 +739,8 @@ impl ShowCapWindow {.shadow(true).build()?;- #[cfg(target_os = "macos")]- {- if let Err(e) = window.center() {- warn!("Failed to center ModeSelect window on macOS: {}", e);- }- }+ let (pos_x, pos_y) = cursor_monitor.center_position(580.0, 340.0);+ let _ = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));#[cfg(windows)]{@@ -624,8 +748,8 @@ impl ShowCapWindow {if let Err(e) = window.set_size(LogicalSize::new(580.0, 340.0)) {warn!("Failed to set ModeSelect window size on Windows: {}", e);}- if let Err(e) = window.center() {- warn!("Failed to center ModeSelect window on Windows: {}", e);+ if let Err(e) = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y)) {+ warn!("Failed to position ModeSelect window on Windows: {}", e);}}@@ -660,12 +784,6 @@ impl ShowCapWindow {.always_on_top(true).visible_on_all_workspaces(true).skip_taskbar(true)- .position(- 100.0,- (monitor.size().height as f64) / monitor.scale_factor()- - WINDOW_SIZE- - 100.0,- ).initialization_script(format!("window.__CAP__ = window.__CAP__ ?? {{}};@@ -674,10 +792,21 @@ impl ShowCapWindow {state.camera_ws_port)).transparent(true)- .visible(false); // We set this true in `CameraWindowState::init_window`+ .visible(false);let window = window_builder.build()?;+ let camera_monitor = CapWindowId::Main+ .get(app)+ .map(|w| CursorMonitorInfo::from_window(&w))+ .unwrap_or(cursor_monitor);+ let camera_pos_x =+ camera_monitor.x + camera_monitor.width - WINDOW_SIZE - 100.0;+ let camera_pos_y =+ camera_monitor.y + camera_monitor.height - WINDOW_SIZE - 100.0;+ let _ = window+ .set_position(tauri::LogicalPosition::new(camera_pos_x, camera_pos_y));+if let Some(id) = state.selected_camera_id.clone()&& !state.camera_in_use{@@ -837,18 +966,6 @@ impl ShowCapWindow {let title = CapWindowId::RecordingControls.title();let should_protect = should_protect_window(app, &title);- let pos_x = ((monitor.size().width as f64) / monitor.scale_factor() - width) / 2.0;- let pos_y =- (monitor.size().height as f64) / monitor.scale_factor() - height - 120.0;-- debug!(- "InProgressRecording window: monitor size={:?}, scale={}, pos=({}, {})",- monitor.size(),- monitor.scale_factor(),- pos_x,- pos_y- );-#[cfg(target_os = "macos")]let window = {self.window_builder(app, "/in-progress-recording")@@ -861,7 +978,6 @@ impl ShowCapWindow {.visible_on_all_workspaces(true).content_protected(should_protect).inner_size(width, height)- .position(pos_x, pos_y).skip_taskbar(true).initialization_script(format!("window.COUNTDOWN = {};",@@ -882,7 +998,6 @@ impl ShowCapWindow {.visible_on_all_workspaces(true).content_protected(should_protect).inner_size(width, height)- .position(pos_x, pos_y).skip_taskbar(false).initialization_script(format!("window.COUNTDOWN = {};",@@ -890,6 +1005,19 @@ impl ShowCapWindow {)).build()?;+ let (pos_x, pos_y) = cursor_monitor.bottom_center_position(width, height, 120.0);+ let _ = window.set_position(tauri::LogicalPosition::new(pos_x, pos_y));++ debug!(+ "InProgressRecording window: cursor_monitor=({}, {}, {}, {}), pos=({}, {})",+ cursor_monitor.x,+ cursor_monitor.y,+ cursor_monitor.width,+ cursor_monitor.height,+ pos_x,+ pos_y+ );+debug!("InProgressRecording window created: label={}, inner_size={:?}, outer_position={:?}",window.label(),@@ -940,15 +1068,16 @@ impl ShowCapWindow {.visible_on_all_workspaces(true).accept_first_mouse(true).content_protected(should_protect)- .inner_size(- (monitor.size().width as f64) / monitor.scale_factor(),- (monitor.size().height as f64) / monitor.scale_factor(),- )+ .inner_size(cursor_monitor.width, cursor_monitor.height).skip_taskbar(true)- .position(0.0, 0.0).transparent(true).build()?;+ let _ = window.set_position(tauri::LogicalPosition::new(+ cursor_monitor.x,+ cursor_monitor.y,+ ));+#[cfg(target_os = "macos")]{app.run_on_main_thread({diff --git a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsxindex e05c0fb34..ac217e08e 100644--- a/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx+++ b/apps/desktop/src/routes/(window-chrome)/new-main/index.tsx@@ -641,7 +641,10 @@ function Page() {reconcile({ variant: "display", id: target.id }),);setOptions("targetMode", "display");- commands.openTargetSelectOverlays({ variant: "display", id: target.id });+ commands.openTargetSelectOverlays(+ { variant: "display", id: target.id },+ null,+ );setDisplayMenuOpen(false);displayTriggerRef?.focus();};@@ -652,7 +655,10 @@ function Page() {reconcile({ variant: "window", id: target.id }),);setOptions("targetMode", "window");- commands.openTargetSelectOverlays({ variant: "window", id: target.id });+ commands.openTargetSelectOverlays(+ { variant: "window", id: target.id },+ null,+ );setWindowMenuOpen(false);windowTriggerRef?.focus();@@ -680,7 +686,7 @@ function Page() {};const targetMode = __CAP__?.initialTargetMode ?? null;setOptions({ targetMode });- if (targetMode) await commands.openTargetSelectOverlays(null);+ if (targetMode) await commands.openTargetSelectOverlays(null, null);else await commands.closeTargetSelectOverlays();const currentWindow = getCurrentWindow();@@ -705,11 +711,23 @@ function Page() {);});+ const unlistenSetTargetMode = events.requestSetTargetMode.listen(+ async (event) => {+ const newTargetMode = event.payload.target_mode;+ const displayId = event.payload.display_id;+ setOptions({ targetMode: newTargetMode });+ if (newTargetMode)+ await commands.openTargetSelectOverlays(null, displayId);+ else await commands.closeTargetSelectOverlays();+ },+ );+commands.updateAuthPlan();onCleanup(async () => {(await unlistenFocus)?.();(await unlistenResize)?.();+ (await unlistenSetTargetMode)?.();});});@@ -834,7 +852,7 @@ function Page() {if (isRecording()) return;const nextMode = rawOptions.targetMode === mode ? null : mode;setOptions("targetMode", nextMode);- if (nextMode) commands.openTargetSelectOverlays(null);+ if (nextMode) commands.openTargetSelectOverlays(null, null);else commands.closeTargetSelectOverlays();};diff --git a/apps/desktop/src/routes/target-select-overlay.tsx b/apps/desktop/src/routes/target-select-overlay.tsxindex f341b96b6..12d2ac9de 100644--- a/apps/desktop/src/routes/target-select-overlay.tsx+++ b/apps/desktop/src/routes/target-select-overlay.tsx@@ -381,7 +381,7 @@ function Inner() {setOptions({targetMode: "area",});- commands.openTargetSelectOverlays(null);+ commands.openTargetSelectOverlays(null, null);}}>Adjust recording area@@ -494,8 +494,8 @@ function Inner() {if (options.mode === "screenshot") return;const bounds = crop();const interacting = isInteracting();+ const displayInfo = areaDisplayInfo.data;- // Find the camera window if we haven't yetlet win = cameraWindow();if (!win) {// Try to find it@@ -569,6 +569,11 @@ function Inner() {bounds.width > newWidth + padding * 2 &&bounds.height > newHeight + padding * 2) {+ const displayOriginX =+ displayInfo?.logical_bounds?.position?.x ?? 0;+ const displayOriginY =+ displayInfo?.logical_bounds?.position?.y ?? 0;+const newX = Math.round(bounds.x + bounds.width - newWidth - padding,);@@ -577,8 +582,8 @@ function Inner() {);setTargetState({- x: newX * scaleFactor,- y: newY * scaleFactor,+ x: (newX + displayOriginX) * scaleFactor,+ y: (newY + displayOriginY) * scaleFactor,width: newWidth * scaleFactor,height: newHeight * scaleFactor,});diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.tsindex 52627a33e..58b432b2b 100644--- a/apps/desktop/src/utils/tauri.ts+++ b/apps/desktop/src/utils/tauri.ts@@ -295,8 +295,8 @@ async deleteWhisperModel(modelPath: string) : Promise<null> {async exportCaptionsSrt(videoId: string) : Promise<string | null> {return await TAURI_INVOKE("export_captions_srt", { videoId });},-async openTargetSelectOverlays(focusedTarget: ScreenCaptureTarget | null) : Promise<null> {- return await TAURI_INVOKE("open_target_select_overlays", { focusedTarget });+async openTargetSelectOverlays(focusedTarget: ScreenCaptureTarget | null, specificDisplayId: string | null) : Promise<null> {+ return await TAURI_INVOKE("open_target_select_overlays", { focusedTarget, specificDisplayId });},async closeTargetSelectOverlays() : Promise<null> {return await TAURI_INVOKE("close_target_select_overlays");@@ -352,6 +352,7 @@ renderFrameEvent: RenderFrameEvent,requestOpenRecordingPicker: RequestOpenRecordingPicker,requestOpenSettings: RequestOpenSettings,requestScreenCapturePrewarm: RequestScreenCapturePrewarm,+requestSetTargetMode: RequestSetTargetMode,requestStartRecording: RequestStartRecording,setCaptureAreaPending: SetCaptureAreaPending,targetUnderCursor: TargetUnderCursor,@@ -376,6 +377,7 @@ renderFrameEvent: "render-frame-event",requestOpenRecordingPicker: "request-open-recording-picker",requestOpenSettings: "request-open-settings",requestScreenCapturePrewarm: "request-screen-capture-prewarm",+requestSetTargetMode: "request-set-target-mode",requestStartRecording: "request-start-recording",setCaptureAreaPending: "set-capture-area-pending",targetUnderCursor: "target-under-cursor",@@ -436,7 +438,7 @@ export type Cursors = { [key in string]: string } | { [key in string]: CursorMetexport type DeviceOrModelID = { DeviceID: string } | { ModelID: ModelIDType }export type DevicesUpdated = { cameras: CameraInfo[]; microphones: string[]; permissions: OSPermissionsCheck }export type DisplayId = string-export type DisplayInformation = { name: string | null; physical_size: PhysicalSize | null; logical_size: LogicalSize | null; refresh_rate: string }+export type DisplayInformation = { name: string | null; physical_size: PhysicalSize | null; logical_size: LogicalSize | null; logical_bounds: LogicalBounds | null; refresh_rate: string }export type DownloadProgress = { progress: number; message: string }export type EditorPreviewQuality = "quarter" | "half" | "full"export type EditorStateChanged = { playhead_position: number }@@ -519,6 +521,7 @@ export type RenderFrameEvent = { frame_number: number; fps: number; resolution_bexport type RequestOpenRecordingPicker = { target_mode: RecordingTargetMode | null }export type RequestOpenSettings = { page: string }export type RequestScreenCapturePrewarm = { force?: boolean }+export type RequestSetTargetMode = { target_mode: RecordingTargetMode | null; display_id: string | null }export type RequestStartRecording = { mode: RecordingMode }export type S3UploadMeta = { id: string }export type SceneMode = "default" | "cameraOnly" | "hideCamera"diff --git a/crates/recording/src/sources/screen_capture/windows.rs b/crates/recording/src/sources/screen_capture/windows.rsindex d79ea442a..b28e3d90a 100644--- a/crates/recording/src/sources/screen_capture/windows.rs+++ b/crates/recording/src/sources/screen_capture/windows.rs@@ -74,11 +74,16 @@ impl ScreenCaptureConfig<Direct3DCapture> {let position = b.position();let size = b.size().map(|v| (v / 2.0).floor() * 2.0);+ let left = position.x().max(0.0) as u32;+ let top = position.y().max(0.0) as u32;+ let right = (position.x() + size.width()).max(0.0) as u32;+ let bottom = (position.y() + size.height()).max(0.0) as u32;+D3D11_BOX {- left: position.x() as u32,- top: position.y() as u32,- right: (position.x() + size.width()) as u32,- bottom: (position.y() + size.height()) as u32,+ left,+ top,+ right: right.max(left),+ bottom: bottom.max(top),front: 0,back: 1,}