objc2-screen-capture-kit 0.3.2

Bindings to the ScreenCaptureKit framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-foundation")]
use objc2_core_foundation::*;
#[cfg(feature = "objc2-core-graphics")]
use objc2_core_graphics::*;
#[cfg(feature = "objc2-core-media")]
use objc2_core_media::*;
use objc2_foundation::*;
#[cfg(feature = "objc2-uniform-type-identifiers")]
use objc2_uniform_type_identifiers::*;

use crate::*;

/// [Apple's documentation](https://developer.apple.com/documentation/screencapturekit/scscreenshotdisplayintent?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SCScreenshotDisplayIntent(pub NSInteger);
impl SCScreenshotDisplayIntent {
    #[doc(alias = "SCScreenshotDisplayIntentCanonical")]
    pub const Canonical: Self = Self(0);
    #[doc(alias = "SCScreenshotDisplayIntentLocal")]
    pub const Local: Self = Self(1);
}

unsafe impl Encode for SCScreenshotDisplayIntent {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for SCScreenshotDisplayIntent {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

/// [Apple's documentation](https://developer.apple.com/documentation/screencapturekit/scscreenshotdynamicrange?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SCScreenshotDynamicRange(pub NSInteger);
impl SCScreenshotDynamicRange {
    #[doc(alias = "SCScreenshotDynamicRangeSDR")]
    pub const SDR: Self = Self(0);
    #[doc(alias = "SCScreenshotDynamicRangeHDR")]
    pub const HDR: Self = Self(1);
    #[doc(alias = "SCScreenshotDynamicRangeSDRAndHDR")]
    pub const SDRAndHDR: Self = Self(2);
}

unsafe impl Encode for SCScreenshotDynamicRange {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for SCScreenshotDynamicRange {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/screencapturekit/scscreenshotconfiguration?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct SCScreenshotConfiguration;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for SCScreenshotConfiguration {}
);

impl SCScreenshotConfiguration {
    extern_methods!(
        /// SCScreenshotProperty for output width as measured in pixels. Default is the width of the content being captured.
        #[unsafe(method(width))]
        #[unsafe(method_family = none)]
        pub unsafe fn width(&self) -> NSInteger;

        /// Setter for [`width`][Self::width].
        #[unsafe(method(setWidth:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setWidth(&self, width: NSInteger);

        /// SCScreenshotProperty for output height as measured in pixels. Default is the height of the content being captured.
        #[unsafe(method(height))]
        #[unsafe(method_family = none)]
        pub unsafe fn height(&self) -> NSInteger;

        /// Setter for [`height`][Self::height].
        #[unsafe(method(setHeight:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHeight(&self, height: NSInteger);

        /// SCScreenshotProperty that specifies whether the cursor should appear in the screenshot.  By default the cursor is visible.
        #[unsafe(method(showsCursor))]
        #[unsafe(method_family = none)]
        pub unsafe fn showsCursor(&self) -> bool;

        /// Setter for [`showsCursor`][Self::showsCursor].
        #[unsafe(method(setShowsCursor:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setShowsCursor(&self, shows_cursor: bool);

        #[cfg(feature = "objc2-core-foundation")]
        /// SCScreenshotProperty that specifies that the screenshot only samples a subset of the frame input. If not set, then the entire screenshot will be captured. The rectangle is specified in points in the display’s logical coordinate system.
        #[unsafe(method(sourceRect))]
        #[unsafe(method_family = none)]
        pub unsafe fn sourceRect(&self) -> CGRect;

        #[cfg(feature = "objc2-core-foundation")]
        /// Setter for [`sourceRect`][Self::sourceRect].
        #[unsafe(method(setSourceRect:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSourceRect(&self, source_rect: CGRect);

        #[cfg(feature = "objc2-core-foundation")]
        /// SCScreenshotProperty that specifies that the screenshot outputs into a subset of the output CGimage.If not set then the output surface is used. The rectangle is specified in pixels in the display's coordinate system.
        #[unsafe(method(destinationRect))]
        #[unsafe(method_family = none)]
        pub unsafe fn destinationRect(&self) -> CGRect;

        #[cfg(feature = "objc2-core-foundation")]
        /// Setter for [`destinationRect`][Self::destinationRect].
        #[unsafe(method(setDestinationRect:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDestinationRect(&self, destination_rect: CGRect);

        /// SCScreenshotProperty to ignore framing on windows (will ignore shadows).
        #[unsafe(method(ignoreShadows))]
        #[unsafe(method_family = none)]
        pub unsafe fn ignoreShadows(&self) -> bool;

        /// Setter for [`ignoreShadows`][Self::ignoreShadows].
        #[unsafe(method(setIgnoreShadows:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setIgnoreShadows(&self, ignore_shadows: bool);

        /// SCScreenshotProperty to ignore framing on windows in the display bounded sharing case (will ignore shadows).
        #[unsafe(method(ignoreClipping))]
        #[unsafe(method_family = none)]
        pub unsafe fn ignoreClipping(&self) -> bool;

        /// Setter for [`ignoreClipping`][Self::ignoreClipping].
        #[unsafe(method(setIgnoreClipping:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setIgnoreClipping(&self, ignore_clipping: bool);

        /// SCScreenshotProperty to show the child windows of the applications and windows being captured.  Child windows are included by default.
        #[unsafe(method(includeChildWindows))]
        #[unsafe(method_family = none)]
        pub unsafe fn includeChildWindows(&self) -> bool;

        /// Setter for [`includeChildWindows`][Self::includeChildWindows].
        #[unsafe(method(setIncludeChildWindows:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setIncludeChildWindows(&self, include_child_windows: bool);

        /// Specifies the render type of the screenshot.
        #[unsafe(method(displayIntent))]
        #[unsafe(method_family = none)]
        pub unsafe fn displayIntent(&self) -> SCScreenshotDisplayIntent;

        /// Setter for [`displayIntent`][Self::displayIntent].
        #[unsafe(method(setDisplayIntent:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDisplayIntent(&self, display_intent: SCScreenshotDisplayIntent);

        /// Specifies the CGImage to return to the client.
        #[unsafe(method(dynamicRange))]
        #[unsafe(method_family = none)]
        pub unsafe fn dynamicRange(&self) -> SCScreenshotDynamicRange;

        /// Setter for [`dynamicRange`][Self::dynamicRange].
        #[unsafe(method(setDynamicRange:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setDynamicRange(&self, dynamic_range: SCScreenshotDynamicRange);

        #[cfg(feature = "objc2-uniform-type-identifiers")]
        /// Specifies the screenshot file format.
        ///
        /// # Safety
        ///
        /// This is not retained internally, you must ensure the object is still alive.
        #[unsafe(method(contentType))]
        #[unsafe(method_family = none)]
        pub unsafe fn contentType(&self) -> Retained<UTType>;

        #[cfg(feature = "objc2-uniform-type-identifiers")]
        /// Setter for [`contentType`][Self::contentType].
        ///
        /// # Safety
        ///
        /// This is unretained, you must ensure the object is kept alive while in use.
        #[unsafe(method(setContentType:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setContentType(&self, content_type: &UTType);

        /// Specifies output URL to save the screenshot.  If the imageOutputURL is nil, then the file will not be saved.
        #[unsafe(method(fileURL))]
        #[unsafe(method_family = none)]
        pub unsafe fn fileURL(&self) -> Option<Retained<NSURL>>;

        /// Setter for [`fileURL`][Self::fileURL].
        #[unsafe(method(setFileURL:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setFileURL(&self, file_url: Option<&NSURL>);

        #[cfg(feature = "objc2-uniform-type-identifiers")]
        /// an array of UTTypes that corresponds to the file formats that are supported. ScreenCaptureKit can save the CGImage into heic, jpeg, and png
        #[unsafe(method(supportedContentTypes))]
        #[unsafe(method_family = none)]
        pub unsafe fn supportedContentTypes() -> Retained<NSArray<UTType>>;
    );
}

/// Methods declared on superclass `NSObject`.
impl SCScreenshotConfiguration {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/screencapturekit/scscreenshotoutput?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct SCScreenshotOutput;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for SCScreenshotOutput {}
);

impl SCScreenshotOutput {
    extern_methods!(
        #[cfg(feature = "objc2-core-graphics")]
        /// SCScreenshotOutput property that denotes the SDR CGimage.  The output CGImage uses the same color space as the display
        #[unsafe(method(sdrImage))]
        #[unsafe(method_family = none)]
        pub unsafe fn sdrImage(&self) -> Option<Retained<CGImage>>;

        #[cfg(feature = "objc2-core-graphics")]
        /// Setter for [`sdrImage`][Self::sdrImage].
        #[unsafe(method(setSdrImage:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setSdrImage(&self, sdr_image: Option<&CGImage>);

        #[cfg(feature = "objc2-core-graphics")]
        /// SCScreenshotOutput property that denotes the HDR CGimage.  The output CGImage uses the extended sRGB color space.
        #[unsafe(method(hdrImage))]
        #[unsafe(method_family = none)]
        pub unsafe fn hdrImage(&self) -> Option<Retained<CGImage>>;

        #[cfg(feature = "objc2-core-graphics")]
        /// Setter for [`hdrImage`][Self::hdrImage].
        #[unsafe(method(setHdrImage:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setHdrImage(&self, hdr_image: Option<&CGImage>);

        /// SCScreenshotOutput property to specify the location where the image was saved.  If a fileURL in the screenshot configuration was not specified, then the fileURL will be nil
        ///
        /// # Safety
        ///
        /// This is not retained internally, you must ensure the object is still alive.
        #[unsafe(method(fileURL))]
        #[unsafe(method_family = none)]
        pub unsafe fn fileURL(&self) -> Option<Retained<NSURL>>;

        /// Setter for [`fileURL`][Self::fileURL].
        ///
        /// # Safety
        ///
        /// This is unretained, you must ensure the object is kept alive while in use.
        #[unsafe(method(setFileURL:))]
        #[unsafe(method_family = none)]
        pub unsafe fn setFileURL(&self, file_url: Option<&NSURL>);
    );
}

/// Methods declared on superclass `NSObject`.
impl SCScreenshotOutput {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}

extern_class!(
    /// [Apple's documentation](https://developer.apple.com/documentation/screencapturekit/scscreenshotmanager?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct SCScreenshotManager;
);

extern_conformance!(
    unsafe impl NSObjectProtocol for SCScreenshotManager {}
);

impl SCScreenshotManager {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[cfg(all(feature = "SCStream", feature = "block2", feature = "objc2-core-media"))]
        /// captureSampleBufferWithFilter:configuration:completionHandler:
        ///
        /// Parameter `contentFilter`: is the filter containing the content to take a screenshot of
        ///
        /// Parameter `config`: is the stream configuration containing information on how to format the screenshot
        ///
        /// Parameter `completionHandler`: is the handler that will deliver the screenshot to the user
        ///
        /// this method takes a screenshot using the filter and configuration passed in and returns it as a CMSampleBuffer
        #[unsafe(method(captureSampleBufferWithFilter:configuration:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn captureSampleBufferWithFilter_configuration_completionHandler(
            content_filter: &SCContentFilter,
            config: &SCStreamConfiguration,
            completion_handler: Option<
                &block2::DynBlock<dyn Fn(*mut CMSampleBuffer, *mut NSError)>,
            >,
        );

