Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Merge remote-tracking branch 'origin/main' into wip/gpui-local-2026-10-15

Richie McIlroy8ec06cf693b7
diff --cc apps/desktop-gpui/src/platform.rs
index dc9430aaa,3a1fab46c..8bf5a7ee5
--- a/apps/desktop-gpui/src/platform.rs
+++ b/apps/desktop-gpui/src/platform.rs
@@@ -1362,224 -1385,9 +1385,225 @@@ mod mac
/// Reverse of [`hide_native`] -- `makeKeyAndOrderFront:`.
pub fn show_native(native: &NativeWindow) {
native.0.makeKeyAndOrderFront(None);
+ rerun_occlusion_handler_after_show(&native.0);
}
+ /// Start an AppKit file drag of `path` from the mouse-down being handled
+ /// right now (`NSApp.currentEvent`): what Finder hands System Settings,
+ /// which adds a dropped `.app` to a privacy list. Called from a gpui
+ /// mouse-down listener; the session runs from the event loop afterwards.
+ pub fn begin_file_drag(window: &Window, path: &std::path::Path) -> bool {
+ use objc2::{class, msg_send};
+ use objc2_foundation::{NSPoint, NSRect, NSSize, NSString};
+
+ let Some(ns) = ns_window(window) else {
+ return false;
+ };
+ let source = file_drag_source();
+ unsafe {
+ let app: *mut AnyObject = msg_send![class!(NSApplication), sharedApplication];
+ let event: *mut AnyObject = msg_send![app, currentEvent];
+ let view: *mut AnyObject = msg_send![&*ns, contentView];
+ if event.is_null() || view.is_null() || source.is_null() {
+ return false;
+ }
+ let path = NSString::from_str(&path.to_string_lossy());
+ let url: *mut AnyObject = msg_send![class!(NSURL), fileURLWithPath: &*path];
+ if url.is_null() {
+ return false;
+ }
+ let item: *mut AnyObject = msg_send![class!(NSDraggingItem), alloc];
+ let item: *mut AnyObject = msg_send![item, initWithPasteboardWriter: url];
+ if item.is_null() {
+ return false;
+ }
+ let workspace: *mut AnyObject = msg_send![class!(NSWorkspace), sharedWorkspace];
+ let icon: *mut AnyObject = msg_send![workspace, iconForFile: &*path];
+ let _: () = msg_send![icon, setSize: NSSize::new(64., 64.)];
+ let location: NSPoint = msg_send![event, locationInWindow];
+ let point: NSPoint = msg_send![view, convertPoint: location, fromView: std::ptr::null_mut::<AnyObject>()];
+ let frame = NSRect::new(
+ NSPoint::new(point.x - 32., point.y - 32.),
+ NSSize::new(64., 64.),
+ );
+ let _: () = msg_send![item, setDraggingFrame: frame, contents: icon];
+ let items: *mut AnyObject = msg_send![class!(NSArray), arrayWithObject: item];
+ let _: () = msg_send![item, release];
+ let session: *mut AnyObject = msg_send![
+ view,
+ beginDraggingSessionWithItems: items,
+ event: event,
+ source: source
+ ];
+ if session.is_null() {
+ return false;
+ }
+ let _: () = msg_send![session, setAnimatesToStartingPositionsOnCancelOrFail: true];
+ true
+ }
+ }
+
+ /// The `NSDraggingSource` for [`begin_file_drag`]: copy/link/generic when
+ /// the drag leaves the app, nothing inside it. One instance, never freed.
+ fn file_drag_source() -> *mut AnyObject {
+ use std::sync::OnceLock;
+
+ use objc2::runtime::{AnyProtocol, ClassBuilder, NSObject};
+ use objc2::{ClassType, msg_send, sel};
+
+ unsafe extern "C" fn operation_mask(
+ _receiver: *mut AnyObject,
+ _selector: Sel,
+ _session: *mut AnyObject,
+ context: isize,
+ ) -> usize {
+ const OUTSIDE_APPLICATION: isize = 0;
+ const COPY_LINK_GENERIC: usize = 1 | 2 | 4;
+ if context == OUTSIDE_APPLICATION {
+ COPY_LINK_GENERIC
+ } else {
+ 0
+ }
+ }
+
+ static SOURCE: OnceLock<usize> = OnceLock::new();
+ *SOURCE.get_or_init(|| {
+ let Some(mut builder) = ClassBuilder::new("CapFileDragSource", NSObject::class())
+ else {
+ return 0;
+ };
+ unsafe {
+ builder.add_method(
+ sel!(draggingSession:sourceOperationMaskForDraggingContext:),
+ operation_mask
+ as unsafe extern "C" fn(
+ *mut AnyObject,
+ Sel,
+ *mut AnyObject,
+ isize,
+ ) -> usize,
+ );
+ }
+ if let Some(protocol) = AnyProtocol::get("NSDraggingSource") {
+ builder.add_protocol(protocol);
+ }
+ let class = builder.register();
+ let instance: *mut AnyObject = unsafe { msg_send![class, new] };
+ instance as usize
+ }) as *mut AnyObject
+ }
+
+ /// System Settings' main window in CoreGraphics coordinates (global,
+ /// top-left origin) -- bounds and owner pid are readable without Screen
+ /// Recording, titles are not, so the window is found by pid and size.
+ pub fn system_settings_frame() -> Option<(f64, f64, f64, f64)> {
+ use core_foundation::array::{CFArray, CFArrayRef};
+ use core_foundation::base::{CFType, TCFType};
+ use core_foundation::dictionary::CFDictionary;
+ use core_foundation::number::CFNumber;
+ use core_foundation::string::{CFString, CFStringRef};
+ use objc2::{class, msg_send};
+ use objc2_foundation::NSString;
+
+ #[link(name = "CoreGraphics", kind = "framework")]
+ unsafe extern "C" {
+ fn CGWindowListCopyWindowInfo(option: u32, relative_to: u32) -> CFArrayRef;
+ static kCGWindowOwnerPID: CFStringRef;
+ static kCGWindowLayer: CFStringRef;
+ static kCGWindowBounds: CFStringRef;
+ }
+ const ON_SCREEN_ONLY: u32 = 1 << 0;
+ const EXCLUDE_DESKTOP_ELEMENTS: u32 = 1 << 4;
+
+ let pid: i32 = unsafe {
+ let bundle = NSString::from_str("com.apple.systempreferences");
+ let apps: *mut AnyObject = msg_send![
+ class!(NSRunningApplication),
+ runningApplicationsWithBundleIdentifier: &*bundle
+ ];
+ if apps.is_null() {
+ return None;
+ }
+ let app: *mut AnyObject = msg_send![apps, firstObject];
+ if app.is_null() {
+ return None;
+ }
+ msg_send![app, processIdentifier]
+ };
+
+ let list = unsafe {
+ let raw = CGWindowListCopyWindowInfo(ON_SCREEN_ONLY | EXCLUDE_DESKTOP_ELEMENTS, 0);
+ if raw.is_null() {
+ return None;
+ }
+ CFArray::<CFDictionary<CFString, CFType>>::wrap_under_create_rule(raw)
+ };
+ let number = |dict: &CFDictionary<CFString, CFType>, key: &CFString| -> Option<f64> {
+ dict.find(key)?.downcast::<CFNumber>()?.to_f64()
+ };
+ let (owner_key, layer_key, bounds_key) = unsafe {
+ (
+ CFString::wrap_under_get_rule(kCGWindowOwnerPID),
+ CFString::wrap_under_get_rule(kCGWindowLayer),
+ CFString::wrap_under_get_rule(kCGWindowBounds),
+ )
+ };
+ let mut best: Option<(f64, f64, f64, f64)> = None;
+ for window in list.iter() {
+ if number(&window, &owner_key) != Some(pid as f64)
+ || number(&window, &layer_key) != Some(0.)
+ {
+ continue;
+ }
+ let Some(bounds) = window
+ .find(&bounds_key)
+ .and_then(|value| value.downcast::<CFDictionary>())
+ else {
+ continue;
+ };
+ let bounds: CFDictionary<CFString, CFType> =
+ unsafe { CFDictionary::wrap_under_get_rule(bounds.as_concrete_TypeRef()) };
+ let field = |name: &'static str| number(&bounds, &CFString::from_static_string(name));
+ let (Some(x), Some(y), Some(w), Some(h)) =
+ (field("X"), field("Y"), field("Width"), field("Height"))
+ else {
+ continue;
+ };
+ if w < 320. || h < 240. {
+ continue;
+ }
+ if best.is_none_or(|(_, _, bw, bh)| w * h > bw * bh) {
+ best = Some((x, y, w, h));
+ }
+ }
+ best
+ }
+
+ /// Whether the user is in System Settings or one of the authentication
+ /// sheets a privacy-list change raises.
+ pub fn system_settings_frontmost() -> bool {
+ use objc2::{class, msg_send};
+ use objc2_foundation::NSString;
+
+ unsafe {
+ let workspace: *mut AnyObject = msg_send![class!(NSWorkspace), sharedWorkspace];
+ let app: *mut AnyObject = msg_send![workspace, frontmostApplication];
+ if app.is_null() {
+ return false;
+ }
+ let bundle: *mut NSString = msg_send![app, bundleIdentifier];
+ let Some(bundle) = bundle.as_ref() else {
+ return false;
+ };
+ matches!(
+ bundle.to_string().as_str(),
+ "com.apple.systempreferences"
+ | "com.apple.SecurityAgent"
+ | "com.apple.LocalAuthentication.UIAgent"
+ )
+ }
+ }
+
/// Close the window the way the red traffic light does: ask the
/// delegate's `windowShouldClose:` (gpui's `on_window_should_close`,
/// where every window's close bookkeeping lives), then `close`.
diff --cc apps/desktop-gpui/src/target_overlay.rs
index ca1c43ac4,27048fa16..7c0bbd63f
--- a/apps/desktop-gpui/src/target_overlay.rs
+++ b/apps/desktop-gpui/src/target_overlay.rs
@@@ -651,15 -673,7 +678,20 @@@ impl OverlayWindow
let main_subscription = main
.update(cx, |_, _, cx| cx.entity())
.ok()
- .map(|main| cx.observe(&main, |_, _, cx| cx.notify()));
+ .map(|main| cx.observe_in(&main, window, |_, _, window, cx| repaint(window, cx)));
+ let media = crate::media_access::MediaAccess::global(cx);
+ media.update(cx, |access, cx| access.refresh(cx));
- cx.observe(&media, |_, _, cx| cx.notify()).detach();
- cx.observe(&SignIn::global(cx), |this: &mut Self, _, cx| {
- this.signed_in = crate::store::auth_snapshot().signed_in();
- cx.notify();
- })
++ cx.observe_in(&media, window, |_, _, window, cx| repaint(window, cx))
++ .detach();
++ cx.observe_in(
++ &SignIn::global(cx),
++ window,
++ |this: &mut Self, _, window, cx| {
++ this.signed_in = crate::store::auth_snapshot().signed_in();
++ repaint(window, cx);
++ },
++ )
+ .detach();
let logical = display
.logical_size()