Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(macos): stabilize capture target discovery and screen startup

Richie McIlroy0d883567ab99
diff --git a/crates/recording/src/sources/screen_capture/macos.rs b/crates/recording/src/sources/screen_capture/macos.rs
index 620e70b14..462b83a58 100644
--- a/crates/recording/src/sources/screen_capture/macos.rs
+++ b/crates/recording/src/sources/screen_capture/macos.rs
@@ -150,6 +150,13 @@ impl output_pipeline::VideoFrame for VideoFrame {
fn timestamp(&self) -> Timestamp {
self.timestamp
}
+
+ fn duplicate(&self) -> Option<Self> {
+ Some(Self {
+ sample_buf: self.sample_buf.clone(),
+ timestamp: self.timestamp,
+ })
+ }
}
impl ScreenCaptureConfig<CMSampleBufferCapture> {
diff --git a/crates/scap-targets/src/platform/macos.rs b/crates/scap-targets/src/platform/macos.rs
index df961872e..699ad57ca 100644
--- a/crates/scap-targets/src/platform/macos.rs
+++ b/crates/scap-targets/src/platform/macos.rs
@@ -510,7 +510,7 @@ impl WindowImpl {
pub fn app_icon(&self) -> Option<Vec<u8>> {
use cocoa::base::{id, nil};
- use cocoa::foundation::{NSArray, NSAutoreleasePool, NSString};
+ use cocoa::foundation::{NSArray, NSAutoreleasePool, NSPoint, NSRect, NSSize, NSString};
use objc::{class, msg_send, sel, sel_impl};
let owner_name = self.owner_name()?;
@@ -549,16 +549,24 @@ impl WindowImpl {
return None;
}
- let tiff_data: id = msg_send![icon, TIFFRepresentation];
- if tiff_data.is_null() {
+ let mut bounds = NSRect::new(NSPoint::new(0., 0.), NSSize::new(128., 128.));
+ let image: *mut std::ffi::c_void = msg_send![
+ icon,
+ CGImageForProposedRect: &mut bounds
+ context: nil
+ hints: nil
+ ];
+ if image.is_null() {
return None;
}
let bitmap_rep_class = class!(NSBitmapImageRep);
- let bitmap_rep: id = msg_send![bitmap_rep_class, imageRepWithData: tiff_data];
+ let bitmap_rep: id = msg_send![bitmap_rep_class, alloc];
+ let bitmap_rep: id = msg_send![bitmap_rep, initWithCGImage: image];
if bitmap_rep.is_null() {
return None;
}
+ let bitmap_rep: id = msg_send![bitmap_rep, autorelease];
let png_data: id = msg_send![
bitmap_rep,