        #[cfg(all(
            feature = "SCStream",
            feature = "block2",
            feature = "objc2-core-graphics"
        ))]
        /// captureImageWithFilter:configuration:completionHandler:
        ///
        /// Parameter `contentFilter`: is the filter containing the content to take a screenshot of
        ///
        /// Parameter `config`: is the stream configuration containing information on how to format the screenshot
        ///
        /// Parameter `completionHandler`: is the handler that will deliver the screenshot to the user
        ///
        /// this method takes a screenshot using the filter and configuration passed in and returns it as a CGImage in BGRA format if captureDynamicRange is SCCaptureDynamicRangeSDR, in RGhA format if captureDynamicRange is SCCaptureDynamicRangeHDRLocalDisplay/SCCaptureDynamicRangeHDRCanonicalDisplay
        #[unsafe(method(captureImageWithFilter:configuration:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn captureImageWithFilter_configuration_completionHandler(
            content_filter: &SCContentFilter,
            config: &SCStreamConfiguration,
            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut CGImage, *mut NSError)>>,
        );

        #[cfg(all(
            feature = "block2",
            feature = "objc2-core-foundation",
            feature = "objc2-core-graphics"
        ))]
        /// captureImageInRect:completionHandler:
        ///
        /// Parameter `rect`: the rect for the region in points on the screen space for the screen shot, this is display agnostic and supports multiple displays
        ///
        /// Parameter `completionHandler`: is the handler that will deliver the screenshot to the client
        ///
        /// this method returns an image containing the contents of the rectangle in points, specified in display space
        #[unsafe(method(captureImageInRect:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn captureImageInRect_completionHandler(
            rect: CGRect,
            completion_handler: Option<&block2::DynBlock<dyn Fn(*mut CGImage, *mut NSError)>>,
        );

        #[cfg(all(feature = "SCStream", feature = "block2"))]
        /// captureScreenshotWithFilter:configuration:completionHandler:
        ///
        /// Parameter `contentFilter`: is the filter containing the content to take a screenshot of
        ///
        /// Parameter `config`: is the screenshot configuration containing information on how to format the screenshot
        ///
        /// Parameter `completionHandler`: is the handler that will deliver the SCScreenshotOutput object to the client
        ///
        /// this method returns an SCScreenshotOutput object containing CGImages of the screenshot requested by the client
        #[unsafe(method(captureScreenshotWithFilter:configuration:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn captureScreenshotWithFilter_configuration_completionHandler(
            content_filter: &SCContentFilter,
            config: &SCScreenshotConfiguration,
            completion_handler: Option<
                &block2::DynBlock<dyn Fn(*mut SCScreenshotOutput, *mut NSError)>,
            >,
        );

        #[cfg(all(feature = "block2", feature = "objc2-core-foundation"))]
        /// captureScreenshotWithRect:configuration:completionHandler:
        ///
        /// Parameter `rect`: the rect for the region in points on the screen space for the screen shot, this is display agnostic and supports multiple displays
        ///
        /// Parameter `config`: is the screenshot configuration containing information on how to format the screenshot
        ///
        /// Parameter `completionHandler`: is the handler that will deliver the SCScreenshotOutput object to the client
        ///
        /// this method returns an SCScreenshotOutput object containing CGImages of the screenshot requested by the client
        #[unsafe(method(captureScreenshotWithRect:configuration:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn captureScreenshotWithRect_configuration_completionHandler(
            rect: CGRect,
            config: &SCScreenshotConfiguration,
            completion_handler: Option<
                &block2::DynBlock<dyn Fn(*mut SCScreenshotOutput, *mut NSError)>,
            >,
        );
    );
}

/// Methods declared on superclass `NSObject`.
impl SCScreenshotManager {
    extern_methods!(
        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;
    );
}