pub struct SCContentSharingPicker;Expand description
System UI for selecting content to share
Available on macOS 14.0+
The picker requires user interaction and cannot block the calling thread. Use one of these approaches:
- Callback-based:
show()/show_filter()- pass a callback closure - Async/await:
AsyncSCContentSharingPickerfrom theasync_apimodule
§Example (callback)
use screencapturekit::content_sharing_picker::*;
let config = SCContentSharingPickerConfiguration::new();
SCContentSharingPicker::show(&config, |outcome| {
if let SCPickerOutcome::Picked(result) = outcome {
let (width, height) = result.pixel_size();
let filter = result.filter();
// ... create stream
}
});§Example (async)
use screencapturekit::async_api::AsyncSCContentSharingPicker;
use screencapturekit::content_sharing_picker::*;
async fn example() {
let config = SCContentSharingPickerConfiguration::new();
if let SCPickerOutcome::Picked(result) = AsyncSCContentSharingPicker::show(&config).await {
let (width, height) = result.pixel_size();
let filter = result.filter();
// ... create stream
}
}Implementations§
Source§impl SCContentSharingPicker
impl SCContentSharingPicker
Sourcepub fn show<F>(config: &SCContentSharingPickerConfiguration, callback: F)
pub fn show<F>(config: &SCContentSharingPickerConfiguration, callback: F)
Show the picker UI with a callback for the result
This is non-blocking - the callback is invoked when the user makes a selection or cancels the picker.
§Example
use screencapturekit::content_sharing_picker::*;
let config = SCContentSharingPickerConfiguration::new();
SCContentSharingPicker::show(&config, |outcome| {
match outcome {
SCPickerOutcome::Picked(result) => {
let (width, height) = result.pixel_size();
let filter = result.filter();
println!("Selected {}x{}", width, height);
}
SCPickerOutcome::Cancelled => println!("Cancelled"),
SCPickerOutcome::Error(e) => eprintln!("Error: {}", e),
}
});Sourcepub fn show_for_stream<F>(
config: &SCContentSharingPickerConfiguration,
stream: &SCStream,
callback: F,
)
pub fn show_for_stream<F>( config: &SCContentSharingPickerConfiguration, stream: &SCStream, callback: F, )
Show the picker UI for an existing stream (to change source while capturing)
Use this when you have an active SCStream and want to let the user
select a new content source. The callback receives the new filter
which can be used with stream.update_content_filter().
§Example
use screencapturekit::content_sharing_picker::*;
use screencapturekit::stream::SCStream;
use screencapturekit::stream::configuration::SCStreamConfiguration;
use screencapturekit::stream::content_filter::SCContentFilter;
use screencapturekit::shareable_content::SCShareableContent;
fn example() -> Option<()> {
let content = SCShareableContent::get().ok()?;
let displays = content.displays();
let display = displays.first()?;
let filter = SCContentFilter::create().with_display(display).with_excluding_windows(&[]).build();
let stream_config = SCStreamConfiguration::new();
let stream = SCStream::new(&filter, &stream_config);
// When stream is active and user wants to change source
let config = SCContentSharingPickerConfiguration::new();
SCContentSharingPicker::show_for_stream(&config, &stream, |outcome| {
if let SCPickerOutcome::Picked(result) = outcome {
// Use result.filter() with stream.update_content_filter()
let _ = result.filter();
}
});
Some(())
}Sourcepub fn show_filter<F>(config: &SCContentSharingPickerConfiguration, callback: F)
pub fn show_filter<F>(config: &SCContentSharingPickerConfiguration, callback: F)
Show the picker UI with a callback that receives just the filter
This is the simple API - use when you just need the filter without metadata.
§Example
use screencapturekit::content_sharing_picker::*;
let config = SCContentSharingPickerConfiguration::new();
SCContentSharingPicker::show_filter(&config, |outcome| {
if let SCPickerFilterOutcome::Filter(filter) = outcome {
// Use filter with SCStream
}
});Sourcepub fn show_using_style<F>(
config: &SCContentSharingPickerConfiguration,
style: SCShareableContentStyle,
callback: F,
)
pub fn show_using_style<F>( config: &SCContentSharingPickerConfiguration, style: SCShareableContentStyle, callback: F, )
Show the picker UI with a specific content style
Presents the picker pre-filtered to a specific content type.
§Arguments
config- The picker configurationstyle- The content style to show (Window, Display, Application)callback- Called with the picker result
Sourcepub fn show_for_stream_using_style<F>(
config: &SCContentSharingPickerConfiguration,
stream: &SCStream,
style: SCShareableContentStyle,
callback: F,
)
pub fn show_for_stream_using_style<F>( config: &SCContentSharingPickerConfiguration, stream: &SCStream, style: SCShareableContentStyle, callback: F, )
Show the picker for an existing stream with a specific content style
§Arguments
config- The picker configurationstream- The stream to updatestyle- The content style to show (Window, Display, Application)callback- Called with the picker result
Sourcepub fn set_maximum_stream_count(count: usize)
pub fn set_maximum_stream_count(count: usize)
Set the maximum number of streams that can be created from the picker
Pass 0 to allow unlimited streams.
Sourcepub fn maximum_stream_count() -> usize
pub fn maximum_stream_count() -> usize
Get the maximum number of streams allowed
Returns 0 if unlimited streams are allowed.