Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
feat(recording): list excludable accessory panel windows on macOS
Richie McIlroy21d92e79a317
diff --git a/crates/recording/src/sources/screen_capture/mod.rs b/crates/recording/src/sources/screen_capture/mod.rsindex 9250eeb91..089830225 100644--- a/crates/recording/src/sources/screen_capture/mod.rs+++ b/crates/recording/src/sources/screen_capture/mod.rs@@ -614,7 +614,39 @@ pub fn list_displays() -> Vec<(CaptureDisplay, Display)> {.collect()}+#[cfg(target_os = "macos")]+fn is_listable_macos_window(+ level: Option<i32>,+ owner_name: &str,+ bundle_identifier: Option<&str>,+ include_accessory_panels: bool,+ is_accessory_application: bool,+) -> bool {+ if owner_name == "Window Server" {+ return false;+ }++ if level == Some(0) {+ return true;+ }++ matches!(level, Some(level) if level > 0)+ && include_accessory_panels+ && is_accessory_application+ && bundle_identifier.is_some_and(|identifier| {+ !identifier.starts_with("com.apple.") && !identifier.starts_with("so.cap.desktop")+ })+}+pub fn list_windows() -> Vec<(CaptureWindow, Window)> {+ list_windows_inner(false)+}++pub fn list_excludable_windows() -> Vec<(CaptureWindow, Window)> {+ list_windows_inner(true)+}++fn list_windows_inner(_include_accessory_panels: bool) -> Vec<(CaptureWindow, Window)> {scap_targets::Window::list().into_iter().flat_map(|v| {@@ -625,13 +657,26 @@ pub fn list_windows() -> Vec<(CaptureWindow, Window)> {}#[cfg(target_os = "macos")]- {- if v.raw_handle().level() != Some(0)- || v.owner_name().filter(|v| v == "Window Server").is_some()- {+ let (owner_name, bundle_identifier) = {+ let owner_name = v.owner_name()?;+ let level = v.raw_handle().level();+ let bundle_identifier = v.raw_handle().bundle_identifier();+ let is_accessory_application = _include_accessory_panels+ && matches!(level, Some(level) if level > 0)+ && v.raw_handle().is_accessory_application();++ if !is_listable_macos_window(+ level,+ &owner_name,+ bundle_identifier.as_deref(),+ _include_accessory_panels,+ is_accessory_application,+ ) {return None;}- }++ (owner_name, bundle_identifier)+ };#[cfg(windows)]{@@ -640,11 +685,9 @@ pub fn list_windows() -> Vec<(CaptureWindow, Window)> {}}+ #[cfg(not(target_os = "macos"))]let owner_name = v.owner_name()?;- #[cfg(target_os = "macos")]- let bundle_identifier = v.raw_handle().bundle_identifier();-#[cfg(not(target_os = "macos"))]let bundle_identifier = None;@@ -690,6 +733,67 @@ mod tests {assert_eq!(physical.size().height(), 720.0);}+ #[test]+ #[cfg(target_os = "macos")]+ fn macos_window_filter_adds_only_third_party_accessory_panels() {+ assert!(is_listable_macos_window(+ Some(0),+ "Example",+ Some("com.example.app"),+ false,+ false,+ ));+ assert!(!is_listable_macos_window(+ Some(3),+ "FreeCastNotes",+ Some("fi.sherbakov.freecastnotes"),+ false,+ true,+ ));+ assert!(is_listable_macos_window(+ Some(3),+ "FreeCastNotes",+ Some("fi.sherbakov.freecastnotes"),+ true,+ true,+ ));+ assert!(!is_listable_macos_window(+ Some(3),+ "Example",+ Some("com.example.app"),+ true,+ false,+ ));+ assert!(!is_listable_macos_window(+ Some(25),+ "Control Centre",+ Some("com.apple.controlcenter"),+ true,+ true,+ ));+ assert!(!is_listable_macos_window(+ Some(3),+ "Cap",+ Some("so.cap.desktop.dev"),+ true,+ true,+ ));+ assert!(!is_listable_macos_window(+ Some(0),+ "Window Server",+ None,+ true,+ false,+ ));+ assert!(!is_listable_macos_window(+ None,+ "Example",+ Some("com.example.app"),+ true,+ true,+ ));+ }+#[test]fn logical_area_to_physical_bounds_clamps_to_display() {let bounds = LogicalBounds::new(