Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(desktop-gpui): keep the camera bubble above the picker overlays
Richie McIlroy80d526615b67
diff --git a/apps/desktop-gpui/src/app_windows.rs b/apps/desktop-gpui/src/app_windows.rsindex 93b540b0b..e6a00c55a 100644--- a/apps/desktop-gpui/src/app_windows.rs+++ b/apps/desktop-gpui/src/app_windows.rs@@ -2606,11 +2606,7 @@ fn open_overlay(window.refresh();}).ok();- if let Some(camera) = cx.update(visible_camera_frame)- && let Err(error) = camera.raise()- {- tracing::warn!(%error, "could not raise the camera above the target picker");- }+ cx.update(raise_camera_above_overlays);}).detach();}@@ -4335,15 +4331,27 @@ pub(crate) fn studio_camera_snapshot(.ok()}-fn visible_camera_frame(cx: &mut App) -> Option<CameraFrame> {+/// Keep the camera bubble above the picker overlays. Not filtered on+/// `window_is_visible` off macOS: Windows' camera is shown asynchronously and+/// X11 has no visibility probe, and neither raise path shows a hidden window.+pub(crate) fn raise_camera_above_overlays(cx: &mut App) {if camera_preview_is_inline(cx) {- return None;+ return;}#[cfg(target_os = "linux")]if clean_capture_active(cx) {- return None;+ return;+ }+ let Some(camera) = camera_frame(cx) else {+ return;+ };+ #[cfg(target_os = "macos")]+ if !camera.visible {+ return;+ }+ if let Err(error) = camera.raise() {+ tracing::warn!(%error, "could not raise the camera above the target picker");}- camera_frame(cx).filter(|camera| camera.visible)}fn camera_snapshot(cx: &mut App) -> Option<CameraSnapshot> {@@ -4363,9 +4371,13 @@ impl CameraFrame {fn raise(&self) -> anyhow::Result<()> {match &self.native {#[cfg(target_os = "macos")]- CameraNativeFrame::Mac { native, .. } => platform::order_front_native(native),+ CameraNativeFrame::Mac { native, .. } => {+ platform::raise_panel_native(native, platform::recording_controls_level())+ }#[cfg(target_os = "windows")]- CameraNativeFrame::Windows(native) => platform::order_front_native(native),+ CameraNativeFrame::Windows(native) => {+ platform::raise_panel_native(native, platform::recording_controls_level())+ }#[cfg(target_os = "linux")]CameraNativeFrame::X11 { window_id, .. } => {use x11rb::connection::Connection as _;diff --git a/apps/desktop-gpui/src/platform.rs b/apps/desktop-gpui/src/platform.rsindex 6549f0b52..e57f143a5 100644--- a/apps/desktop-gpui/src/platform.rs+++ b/apps/desktop-gpui/src/platform.rs@@ -1586,8 +1586,8 @@ mod mac {NSRect::new(NSPoint::new(x, appkit_y), NSSize::new(width, height)),true,);- ns_window.setLevel(level);apply_fullscreen_overlay_behavior(ns_window);+ ns_window.setLevel(level);// `.shadow(false)` in the Tauri builder.ns_window.setHasShadow(false);ns_window.setAnimationBehavior(objc2_app_kit::NSWindowAnimationBehavior::None);@@ -1730,6 +1730,15 @@ mod mac {rerun_occlusion_handler_after_show(&native.0);}+ /// Lift a floating panel to the front of its level, first restoring the+ /// level if anything lowered it below `level`.+ pub fn raise_panel_native(native: &NativeWindow, level: isize) {+ if native.0.level() < level {+ native.0.setLevel(level);+ }+ native.0.orderFrontRegardless();+ }+/// The `NSWindow` behind a gpui window.pub fn ns_window(window: &Window) -> Option<Retained<NSWindow>> {// Fully qualified: `Window` also has an inherent `window_handle()`@@ -1753,15 +1762,17 @@ mod mac {tracing::error!("no NSWindow behind gpui window; panel behavior not applied");return;};+ // Before the level: `setFloatingPanel:` resets it to+ // `NSFloatingWindowLevel`.+ if behavior.join_all_spaces {+ apply_fullscreen_overlay_behavior(&ns_window);+ }ns_window.setLevel(behavior.level);tracing::debug!(requested = behavior.level,actual = ns_window.level(),"panel level applied");- if behavior.join_all_spaces {- apply_fullscreen_overlay_behavior(&ns_window);- }ns_window.setHasShadow(behavior.shadow);}@@ -3175,6 +3186,7 @@ mod stub {}pub fn set_window_frame(_native: &NativeWindow, _x: f64, _y: f64, _width: f64, _height: f64) {}pub fn order_front_native(_native: &NativeWindow) {}+ pub fn raise_panel_native(_native: &NativeWindow, _level: isize) {}pub fn frame_is_on_screen(_x: f64, _y: f64, _width: f64, _height: f64) -> bool {true}diff --git a/apps/desktop-gpui/src/platform/windows.rs b/apps/desktop-gpui/src/platform/windows.rsindex a0468465b..5a340c73f 100644--- a/apps/desktop-gpui/src/platform/windows.rs+++ b/apps/desktop-gpui/src/platform/windows.rs@@ -464,6 +464,22 @@ pub fn order_front_native(native: &NativeWindow) {}}+/// Synchronous on purpose: `order_front_native`'s posted `HWND_TOP` lands+/// after an overlay's own activation and loses to it.+pub fn raise_panel_native(native: &NativeWindow, _level: isize) {+ unsafe {+ SetWindowPos(+ native.hwnd(),+ HWND_TOPMOST,+ 0,+ 0,+ 0,+ 0,+ SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE,+ );+ }+}+fn overlap_is_visible(first: Rect, second: Rect) -> bool {const MIN_VISIBLE: f64 = 80.;if !first.is_valid() || !second.is_valid() {diff --git a/apps/desktop-gpui/src/target_overlay.rs b/apps/desktop-gpui/src/target_overlay.rsindex 430a049bf..4afc0e5ce 100644--- a/apps/desktop-gpui/src/target_overlay.rs+++ b/apps/desktop-gpui/src/target_overlay.rs@@ -899,6 +899,14 @@ impl OverlayWindow {let theme = Theme::for_window(window, cx, false);cx.observe_in(&select, window, |_, _, window, cx| repaint(window, cx)).detach();+ // Activating an overlay (a click, or the focus hand-off when it opens)+ // lifts it to the top of its band on Windows and X11, over the camera.+ cx.observe_window_activation(window, |_, window, cx| {+ if window.is_window_active() {+ cx.defer(app_windows::raise_camera_above_overlays);+ }+ })+ .detach();let session = crate::session::RecordingSession::global(cx);let mut drawn_phase = session.read(cx).phase;cx.observe_in(&session, window, move |_, session, window, cx| {