Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(desktop): correct notch overlay edge cases
Jamie Davenport1887b7d4bc6b
diff --git a/apps/desktop/src-tauri/src/import.rs b/apps/desktop/src-tauri/src/import.rsindex b2baf436a..38c425d8c 100644--- a/apps/desktop/src-tauri/src/import.rs+++ b/apps/desktop/src-tauri/src/import.rs@@ -1021,7 +1021,7 @@ fn copy_source_segment(system_audio,cursor,keyboard,- display_notch: None,+ display_notch: source_segment.display_notch,})}diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rsindex f6f3f9866..6a57a6624 100644--- a/apps/desktop/src-tauri/src/lib.rs+++ b/apps/desktop/src-tauri/src/lib.rs@@ -4796,10 +4796,44 @@ fn configure_camera_blur_recovery(}#[cfg_attr(mobile, tauri::mobile_entry_point)]-/// Extracted so the TypeScript bindings can be regenerated without booting-/// the app, which would otherwise ask for camera and microphone access.-fn create_specta_builder() -> tauri_specta::Builder {- tauri_specta::Builder::new()+pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {+ // Arm the unexpected-termination sentinel before anything else can crash, and+ // report any previous session that died without a clean shutdown.+ let previous_termination = crash_sentinel::init(&logs_dir, env!("CARGO_PKG_VERSION"));+ configure_windows_graphics_recovery(previous_termination);++ // Keep the sentinel's blur marker in sync with live BlurProcessor instances+ // (camera preview and editor render alike), so a native blur crash is+ // attributable on the next launch.+ cap_camera_effects::set_blur_session_observer(|active| {+ if active {+ crash_sentinel::enter_blur_session();+ } else {+ crash_sentinel::exit_blur_session();+ }+ });++ ffmpeg::init()+ .map_err(|e| {+ error!("Failed to initialize ffmpeg: {e}");+ })+ .ok();++ // Detect the camera-preview quality profile once from total RAM. On low-RAM+ // machines (<= 8GB) this opts the preview into a cheaper profile (smaller+ // textures, 30fps, no background blur); higher-spec machines keep the exact+ // current behaviour. Only the preview is affected — recording is untouched.+ {+ let mut system = sysinfo::System::new();+ system.refresh_memory();+ camera::init_preview_profile(system.total_memory());+ }++ telemetry::init();++ let tauri_context = tauri::generate_context!();++ let specta_builder = tauri_specta::Builder::new().commands(tauri_specta::collect_commands![set_mic_input,set_camera_input,@@ -5015,64 +5049,22 @@ fn create_specta_builder() -> tauri_specta::Builder {.typ::<cap_automation::ClipboardSource>().typ::<cap_automation::ExportFormat>().typ::<cap_automation::AutomationExportCompression>()- .typ::<cap_automation::ExportDestination>()-}--#[cfg(debug_assertions)]-fn export_typescript_bindings(builder: &tauri_specta::Builder) {- let bindings_path = std::path::Path::new("../src/utils/tauri.ts");- if !bindings_path.parent().is_some_and(|parent| parent.exists()) {- debug!("Skipping TypeScript bindings export outside source checkout");- return;- }-- if let Err(err) = builder.export(specta_typescript::Typescript::default(), bindings_path) {- warn!(error = %err, "Failed to export TypeScript bindings");- }-}+ .typ::<cap_automation::ExportDestination>();-pub async fn run(recording_logging_handle: LoggingHandle, logs_dir: PathBuf) {- // Arm the unexpected-termination sentinel before anything else can crash, and- // report any previous session that died without a clean shutdown.- let previous_termination = crash_sentinel::init(&logs_dir, env!("CARGO_PKG_VERSION"));- configure_windows_graphics_recovery(previous_termination);-- // Keep the sentinel's blur marker in sync with live BlurProcessor instances- // (camera preview and editor render alike), so a native blur crash is- // attributable on the next launch.- cap_camera_effects::set_blur_session_observer(|active| {- if active {- crash_sentinel::enter_blur_session();+ #[cfg(debug_assertions)]+ {+ let bindings_path = std::path::Path::new("../src/utils/tauri.ts");+ if bindings_path.parent().is_some_and(|parent| parent.exists()) {+ if let Err(err) =+ specta_builder.export(specta_typescript::Typescript::default(), bindings_path)+ {+ warn!(error = %err, "Failed to export TypeScript bindings");+ }} else {- crash_sentinel::exit_blur_session();+ debug!("Skipping TypeScript bindings export outside source checkout");}- });-- ffmpeg::init()- .map_err(|e| {- error!("Failed to initialize ffmpeg: {e}");- })- .ok();-- // Detect the camera-preview quality profile once from total RAM. On low-RAM- // machines (<= 8GB) this opts the preview into a cheaper profile (smaller- // textures, 30fps, no background blur); higher-spec machines keep the exact- // current behaviour. Only the preview is affected — recording is untouched.- {- let mut system = sysinfo::System::new();- system.refresh_memory();- camera::init_preview_profile(system.total_memory());}- telemetry::init();-- let tauri_context = tauri::generate_context!();-- let specta_builder = create_specta_builder();-- #[cfg(debug_assertions)]- export_typescript_bindings(&specta_builder);-let (camera_preview_state_tx, camera_preview_state_rx) =tokio::sync::watch::channel(CameraPreviewState::default());let (camera_tx, camera_ws_port, _shutdown) =@@ -6847,14 +6839,3 @@ mod screenshot_share_cache_tests {assert!(link.is_none());}}--#[cfg(all(test, debug_assertions))]-mod bindings_tests {- /// Regenerates `apps/desktop/src/utils/tauri.ts`, which is committed and- /// which CI typechecks against. Running the app in debug does the same, but- /// that needs camera and microphone access; this does not.- #[test]- fn export_typescript_bindings() {- super::export_typescript_bindings(&super::create_specta_builder());- }-}diff --git a/apps/desktop/src-tauri/src/recording.rs b/apps/desktop/src-tauri/src/recording.rsindex bc32fdd28..a12f05431 100644--- a/apps/desktop/src-tauri/src/recording.rs+++ b/apps/desktop/src-tauri/src/recording.rs@@ -3853,13 +3853,11 @@ fn project_config_from_recording(Vec::new()};- // Screen captures only; the editor's toggle is there for anyone who wants a- // notch over a window recording anyway.- let captured_screen = matches!(+ if should_enable_notch_overlay(capture_target,- Some(ScreenCaptureTarget::Display { .. } | ScreenCaptureTarget::Area { .. })- );- if captured_screen && settings.macbook_notch_overlay.unwrap_or(false) {+ settings.macbook_notch_overlay.unwrap_or(false),+ completed_recording.meta.display_notch().is_some(),+ ) {config.background.notch = Some(cap_project::NotchConfiguration {enabled: true,..Default::default()@@ -3881,6 +3879,19 @@ fn project_config_from_recording(config}+fn should_enable_notch_overlay(+ capture_target: Option<&ScreenCaptureTarget>,+ setting_enabled: bool,+ has_recorded_notch: bool,+) -> bool {+ setting_enabled+ && has_recorded_notch+ && matches!(+ capture_target,+ Some(ScreenCaptureTarget::Display { .. } | ScreenCaptureTarget::Area { .. })+ )+}+fn apply_recording_presentation_defaults(app: &AppHandle,config: &mut ProjectConfiguration,@@ -4337,6 +4348,31 @@ mod tests {));}+ #[test]+ fn notch_overlay_requires_recorded_geometry_on_screen_target() {+ let display = ScreenCaptureTarget::Display {+ id: "1".parse().unwrap(),+ };+ let area = ScreenCaptureTarget::Area {+ screen: "1".parse().unwrap(),+ bounds: scap_targets::bounds::LogicalBounds::new(+ scap_targets::bounds::LogicalPosition::new(0.0, 0.0),+ scap_targets::bounds::LogicalSize::new(100.0, 100.0),+ ),+ };++ assert!(should_enable_notch_overlay(Some(&display), true, true));+ assert!(should_enable_notch_overlay(Some(&area), true, true));+ assert!(!should_enable_notch_overlay(Some(&display), true, false));+ assert!(!should_enable_notch_overlay(Some(&area), true, false));+ assert!(!should_enable_notch_overlay(Some(&display), false, true));+ assert!(!should_enable_notch_overlay(+ Some(&ScreenCaptureTarget::CameraOnly),+ true,+ true+ ));+ }+#[test]fn skips_screen_presentation_defaults_for_camera_only_recordings() {let mut config = ProjectConfiguration::default();diff --git a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx b/apps/desktop/src/routes/(window-chrome)/settings/general.tsxindex 50eeaf7f0..46e7b2052 100644--- a/apps/desktop/src/routes/(window-chrome)/settings/general.tsx+++ b/apps/desktop/src/routes/(window-chrome)/settings/general.tsx@@ -670,7 +670,7 @@ function Inner(props: {/><ToggleSettingItemlabel="Draw the MacBook notch on screen recordings"- description="Screen capture records straight through the notch, so recordings show an unbroken menu bar. This draws it back on by default for new screen and area recordings; window recordings are left alone. Each recording can override it in the editor."+ description="Automatically restores the notch for new screen and area recordings when the selected region contains the complete notch. External displays, partial areas, and window recordings are left alone. Each recording can override it in the editor."value={!!settings.macbookNotchOverlay}onChange={(value) => handleChange("macbookNotchOverlay", value)}/>diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsxindex cbad8d11d..fce6f7a95 100644--- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx+++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx@@ -1652,6 +1652,11 @@ function BackgroundConfig(props: {}) {const { project, setProject, editorInstance, projectHistory } =useEditorContext();+ const notchXMax = () => {+ const width =+ project.background.notch?.width ?? editorInstance.notchBase.width;+ return 1 - Math.min(Math.max(width, 0), 1);+ };const isNoneBackground = () =>project.background.padding === 0 && project.background.rounding === 0;const initialCurrentDesktopBackgroundPath = () => {@@ -2727,8 +2732,14 @@ function BackgroundConfig(props: {><Slidervalue={[- project.background.notch?.[field.key] ??- editorInstance.notchBase[field.key],+ field.key === "x"+ ? Math.min(+ project.background.notch?.x ??+ editorInstance.notchBase.x,+ notchXMax(),+ )+ : (project.background.notch?.[field.key] ??+ editorInstance.notchBase[field.key]),]}onChange={(v) => {const base = editorInstance.notchBase;@@ -2737,7 +2748,11 @@ function BackgroundConfig(props: {...prev,enabled: true,};- next[field.key] = v[0];+ if (field.key === "x") {+ next.x = Math.min(v[0], notchXMax());+ } else {+ next[field.key] = v[0];+ }if (field.key === "width") {// Resize about the centre rather than dragging the@@ -2753,7 +2768,7 @@ function BackgroundConfig(props: {setProject("background", "notch", next);}}minValue={0}- maxValue={field.max}+ maxValue={field.key === "x" ? notchXMax() : field.max}step={0.001}formatTooltip={(value) => `${(value * 100).toFixed(1)}%`}/>diff --git a/crates/recording/src/capture_pipeline.rs b/crates/recording/src/capture_pipeline.rsindex 09bec811a..9355b084f 100644--- a/crates/recording/src/capture_pipeline.rs+++ b/crates/recording/src/capture_pipeline.rs@@ -551,6 +551,8 @@ pub fn target_to_display_and_crop(////// Window captures get `None`: they record the window's own surface rather than/// a screen region, and the window moves, so there is no stable position.+/// Area captures also return `None` when they contain only part of the notch,+/// because `DisplayNotch` cannot encode a cropped source shape.pub fn resolve_display_notch(target: &ScreenCaptureTarget) -> Option<cap_project::DisplayNotch> {let display = target.display()?;let notch = display.notch()?;@@ -561,38 +563,95 @@ pub fn resolve_display_notch(target: &ScreenCaptureTarget) -> Option<cap_projectwidth: notch.width,height: notch.height,}),- // Cropped at capture time, so the notch is rebased onto the crop and- // dropped when it falls outside.ScreenCaptureTarget::Area { bounds, .. } => {let display_size = display.logical_size()?;- let notch_left = notch.x * display_size.width();- let notch_right = notch_left + notch.width * display_size.width();- let notch_bottom = notch.height * display_size.height();+ resolve_area_display_notch(notch, display_size, *bounds)+ }+ ScreenCaptureTarget::Window { .. } | ScreenCaptureTarget::CameraOnly => None,+ }+}- let area_left = bounds.position().x();- let area_top = bounds.position().y();- let area_width = bounds.size().width();- let area_height = bounds.size().height();+fn resolve_area_display_notch(+ notch: scap_targets::NotchGeometry,+ display_size: scap_targets::bounds::LogicalSize,+ bounds: scap_targets::bounds::LogicalBounds,+) -> Option<cap_project::DisplayNotch> {+ let area_left = bounds.position().x();+ let area_top = bounds.position().y();+ let area_width = bounds.size().width();+ let area_height = bounds.size().height();+ if area_width <= 0.0 || area_height <= 0.0 || area_top != 0.0 {+ return None;+ }- if area_width <= 0.0 || area_height <= 0.0 {- return None;- }+ let notch_left = notch.x * display_size.width();+ let notch_width = notch.width * display_size.width();+ let notch_right = notch_left + notch_width;+ let notch_height = notch.height * display_size.height();+ let area_right = area_left + area_width;+ let area_bottom = area_height;+ if area_left > notch_left || area_right < notch_right || area_bottom < notch_height {+ return None;+ }- let left = notch_left.max(area_left);- let right = notch_right.min(area_left + area_width);- let bottom = notch_bottom.min(area_top + area_height);+ Some(cap_project::DisplayNotch {+ x: (notch_left - area_left) / area_width,+ width: notch_width / area_width,+ height: notch_height / area_height,+ })+}- if right <= left || bottom <= area_top {- return None;- }+#[cfg(test)]+mod display_notch_tests {+ use super::*;+ use scap_targets::bounds::{LogicalBounds, LogicalPosition, LogicalSize};++ const NOTCH: scap_targets::NotchGeometry = scap_targets::NotchGeometry {+ x: 0.4,+ width: 0.2,+ height: 0.1,+ };++ fn display_size() -> LogicalSize {+ LogicalSize::new(1_000.0, 800.0)+ }+ #[test]+ fn area_containing_the_full_notch_rebases_it() {+ let bounds = LogicalBounds::new(+ LogicalPosition::new(300.0, 0.0),+ LogicalSize::new(400.0, 200.0),+ );++ assert_eq!(+ resolve_area_display_notch(NOTCH, display_size(), bounds),Some(cap_project::DisplayNotch {- x: (left - area_left) / area_width,- width: (right - left) / area_width,- height: (bottom - area_top) / area_height,+ x: 0.25,+ width: 0.5,+ height: 0.4,})- }- ScreenCaptureTarget::Window { .. } | ScreenCaptureTarget::CameraOnly => None,+ );+ }++ #[test]+ fn partially_intersected_notches_are_omitted() {+ let horizontal = LogicalBounds::new(+ LogicalPosition::new(500.0, 0.0),+ LogicalSize::new(200.0, 200.0),+ );+ let vertical = LogicalBounds::new(+ LogicalPosition::new(300.0, 40.0),+ LogicalSize::new(400.0, 200.0),+ );++ assert_eq!(+ resolve_area_display_notch(NOTCH, display_size(), horizontal),+ None+ );+ assert_eq!(+ resolve_area_display_notch(NOTCH, display_size(), vertical),+ None+ );}}diff --git a/crates/rendering/src/layers/notch.rs b/crates/rendering/src/layers/notch.rsindex 4d90a6ca3..2c7a1915d 100644--- a/crates/rendering/src/layers/notch.rs+++ b/crates/rendering/src/layers/notch.rs@@ -11,6 +11,7 @@ pub struct NotchUniforms {/// Unzoomed notch size in output px. Zoom scales the texture rather than/// re-rasterizing it, so an animating zoom doesn't thrash the cache.pub raster_size: [f64; 2],+ pub source_crop: [f32; 4],}/// Redraws the recording device's physical notch over the screen capture.@@ -127,7 +128,12 @@ impl NotchLayer {let mut composite = notch.composite;composite.frame_size = [tex_w as f32, tex_h as f32];- composite.crop_bounds = [0.0, 0.0, tex_w as f32, tex_h as f32];+ composite.crop_bounds = [+ notch.source_crop[0] * tex_w as f32,+ notch.source_crop[1] * tex_h as f32,+ notch.source_crop[2] * tex_w as f32,+ notch.source_crop[3] * tex_h as f32,+ ];composite.write_to_buffer(queue, &self.uniforms_buffer);self.ready = true;}@@ -188,16 +194,17 @@ mod tests {(BOUNDS[2] - BOUNDS[0]) as f64,(BOUNDS[3] - BOUNDS[1]) as f64,],+ source_crop: [0.0, 0.0, 1.0, 1.0],}}/// Renders the notch over a white frame and returns the RGBA pixels.- fn render() -> Option<Vec<u8>> {+ fn render_with_uniforms(uniforms: NotchUniforms) -> Option<Vec<u8>> {let (device, queue) = device()?;let mut layer =NotchLayer::new(&device, Arc::new(CompositeVideoFramePipeline::new(&device)));- layer.prepare(&device, &queue, Some(uniforms()));+ layer.prepare(&device, &queue, Some(uniforms));assert!(layer.has_content());let target = device.create_texture(&wgpu::TextureDescriptor {@@ -273,6 +280,10 @@ mod tests {Some(pixels)}+ fn render() -> Option<Vec<u8>> {+ render_with_uniforms(uniforms())+ }+fn pixel(pixels: &[u8], x: u32, y: u32) -> [u8; 4] {let i = ((y * OUTPUT + x) * 4) as usize;[pixels[i], pixels[i + 1], pixels[i + 2], pixels[i + 3]]@@ -335,6 +346,34 @@ mod tests {);}+ #[test]+ fn source_crop_preserves_the_uncropped_shape() {+ let Some(full) = render() else {+ return;+ };+ let mut cropped_uniforms = uniforms();+ cropped_uniforms.source_crop = [0.5, 0.0, 1.0, 1.0];+ cropped_uniforms.composite.target_bounds = [128.0, 0.0, 192.0, 48.0];+ cropped_uniforms.composite.target_size = [64.0, 48.0];+ let Some(cropped) = render_with_uniforms(cropped_uniforms) else {+ return;+ };++ for y in 1..47 {+ for x in 129..191 {+ let cropped_pixel = pixel(&cropped, x, y);+ let full_pixel = pixel(&full, x, y);+ assert!(+ cropped_pixel+ .iter()+ .zip(full_pixel)+ .all(|(cropped, full)| cropped.abs_diff(full) <= 32),+ "{x},{y}: {cropped_pixel:?} != {full_pixel:?}"+ );+ }+ }+ }+#[test]fn draws_nothing_when_there_is_no_notch() {let Some((device, queue)) = device() else {diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rsindex feb92c7fb..eb41f1116 100644--- a/crates/rendering/src/lib.rs+++ b/crates/rendering/src/lib.rs@@ -2546,8 +2546,16 @@ const FLOATING_ROUNDING_FRAC: f32 = 0.028;const SCREEN_MAX_PADDING: f64 = 0.4;-/// Places a notch on the output frame, returning its bounds and size in output-/// px, or `None` when the crop leaves nothing of it to draw.+#[derive(Clone, Copy, Debug, PartialEq)]+struct NotchPlacement {+ bounds: [f32; 4],+ size: [f32; 2],+ full_size: [f32; 2],+ source_crop: [f32; 4],+}++/// Places the visible part of a notch on the output frame while retaining the+/// source crop and full raster size, or returns `None` when nothing remains.////// The notch is part of the screen rather than decoration around it, so it goes/// through the same RawDisplaySpace -> zoomed frame space chain the cursor@@ -2558,16 +2566,23 @@ fn notch_bounds(project: &ProjectConfiguration,resolution_base: XY<u32>,zoom: &InterpolatedZoom,-) -> Option<([f32; 4], [f32; 2])> {+) -> Option<NotchPlacement> {let screen = options.screen_size.map(|v| v as f64);let crop = ProjectUniforms::get_crop(options, project);let crop_start = crop.position.map(|v| v as f64);let crop_end = crop_start + crop.size.map(|v| v as f64);- let left = (notch.x * screen.x).max(crop_start.x);- let right = ((notch.x + notch.width) * screen.x).min(crop_end.x);- let top = crop_start.y.max(0.0);- let bottom = (notch.height * screen.y).min(crop_end.y);+ let notch_start = XY::new(notch.x * screen.x, 0.0);+ let notch_end = XY::new((notch.x + notch.width) * screen.x, notch.height * screen.y);+ let notch_size = notch_end - notch_start;+ if notch_size.x <= 0.0 || notch_size.y <= 0.0 {+ return None;+ }++ let left = notch_start.x.max(crop_start.x);+ let right = notch_end.x.min(crop_end.x);+ let top = notch_start.y.max(crop_start.y);+ let bottom = notch_end.y.min(crop_end.y);if right <= left || bottom <= top {return None;@@ -2583,15 +2598,28 @@ fn notch_bounds(let start = to_output(XY::new(left, top));let end = to_output(XY::new(right, bottom));+ let full_start = to_output(notch_start);+ let full_end = to_output(notch_end);let size = [(end.x - start.x) as f32, (end.y - start.y) as f32];- if size[0] <= 0.0 || size[1] <= 0.0 {+ let full_size = [+ (full_end.x - full_start.x) as f32,+ (full_end.y - full_start.y) as f32,+ ];+ if size[0] <= 0.0 || size[1] <= 0.0 || full_size[0] <= 0.0 || full_size[1] <= 0.0 {return None;}- Some((- [start.x as f32, start.y as f32, end.x as f32, end.y as f32],+ Some(NotchPlacement {+ bounds: [start.x as f32, start.y as f32, end.x as f32, end.y as f32],size,- ))+ full_size,+ source_crop: [+ ((left - notch_start.x) / notch_size.x).clamp(0.0, 1.0) as f32,+ ((top - notch_start.y) / notch_size.y).clamp(0.0, 1.0) as f32,+ ((right - notch_start.x) / notch_size.x).clamp(0.0, 1.0) as f32,+ ((bottom - notch_start.y) / notch_size.y).clamp(0.0, 1.0) as f32,+ ],+ })}const MOTION_BLUR_BASELINE_FPS: f32 = 60.0;@@ -3650,11 +3678,10 @@ impl ProjectUniforms {.notch.and_then(|config| config.resolve(constants.meta.display_notch())).and_then(|notch| {- let (bounds, size) =- notch_bounds(notch, options, project, resolution_base, &zoom)?;+ let placement = notch_bounds(notch, options, project, resolution_base, &zoom)?;// Rasterize at the unzoomed size and let zoom scale the// texture, so an animating zoom reuses one rasterization.- let (_, unzoomed) = notch_bounds(+ let unzoomed = notch_bounds(notch,options,project,@@ -3668,8 +3695,8 @@ impl ProjectUniforms {Some(NotchUniforms {composite: CompositeVideoFrameUniforms {output_size: [output_size.x as f32, output_size.y as f32],- target_bounds: bounds,- target_size: size,+ target_bounds: placement.bounds,+ target_size: placement.size,// The outline is baked into the texture's alpha, so// the SDF has to leave the edges alone.preserve_source_alpha: 1.0,@@ -3694,7 +3721,8 @@ impl ProjectUniforms {frame_size: [1.0, 1.0],crop_bounds: [0.0, 0.0, 1.0, 1.0],},- raster_size: [unzoomed[0] as f64, unzoomed[1] as f64],+ raster_size: [unzoomed.full_size[0] as f64, unzoomed.full_size[1] as f64],+ source_crop: placement.source_crop,})});@@ -5970,10 +5998,7 @@ mod notch_bounds_tests {}}- fn place(- project: &ProjectConfiguration,- zoom: &InterpolatedZoom,- ) -> Option<([f32; 4], [f32; 2])> {+ fn place(project: &ProjectConfiguration, zoom: &InterpolatedZoom) -> Option<NotchPlacement> {notch_bounds(NOTCH, &options(), project, SCREEN, zoom)}@@ -5987,27 +6012,28 @@ mod notch_bounds_tests {#[test]fn sits_flush_against_the_top_of_the_screen() {let project = ProjectConfiguration::default();- let (bounds, size) = place(&project, &no_zoom()).unwrap();+ let placement = place(&project, &no_zoom()).unwrap();let display_offset = ProjectUniforms::display_offset(&options(), &project, SCREEN);assert!(- (bounds[1] as f64 - display_offset.coord.y).abs() < 1e-3,+ (placement.bounds[1] as f64 - display_offset.coord.y).abs() < 1e-3,"notch top {} should meet the display top {}",- bounds[1],+ placement.bounds[1],display_offset.coord.y);- assert!(size[0] > 0.0 && size[1] > 0.0);+ assert!(placement.size[0] > 0.0 && placement.size[1] > 0.0);+ assert_eq!(placement.source_crop, [0.0, 0.0, 1.0, 1.0]);}#[test]fn is_horizontally_centred_on_the_display() {let project = ProjectConfiguration::default();- let (bounds, _) = place(&project, &no_zoom()).unwrap();+ let placement = place(&project, &no_zoom()).unwrap();let display_offset = ProjectUniforms::display_offset(&options(), &project, SCREEN);let display_size = ProjectUniforms::display_size(&options(), &project, SCREEN);- let notch_centre = (bounds[0] + bounds[2]) as f64 / 2.0;+ let notch_centre = (placement.bounds[0] + placement.bounds[2]) as f64 / 2.0;let display_centre = display_offset.coord.x + display_size.coord.x / 2.0;// The measured notch is half a point off-centre on a 1512pt panel.@@ -6020,11 +6046,11 @@ mod notch_bounds_tests {#[test]fn keeps_its_proportions_relative_to_the_display() {let project = ProjectConfiguration::default();- let (_, size) = place(&project, &no_zoom()).unwrap();+ let placement = place(&project, &no_zoom()).unwrap();let display_size = ProjectUniforms::display_size(&options(), &project, SCREEN);- let width_frac = size[0] as f64 / display_size.coord.x;- let height_frac = size[1] as f64 / display_size.coord.y;+ let width_frac = placement.size[0] as f64 / display_size.coord.x;+ let height_frac = placement.size[1] as f64 / display_size.coord.y;assert!((width_frac - NOTCH.width).abs() < 1e-3, "{width_frac}");assert!((height_frac - NOTCH.height).abs() < 1e-3, "{height_frac}");@@ -6033,22 +6059,22 @@ mod notch_bounds_tests {#[test]fn scales_and_translates_with_zoom() {let project = ProjectConfiguration::default();- let (unzoomed, unzoomed_size) = place(&project, &no_zoom()).unwrap();+ let unzoomed = place(&project, &no_zoom()).unwrap();let zoom = InterpolatedZoom {t: 1.0,bounds: SegmentBounds::from_amount_center(2.0, ProjectXY::new(0.5, 0.5)),};- let (zoomed, zoomed_size) = place(&project, &zoom).unwrap();+ let zoomed = place(&project, &zoom).unwrap();assert!(- zoomed_size[0] > unzoomed_size[0] * 1.9,+ zoomed.size[0] > unzoomed.size[0] * 1.9,"2x zoom should roughly double the notch width: {} -> {}",- unzoomed_size[0],- zoomed_size[0]+ unzoomed.size[0],+ zoomed.size[0]);assert!(- zoomed[1] < unzoomed[1],+ zoomed.bounds[1] < unzoomed.bounds[1],"zooming into the centre should push the top edge off-frame");}@@ -6061,12 +6087,13 @@ mod notch_bounds_tests {bounds: SegmentBounds::from_amount_center(3.0, ProjectXY::new(1.0, 1.0)),};- let (bounds, _) = place(&project, &zoom).unwrap();+ let placement = place(&project, &zoom).unwrap();let output = ProjectUniforms::get_output_size(&options(), &project, SCREEN);assert!(- bounds[3] < 0.0 || bounds[0] > output.0 as f32,- "notch should leave the frame entirely, got {bounds:?}"+ placement.bounds[3] < 0.0 || placement.bounds[0] > output.0 as f32,+ "notch should leave the frame entirely, got {:?}",+ placement.bounds);}@@ -6089,20 +6116,39 @@ mod notch_bounds_tests {size: ProjectXY::new(SCREEN.x, SCREEN.y / 2),});- let (_, size) = place(&project, &no_zoom()).expect("notch is still visible");- assert!(size[0] > 0.0 && size[1] > 0.0);+ let placement = place(&project, &no_zoom()).expect("notch is still visible");+ assert!(placement.size[0] > 0.0 && placement.size[1] > 0.0);+ }++ #[test]+ fn partial_crop_preserves_source_coordinates() {+ let notch_mid_x = ((NOTCH.x + NOTCH.width / 2.0) * SCREEN.x as f64).round() as u32;+ let notch_mid_y = (NOTCH.height * SCREEN.y as f64 / 2.0).round() as u32;+ let mut project = ProjectConfiguration::default();+ project.background.crop = Some(Crop {+ position: ProjectXY::new(notch_mid_x, notch_mid_y),+ size: ProjectXY::new(SCREEN.x - notch_mid_x, SCREEN.y - notch_mid_y),+ });++ let placement = place(&project, &no_zoom()).unwrap();++ assert!((placement.source_crop[0] - 0.5).abs() < 0.01);+ assert!((placement.source_crop[1] - 0.5).abs() < 0.01);+ assert_eq!(placement.source_crop[2..], [1.0, 1.0]);+ assert!((placement.size[0] / placement.full_size[0] - 0.5).abs() < 0.01);+ assert!((placement.size[1] / placement.full_size[1] - 0.5).abs() < 0.01);}#[test]fn padding_shrinks_the_notch_with_the_display() {let mut project = ProjectConfiguration::default();- let (_, unpadded) = place(&project, &no_zoom()).unwrap();+ let unpadded = place(&project, &no_zoom()).unwrap();project.background.padding = 40.0;- let (_, padded) = place(&project, &no_zoom()).unwrap();+ let padded = place(&project, &no_zoom()).unwrap();assert!(- padded[0] < unpadded[0],+ padded.size[0] < unpadded.size[0],"padded notch {padded:?} should be narrower than {unpadded:?}");}