Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(recording): share floating window eligibility with the desktop picker

Baytowneae615bb48659
diff --git a/apps/desktop-gpui/src/devices.rs b/apps/desktop-gpui/src/devices.rs
index efd6bf950..9d0db6a43 100644
--- a/apps/desktop-gpui/src/devices.rs
+++ b/apps/desktop-gpui/src/devices.rs
@@ -712,16 +712,6 @@ pub fn list_display_targets() -> Vec<(DisplayOption, Display)> {
.collect()
}
-/// Mirrors the picker path of `cap_recording::sources::screen_capture::list_windows`
-/// (i.e. `include_accessory_panels: false`), which collapses to: a non-empty
-/// title, not owned by the Window Server, and at window level 0.
-///
-/// The level check is what actually matters. A raw `Window::list()` on macOS is
-/// dominated by menu-bar extras and status items — Control Centre alone
-/// contributes a dozen `Item-0` windows at level 25 — so without it the picker
-/// is unusable. This is deliberately duplicated rather than imported:
-/// `cap-recording` drags in ffmpeg and the whole encode stack, which this app
-/// has no other reason to build.
pub fn list_windows() -> Vec<WindowOption> {
list_window_targets()
.into_iter()
@@ -754,21 +744,27 @@ pub fn list_window_targets() -> Vec<(WindowOption, Window)> {
// (`app_windows::begin_recording`), so offering one as a target
// records a hole. Matched by owner pid rather than title or
// bundle id -- the dev binary is unbundled, and most of our
- // windows carry no CG title at all. (The shared
- // `screen_capture::list_windows` has no such filter; the Tauri
- // main window only escapes it by being a level>0 panel.)
+ // windows carry no CG title at all.
#[cfg(target_os = "macos")]
if window.raw_handle().owner_pid() == Some(std::process::id() as i32) {
return None;
}
- // Normal and floating ("Stay on Top") app windows only; menu bar
- // extras and other system levels are not recordable targets.
#[cfg(target_os = "macos")]
- if !cap_recording::sources::screen_capture::is_pickable_macos_window_level(
- window.raw_handle().level(),
- ) {
- return None;
+ {
+ let level = window.raw_handle().level();
+ let bundle_identifier = window.raw_handle().bundle_identifier();
+ let is_accessory_application = matches!(level, Some(level) if level > 0)
+ && window.raw_handle().is_accessory_application();
+ if !cap_recording::sources::screen_capture::is_listable_macos_window(
+ level,
+ &app,
+ bundle_identifier.as_deref(),
+ false,
+ is_accessory_application,
+ ) {
+ return None;
+ }
}
Some((
diff --git a/crates/recording/src/sources/screen_capture/mod.rs b/crates/recording/src/sources/screen_capture/mod.rs
index a790446da..c2f4a3157 100644
--- a/crates/recording/src/sources/screen_capture/mod.rs
+++ b/crates/recording/src/sources/screen_capture/mod.rs
@@ -616,21 +616,12 @@ pub fn list_displays() -> Vec<(CaptureDisplay, Display)> {
.collect()
}
-/// `kCGWindowLevelForKey(kCGFloatingWindowLevelKey)`: the level a regular app
-/// window moves to when it is raised with "Stay on Top" (NSFloatingWindowLevel).
+// NSFloatingWindowLevel is 3; Stay On Top moves Simulator windows to this level.
#[cfg(target_os = "macos")]
-pub const MACOS_FLOATING_WINDOW_LEVEL: i32 = 3;
+const MACOS_FLOATING_WINDOW_LEVEL: i32 = 3;
-/// Whether a window at `level` is a regular, pickable app window on macOS:
-/// the normal level or a floating ("Stay on Top") one. Menu bar extras,
-/// overlays and other system levels sit above that.
#[cfg(target_os = "macos")]
-pub fn is_pickable_macos_window_level(level: Option<i32>) -> bool {
- matches!(level, Some(level) if (0..=MACOS_FLOATING_WINDOW_LEVEL).contains(&level))
-}
-
-#[cfg(target_os = "macos")]
-fn is_listable_macos_window(
+pub fn is_listable_macos_window(
level: Option<i32>,
owner_name: &str,
bundle_identifier: Option<&str>,
@@ -655,7 +646,7 @@ fn is_listable_macos_window(
&& is_third_party_bundle;
}
- is_pickable_macos_window_level(level)
+ level == Some(MACOS_FLOATING_WINDOW_LEVEL)
&& bundle_identifier.is_some_and(|identifier| !identifier.starts_with("so.cap.desktop"))
}
@@ -899,17 +890,72 @@ mod tests {
#[test]
#[cfg(target_os = "macos")]
- fn macos_pickable_levels_are_normal_and_floating_only() {
- assert!(is_pickable_macos_window_level(Some(0)));
- assert!(is_pickable_macos_window_level(Some(
- MACOS_FLOATING_WINDOW_LEVEL
- )));
- assert!(!is_pickable_macos_window_level(Some(
- MACOS_FLOATING_WINDOW_LEVEL + 1
- )));
- assert!(!is_pickable_macos_window_level(Some(-1)));
- assert!(!is_pickable_macos_window_level(Some(25)));
- assert!(!is_pickable_macos_window_level(None));
+ fn macos_window_filter_preserves_normal_windows_and_rejects_other_levels() {
+ for accessory in [false, true] {
+ assert!(is_listable_macos_window(
+ Some(0),
+ "Example",
+ None,
+ false,
+ accessory
+ ));
+ }
+ for level in [None, Some(-1), Some(1), Some(2), Some(4), Some(25)] {
+ for include_accessory_panels in [false, true] {
+ assert!(!is_listable_macos_window(
+ level,
+ "Example",
+ Some("com.example.app"),
+ include_accessory_panels,
+ false,
+ ));
+ }
+ }
+ }
+
+ #[test]
+ #[cfg(target_os = "macos")]
+ fn macos_window_filter_preserves_accessory_panel_exclusions() {
+ for level in [Some(3), Some(25)] {
+ for bundle in [
+ None,
+ Some("com.apple.controlcenter"),
+ Some("so.cap.desktop.dev"),
+ ] {
+ for include_accessory_panels in [false, true] {
+ assert!(!is_listable_macos_window(
+ level,
+ "Panel",
+ bundle,
+ include_accessory_panels,
+ true,
+ ));
+ }
+ }
+ assert!(!is_listable_macos_window(
+ level,
+ "Panel",
+ Some("com.example.app"),
+ false,
+ true,
+ ));
+ assert!(is_listable_macos_window(
+ level,
+ "Panel",
+ Some("com.example.app"),
+ true,
+ true,
+ ));
+ }
+ for level in [Some(0), Some(3)] {
+ assert!(!is_listable_macos_window(
+ level,
+ "Window Server",
+ Some("com.example.app"),
+ false,
+ false,
+ ));
+ }
}
#[test]