pub struct SCContentFilter(/* private fields */);Expand description
Content filter for ScreenCaptureKit streams
Defines what content to capture (displays, windows, or applications).
§Immutability, Clone, Send and Sync
An SCContentFilter is immutable once built. Every method on it is a
read; the one property Apple declares as writable, includeMenuBar, is set
by SCContentFilterBuilder::with_include_menu_bar while the underlying
object is still uniquely owned by the builder and has not yet escaped.
That invariant is what makes the three otherwise-conflicting properties of this type sound together:
Clonealiases.SCContentFilteris a plainNSObject: Apple provides no copy initialiser and does not conform it toNSCopying, so a deep copy is impossible. Cloning therefore performs an Objective-Cretainand hands back a second handle to the same object.Send + Syncareunsafe impls. They promise that sharing a handle across threads is safe.includeMenuBaris@property(nonatomic, assign)— an unsynchronisedBOOLivar.
Exposing a setter alongside an aliasing Clone and Sync would let two
threads write and read that ivar concurrently through safe Rust, which is a
data race. Removing the setter (rather than Clone or Send/Sync) keeps
the ergonomic handle semantics while leaving nothing to race on. Filters
obtained from the content sharing picker keep whatever includeMenuBar
value the system chose; build your own filter if you need to override it.
§Examples
use screencapturekit::shareable_content::SCShareableContent;
use screencapturekit::stream::content_filter::SCContentFilter;
let content = SCShareableContent::get()?;
let display = &content.displays()[0];
// Capture entire display
let filter = SCContentFilter::create()
.with_display(display)
.with_excluding_windows(&[])
.build()?;
// Or capture a specific window
let window = &content.windows()[0];
let filter = SCContentFilter::create()
.with_window(window)
.build()?;Implementations§
Source§impl SCContentFilter
impl SCContentFilter
Sourcepub fn create() -> SCContentFilterBuilder
pub fn create() -> SCContentFilterBuilder
Creates a content filter builder
§Examples
use screencapturekit::prelude::*;
let content = SCShareableContent::get()?;
let display = &content.displays()[0];
let filter = SCContentFilter::create()
.with_display(display)
.with_excluding_windows(&[])
.build()?;Sourcepub fn content_rect(&self) -> CGRect
pub fn content_rect(&self) -> CGRect
Gets the content rectangle for this filter (macOS 14.0+)
This mirrors Apple’s read-only SCContentFilter.contentRect: the rect,
in points, that the filter’s content occupies. There is no setter —
SCContentFilter derives the rect from the display/window/application
it was built from. Returns a zero rect on macOS < 14.0.
Sourcepub fn style(&self) -> SCResult<SCShareableContentStyle>
pub fn style(&self) -> SCResult<SCShareableContentStyle>
Get the content style (macOS 14.0+)
Returns the type of content being captured (window, display, application, or none).
Sourcepub fn stream_type(&self) -> SCResult<SCStreamType>
👎Deprecated since 8.0.0: Apple deprecated SCContentFilter.streamType in macOS 14.2 (and SCStreamType itself in 15.0). Use style(), which also distinguishes application filters.
pub fn stream_type(&self) -> SCResult<SCStreamType>
Apple deprecated SCContentFilter.streamType in macOS 14.2 (and SCStreamType itself in 15.0). Use style(), which also distinguishes application filters.
Get the stream type (macOS 14.0+)
Returns whether this filter captures a window or a display.
Sourcepub fn point_pixel_scale(&self) -> f32
pub fn point_pixel_scale(&self) -> f32
Get the point-to-pixel scale factor (macOS 14.0+)
Returns the scaling factor used to convert points to pixels. Typically 2.0 for Retina displays.
Whether the menu bar is included in capture (macOS 14.2+)
Fixed when the filter is built. Apple’s default depends on the
constructor — true for display-excluding filters, false for
display-including ones — and is overridden by
SCContentFilterBuilder::with_include_menu_bar.
There is deliberately no setter: SCContentFilter is immutable once it
escapes the builder, which is what makes Clone, Send and
Sync sound for this handle. See the type-level docs.
Sourcepub fn included_displays(&self) -> Vec<SCDisplay>
pub fn included_displays(&self) -> Vec<SCDisplay>
Get included displays (macOS 15.2+)
Returns the displays currently included in this filter.
Sourcepub fn included_windows(&self) -> Vec<SCWindow>
pub fn included_windows(&self) -> Vec<SCWindow>
Get included windows (macOS 15.2+)
Returns the windows currently included in this filter.
Sourcepub fn included_applications(&self) -> Vec<SCRunningApplication>
pub fn included_applications(&self) -> Vec<SCRunningApplication>
Get included applications (macOS 15.2+)
Returns the applications currently included in this filter.