Skip to content

Commit

Permalink
[ScreenCaptureKit] Improve and simplify the manually bound constructo…
Browse files Browse the repository at this point in the history
…rs for SCContentFilter. (#21654)
  • Loading branch information
rolfbjarne authored Nov 21, 2024
1 parent 6efc90f commit 4411755
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 27 deletions.
29 changes: 16 additions & 13 deletions src/ScreenCaptureKit/SCContentFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,52 @@
using ObjCRuntime;

namespace ScreenCaptureKit {

#if NET
/// <summary>This enum describes how to interpret some arguments when creating <see cref="SCContentFilter" /> instances.</summary>
[UnsupportedOSPlatform ("ios")]
[UnsupportedOSPlatform ("tvos")]
[SupportedOSPlatform ("macos12.3")]
[UnsupportedOSPlatform ("maccatalyst")]
#else
[NoiOS]
[NoTV]
[NoWatch]
[Mac (12, 3)]
[NoMacCatalyst]
#endif
public enum SCContentFilterOption {
/// <summary>The specified windows or applications are included in the filter.</summary>
Include,
/// <summary>The specified windows or applications are excluded from the filter.</summary>
Exclude,
}

public partial class SCContentFilter {

/// <summary>Create a new <see cref="SCContentFilter" /> to capture the contents of the specified display, including or excluding specific windows.</summary>
/// <param name="display">The display to capture.</param>
/// <param name="windows">The windows to include or exclude.</param>
/// <param name="option">Whether windows specified in the <paramref name="windows" /> parameter are to be included or excluded.</param>
public SCContentFilter (SCDisplay display, SCWindow [] windows, SCContentFilterOption option) : base (NSObjectFlag.Empty)
{
switch (option) {
case SCContentFilterOption.Include:
Handle = InitWithDisplayIncludingWindows (display, windows);
Handle = _InitWithDisplayIncludingWindows (display, windows);
break;
case SCContentFilterOption.Exclude:
Handle = InitWithDisplayExcludingWindows (display, windows);
Handle = _InitWithDisplayExcludingWindows (display, windows);
break;
default:
ObjCRuntime.ThrowHelper.ThrowArgumentOutOfRangeException (nameof (option), $"Unknown option {option}");
break;
};
}

/// <summary>Create a new <see cref="SCContentFilter" /> to capture the contents of the specified display, including or excluding specific apps.</summary>
/// <param name="display">The display to capture.</param>
/// <param name="applications">The applications to include or exclude.</param>
/// <param name="exceptingWindows">Any windows that are an exception to the condition to include or include windows.</param>
/// <param name="option">Whether applications specified in the <paramref name="applications" /> parameter are to be included or excluded.</param>
public SCContentFilter (SCDisplay display, SCRunningApplication [] applications, SCWindow [] exceptingWindows, SCContentFilterOption option) : base (NSObjectFlag.Empty)
{
switch (option) {
case SCContentFilterOption.Include:
Handle = InitWithDisplayIncludingApplications (display, applications, exceptingWindows);
Handle = _InitWithDisplayIncludingApplications (display, applications, exceptingWindows);
break;
case SCContentFilterOption.Exclude:
Handle = InitWithDisplayExcludingApplications (display, applications, exceptingWindows);
Handle = _InitWithDisplayExcludingApplications (display, applications, exceptingWindows);
break;
default:
ObjCRuntime.ThrowHelper.ThrowArgumentOutOfRangeException (nameof (option), $"Unknown option {option}");
Expand Down
8 changes: 4 additions & 4 deletions src/screencapturekit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,19 @@ interface SCContentFilter {

[Internal]
[Export ("initWithDisplay:excludingWindows:")]
NativeHandle InitWithDisplayExcludingWindows (SCDisplay display, SCWindow [] excludedWindows);
NativeHandle _InitWithDisplayExcludingWindows (SCDisplay display, SCWindow [] excludedWindows);

[Internal]
[Export ("initWithDisplay:includingWindows:")]
NativeHandle InitWithDisplayIncludingWindows (SCDisplay display, SCWindow [] includedWindows);
NativeHandle _InitWithDisplayIncludingWindows (SCDisplay display, SCWindow [] includedWindows);

[Internal]
[Export ("initWithDisplay:includingApplications:exceptingWindows:")]
NativeHandle InitWithDisplayIncludingApplications (SCDisplay display, SCRunningApplication [] includingApplications, SCWindow [] exceptingWindows);
NativeHandle _InitWithDisplayIncludingApplications (SCDisplay display, SCRunningApplication [] includingApplications, SCWindow [] exceptingWindows);

[Internal]
[Export ("initWithDisplay:excludingApplications:exceptingWindows:")]
NativeHandle InitWithDisplayExcludingApplications (SCDisplay display, SCRunningApplication [] excludingApplications, SCWindow [] exceptingWindows);
NativeHandle _InitWithDisplayExcludingApplications (SCDisplay display, SCRunningApplication [] excludingApplications, SCWindow [] exceptingWindows);

// per docs, the following selectors are available for 12.3+
// but return types are SCStreamType and SCShareableContentStyle are 14.0+
Expand Down
5 changes: 0 additions & 5 deletions tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17701,8 +17701,6 @@ F:ScreenCaptureKit.SCCaptureDynamicRange.Sdr
F:ScreenCaptureKit.SCCaptureResolutionType.Automatic
F:ScreenCaptureKit.SCCaptureResolutionType.Best
F:ScreenCaptureKit.SCCaptureResolutionType.Nominal
F:ScreenCaptureKit.SCContentFilterOption.Exclude
F:ScreenCaptureKit.SCContentFilterOption.Include
F:ScreenCaptureKit.SCContentSharingPickerMode.MultipleApplications
F:ScreenCaptureKit.SCContentSharingPickerMode.MultipleWindows
F:ScreenCaptureKit.SCContentSharingPickerMode.SingleApplication
Expand Down Expand Up @@ -43213,8 +43211,6 @@ M:ScreenCaptureKit.ISCStreamDelegate.DidStop(ScreenCaptureKit.SCStream,Foundatio
M:ScreenCaptureKit.ISCStreamDelegate.OutputVideoEffectDidStart(ScreenCaptureKit.SCStream)
M:ScreenCaptureKit.ISCStreamDelegate.OutputVideoEffectDidStop(ScreenCaptureKit.SCStream)
M:ScreenCaptureKit.ISCStreamOutput.DidOutputSampleBuffer(ScreenCaptureKit.SCStream,CoreMedia.CMSampleBuffer,ScreenCaptureKit.SCStreamOutputType)
M:ScreenCaptureKit.SCContentFilter.#ctor(ScreenCaptureKit.SCDisplay,ScreenCaptureKit.SCRunningApplication[],ScreenCaptureKit.SCWindow[],ScreenCaptureKit.SCContentFilterOption)
M:ScreenCaptureKit.SCContentFilter.#ctor(ScreenCaptureKit.SCDisplay,ScreenCaptureKit.SCWindow[],ScreenCaptureKit.SCContentFilterOption)
M:ScreenCaptureKit.SCScreenshotManager.CaptureImageAsync(ScreenCaptureKit.SCContentFilter,ScreenCaptureKit.SCStreamConfiguration)
M:ScreenCaptureKit.SCScreenshotManager.CaptureSampleBufferAsync(ScreenCaptureKit.SCContentFilter,ScreenCaptureKit.SCStreamConfiguration)
M:ScreenCaptureKit.SCShareableContent.GetCurrentProcessShareableContentAsync
Expand Down Expand Up @@ -75479,7 +75475,6 @@ T:ScreenCaptureKit.ISCStreamDelegate
T:ScreenCaptureKit.ISCStreamOutput
T:ScreenCaptureKit.SCCaptureDynamicRange
T:ScreenCaptureKit.SCCaptureResolutionType
T:ScreenCaptureKit.SCContentFilterOption
T:ScreenCaptureKit.SCContentSharingPickerMode
T:ScreenCaptureKit.SCContentSharingPickerObserver
T:ScreenCaptureKit.SCFrameStatus
Expand Down
5 changes: 0 additions & 5 deletions tests/introspection/ApiSelectorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1295,11 +1295,6 @@ protected virtual bool SkipInit (string selector, MethodBase m)
case "initWithProvisioningCredentialIdentifier:sharingInstanceIdentifier:cardConfigurationIdentifier:preview:":
// NSImage
case "initWithDataIgnoringOrientation:":
// SCContentFilter
case "initWithDisplay:excludingApplications:exceptingWindows:":
case "initWithDisplay:excludingWindows:":
case "initWithDisplay:includingApplications:exceptingWindows:":
case "initWithDisplay:includingWindows:":
var mi = m as MethodInfo;
return mi is not null && !mi.IsPublic && (mi.ReturnType.Name == "IntPtr" || mi.ReturnType.Name == "NativeHandle");
// NSAppleEventDescriptor
Expand Down

6 comments on commit 4411755

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.