SCContentSharingPicker

Struct SCContentSharingPicker 

Source
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: AsyncSCContentSharingPicker from the async_api module

§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

Source

pub fn show<F>(config: &SCContentSharingPickerConfiguration, callback: F)
where F: FnOnce(SCPickerOutcome) + Send + 'static,

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),
    }
});
Source

pub fn show_for_stream<F>( config: &SCContentSharingPickerConfiguration, stream: &SCStream, callback: F, )
where F: FnOnce(SCPickerOutcome) + Send + 'static,

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(())
}
Source

pub fn show_filter<F>(config: &SCContentSharingPickerConfiguration, callback: F)
where F: FnOnce(SCPickerFilterOutcome) + Send + 'static,

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
    }
});
Source

pub fn show_using_style<F>( config: &SCContentSharingPickerConfiguration, style: SCShareableContentStyle, callback: F, )
where F: FnOnce(SCPickerOutcome) + Send + 'static,

Show the picker UI with a specific content style

Presents the picker pre-filtered to a specific content type.

§Arguments
  • config - The picker configuration
  • style - The content style to show (Window, Display, Application)
  • callback - Called with the picker result
Source

pub fn show_for_stream_using_style<F>( config: &SCContentSharingPickerConfiguration, stream: &SCStream, style: SCShareableContentStyle, callback: F, )
where F: FnOnce(SCPickerOutcome) + Send + 'static,

Show the picker for an existing stream with a specific content style

§Arguments
  • config - The picker configuration
  • stream - The stream to update
  • style - The content style to show (Window, Display, Application)
  • callback - Called with the picker result
Source

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.

Source

pub fn maximum_stream_count() -> usize

Get the maximum number of streams allowed

Returns 0 if unlimited streams are allowed.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.