diff --git a/bindings/csharp/src/CNativeAPI/generated/CaptureSource.cs b/bindings/csharp/src/CNativeAPI/generated/CaptureSource.cs
new file mode 100644
index 00000000..519ac7fa
--- /dev/null
+++ b/bindings/csharp/src/CNativeAPI/generated/CaptureSource.cs
@@ -0,0 +1,28 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+#nullable enable
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace CNativeAPI;
+
+public static partial class Interop
+{
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr native_capture_source_get_name(ulong self);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern int native_capture_source_get_type(ulong self);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern ulong native_capture_source_from_display(ulong display);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern ulong native_capture_source_from_window(ulong window);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern void native_capture_source_free(ulong handle);
+}
+
diff --git a/bindings/csharp/src/CNativeAPI/generated/ScreenCapturer.cs b/bindings/csharp/src/CNativeAPI/generated/ScreenCapturer.cs
new file mode 100644
index 00000000..c8abdfe6
--- /dev/null
+++ b/bindings/csharp/src/CNativeAPI/generated/ScreenCapturer.cs
@@ -0,0 +1,59 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+#nullable enable
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace CNativeAPI;
+
+[StructLayout(LayoutKind.Sequential)]
+public struct native_capture_source_selection_options_t
+{
+ public byte allow_displays;
+ public byte allow_windows;
+ public ulong parent_window;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct native_screen_capture_options_t
+{
+ public byte include_cursor;
+ public byte crop_enabled;
+ public native_rectangle_t crop;
+}
+
+[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+public delegate void ScreenCapturerCaptureCallbackNativeCallback([MarshalAs(UnmanagedType.I1)] bool arg0, ulong arg1, ulong delivery, IntPtr userData);
+
+[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+public delegate void ScreenCapturerSelectSourceCallbackNativeCallback([MarshalAs(UnmanagedType.I1)] bool arg0, ulong arg1, ulong delivery, IntPtr userData);
+
+public static partial class Interop
+{
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ [return: MarshalAs(UnmanagedType.I1)]
+ public static extern bool native_screen_capturer_is_direct_capture_supported(int type);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ [return: MarshalAs(UnmanagedType.I1)]
+ public static extern bool native_screen_capturer_is_source_selection_supported();
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ [return: MarshalAs(UnmanagedType.I1)]
+ public static extern bool native_screen_capturer_is_supported();
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern void native_capture_source_selection_options_free(ref native_capture_source_selection_options_t value);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern void native_screen_capture_options_free(ref native_screen_capture_options_t value);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern void native_screen_capturer_capture(ulong source, native_screen_capture_options_t options, ScreenCapturerCaptureCallbackNativeCallback callback, IntPtr callback_user_data, ReleaseUserDataNativeCallback callback_release_user_data);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern void native_screen_capturer_select_source(native_capture_source_selection_options_t options, ScreenCapturerSelectSourceCallbackNativeCallback callback, IntPtr callback_user_data, ReleaseUserDataNativeCallback callback_release_user_data);
+}
+
diff --git a/bindings/csharp/src/CNativeAPI/generated/ScreenRecorder.cs b/bindings/csharp/src/CNativeAPI/generated/ScreenRecorder.cs
new file mode 100644
index 00000000..bed4454a
--- /dev/null
+++ b/bindings/csharp/src/CNativeAPI/generated/ScreenRecorder.cs
@@ -0,0 +1,96 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+#nullable enable
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace CNativeAPI;
+
+[StructLayout(LayoutKind.Sequential)]
+public struct native_screen_recording_options_t
+{
+ public native_screen_capture_options_t capture;
+ public double frame_rate;
+ public CULong video_bitrate;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct native_screen_recording_event_t
+{
+ public int type;
+ public DataUnion data;
+
+ [StructLayout(LayoutKind.Explicit)]
+ public struct DataUnion
+ {
+ [FieldOffset(0)] public CompletedData completed;
+ [FieldOffset(0)] public FailedData failed;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct CompletedData
+ {
+ public IntPtr file_path;
+ public double duration;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct FailedData
+ {
+ public IntPtr message;
+ }
+}
+
+[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+public delegate void ScreenRecordingEventNativeCallback(IntPtr evt, IntPtr userData);
+
+public static partial class Interop
+{
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ [return: MarshalAs(UnmanagedType.I1)]
+ public static extern bool native_screen_recorder_cancel(ulong self);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ [return: MarshalAs(UnmanagedType.I1)]
+ public static extern bool native_screen_recorder_is_active(ulong self);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ [return: MarshalAs(UnmanagedType.I1)]
+ public static extern bool native_screen_recorder_is_supported();
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ [return: MarshalAs(UnmanagedType.I1)]
+ public static extern bool native_screen_recorder_remove_listener(ulong self, ulong listenerId);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ [return: MarshalAs(UnmanagedType.I1)]
+ public static extern bool native_screen_recorder_start(ulong self, ulong source, [MarshalAs(UnmanagedType.LPUTF8Str)] string? filePath, native_screen_recording_options_t options);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ [return: MarshalAs(UnmanagedType.I1)]
+ public static extern bool native_screen_recorder_stop(ulong self);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr native_screen_recorder_get_file_path(ulong self);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern double native_screen_recorder_get_duration(ulong self);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern int native_screen_recorder_get_state(ulong self);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern ulong native_screen_recorder_add_listener(ulong self, ScreenRecordingEventNativeCallback callback, IntPtr userData, ReleaseUserDataNativeCallback releaseUserData);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern ulong native_screen_recorder_create();
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern void native_screen_recorder_free(ulong handle);
+
+ [DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
+ public static extern void native_screen_recording_options_free(ref native_screen_recording_options_t value);
+}
+
diff --git a/bindings/csharp/src/NativeAPI/CaptureSource.cs b/bindings/csharp/src/NativeAPI/CaptureSource.cs
new file mode 100644
index 00000000..aeafdbe8
--- /dev/null
+++ b/bindings/csharp/src/NativeAPI/CaptureSource.cs
@@ -0,0 +1,80 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+#nullable enable
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using CNativeAPI;
+
+namespace NativeAPI;
+
+public enum CaptureSourceType
+{
+ None = 0,
+ Display = 1,
+ Window = 2,
+ Unknown = 3,
+}
+
+/// Owned handle to a native CaptureSource.
+public sealed partial class CaptureSource : IDisposable
+{
+ public ulong NativeHandle { get; private set; }
+ private readonly bool _ownsHandle;
+
+ public CaptureSource(ulong nativeHandle, bool ownsHandle = true)
+ {
+ NativeHandle = nativeHandle;
+ _ownsHandle = ownsHandle;
+ }
+
+ ~CaptureSource() => ReleaseHandle();
+
+ public void Dispose()
+ {
+ ReleaseHandle();
+ GC.SuppressFinalize(this);
+ }
+
+ private void ReleaseHandle()
+ {
+ if (_ownsHandle && NativeHandle != 0)
+ {
+ Interop.native_capture_source_free(NativeHandle);
+ NativeHandle = 0;
+ }
+ }
+
+ public static CaptureSource? FromDisplay(Display? display)
+ {
+ var rawResult = Interop.native_capture_source_from_display(display?.NativeHandle ?? 0);
+ return rawResult == 0 ? null : new CaptureSource(rawResult);
+ }
+
+ public static CaptureSource? FromWindow(Window? window)
+ {
+ var rawResult = Interop.native_capture_source_from_window(window?.NativeHandle ?? 0);
+ return rawResult == 0 ? null : new CaptureSource(rawResult);
+ }
+
+ public CaptureSourceType Type
+ {
+ get
+ {
+ var rawResult = Interop.native_capture_source_get_type(NativeHandle);
+ return (CaptureSourceType)rawResult;
+ }
+ }
+
+ public string? Name
+ {
+ get
+ {
+ var rawResult = Interop.native_capture_source_get_name(NativeHandle);
+ return Interop.ConsumeString(rawResult);
+ }
+ }
+
+}
+
diff --git a/bindings/csharp/src/NativeAPI/ScreenCapturer.cs b/bindings/csharp/src/NativeAPI/ScreenCapturer.cs
new file mode 100644
index 00000000..f51ff888
--- /dev/null
+++ b/bindings/csharp/src/NativeAPI/ScreenCapturer.cs
@@ -0,0 +1,113 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+#nullable enable
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using CNativeAPI;
+
+namespace NativeAPI;
+
+public struct CaptureSourceSelectionOptions
+{
+ public bool AllowDisplays;
+ public bool AllowWindows;
+ public Window? ParentWindow;
+
+ public CaptureSourceSelectionOptions(bool allowDisplays, bool allowWindows, Window? parentWindow)
+ {
+ AllowDisplays = allowDisplays;
+ AllowWindows = allowWindows;
+ ParentWindow = parentWindow;
+ }
+
+ internal static CaptureSourceSelectionOptions FromRaw(in native_capture_source_selection_options_t raw)
+ {
+ return new CaptureSourceSelectionOptions(raw.allow_displays != 0, raw.allow_windows != 0, raw.parent_window == 0 ? null : new Window(Interop.native_handle_retain(raw.parent_window)));
+ }
+
+ internal native_capture_source_selection_options_t ToRaw()
+ {
+ var raw = new native_capture_source_selection_options_t();
+ raw.allow_displays = (byte)(AllowDisplays ? 1 : 0);
+ raw.allow_windows = (byte)(AllowWindows ? 1 : 0);
+ raw.parent_window = ParentWindow?.NativeHandle ?? 0;
+ return raw;
+ }
+
+ internal static void ReleaseRaw(ref native_capture_source_selection_options_t raw)
+ {
+ }
+}
+
+public struct ScreenCaptureOptions
+{
+ public bool IncludeCursor;
+ public bool CropEnabled;
+ public Rectangle Crop;
+
+ public ScreenCaptureOptions(bool includeCursor, bool cropEnabled, Rectangle crop)
+ {
+ IncludeCursor = includeCursor;
+ CropEnabled = cropEnabled;
+ Crop = crop;
+ }
+
+ internal static ScreenCaptureOptions FromRaw(in native_screen_capture_options_t raw)
+ {
+ return new ScreenCaptureOptions(raw.include_cursor != 0, raw.crop_enabled != 0, Rectangle.FromRaw(in raw.crop));
+ }
+
+ internal native_screen_capture_options_t ToRaw()
+ {
+ var raw = new native_screen_capture_options_t();
+ raw.include_cursor = (byte)(IncludeCursor ? 1 : 0);
+ raw.crop_enabled = (byte)(CropEnabled ? 1 : 0);
+ raw.crop = Crop.ToRaw();
+ return raw;
+ }
+
+ internal static void ReleaseRaw(ref native_screen_capture_options_t raw)
+ {
+ }
+}
+
+public static partial class ScreenCapturer
+{
+ public static bool IsSupported()
+ {
+ var rawResult = Interop.native_screen_capturer_is_supported();
+ return rawResult;
+ }
+
+ public static bool IsSourceSelectionSupported()
+ {
+ var rawResult = Interop.native_screen_capturer_is_source_selection_supported();
+ return rawResult;
+ }
+
+ public static bool IsDirectCaptureSupported(CaptureSourceType type)
+ {
+ var rawResult = Interop.native_screen_capturer_is_direct_capture_supported((int)type);
+ return rawResult;
+ }
+
+ public static void SelectSource(CaptureSourceSelectionOptions options, Action callback)
+ {
+ var rawOptions = options.ToRaw();
+ ScreenCapturerSelectSourceCallbackNativeCallback nativeCallback = (arg0, arg1, delivery, userData) => { try { if (!Interop.native_event_delivery_is_active(delivery)) return; callback(arg0, arg1 == 0 ? null : new CaptureSource(Interop.native_handle_retain(arg1))); } catch (Exception) { } finally { Interop.native_event_delivery_complete(delivery, true); } };
+ Interop.native_screen_capturer_select_source(rawOptions, nativeCallback, CallbackKeeper.Hold(nativeCallback), CallbackKeeper.Release);
+ CaptureSourceSelectionOptions.ReleaseRaw(ref rawOptions);
+ }
+
+ public static void Capture(CaptureSource? source, ScreenCaptureOptions options, Action callback)
+ {
+ var rawOptions = options.ToRaw();
+ ScreenCapturerCaptureCallbackNativeCallback nativeCallback = (arg0, arg1, delivery, userData) => { try { if (!Interop.native_event_delivery_is_active(delivery)) return; callback(arg0, arg1 == 0 ? null : new Image(Interop.native_handle_retain(arg1))); } catch (Exception) { } finally { Interop.native_event_delivery_complete(delivery, true); } };
+ Interop.native_screen_capturer_capture(source?.NativeHandle ?? 0, rawOptions, nativeCallback, CallbackKeeper.Hold(nativeCallback), CallbackKeeper.Release);
+ ScreenCaptureOptions.ReleaseRaw(ref rawOptions);
+ }
+
+}
+
diff --git a/bindings/csharp/src/NativeAPI/ScreenRecorder.cs b/bindings/csharp/src/NativeAPI/ScreenRecorder.cs
new file mode 100644
index 00000000..8b8ee5c4
--- /dev/null
+++ b/bindings/csharp/src/NativeAPI/ScreenRecorder.cs
@@ -0,0 +1,205 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+#nullable enable
+
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using CNativeAPI;
+
+namespace NativeAPI;
+
+public enum ScreenRecordingState
+{
+ Idle = 0,
+ Starting = 1,
+ Recording = 2,
+ Stopping = 3,
+ Completed = 4,
+ Cancelled = 5,
+ Failed = 6,
+}
+
+public struct ScreenRecordingOptions
+{
+ public ScreenCaptureOptions Capture;
+ public double FrameRate;
+ public ulong VideoBitrate;
+
+ public ScreenRecordingOptions(ScreenCaptureOptions capture, double frameRate, ulong videoBitrate)
+ {
+ Capture = capture;
+ FrameRate = frameRate;
+ VideoBitrate = videoBitrate;
+ }
+
+ internal static ScreenRecordingOptions FromRaw(in native_screen_recording_options_t raw)
+ {
+ return new ScreenRecordingOptions(ScreenCaptureOptions.FromRaw(in raw.capture), raw.frame_rate, (ulong)raw.video_bitrate.Value);
+ }
+
+ internal native_screen_recording_options_t ToRaw()
+ {
+ var raw = new native_screen_recording_options_t();
+ raw.capture = Capture.ToRaw();
+ raw.frame_rate = FrameRate;
+ raw.video_bitrate = new CULong(checked((nuint)VideoBitrate));
+ return raw;
+ }
+
+ internal static void ReleaseRaw(ref native_screen_recording_options_t raw)
+ {
+ }
+}
+
+/// One ScreenRecordingEvent, in its concrete form.
+public abstract record ScreenRecordingEvent
+{
+ private ScreenRecordingEvent() { }
+
+ public sealed record Started : ScreenRecordingEvent;
+ public sealed record Completed(string? FilePath, double Duration) : ScreenRecordingEvent;
+ public sealed record Cancelled : ScreenRecordingEvent;
+ public sealed record Failed(string? Message) : ScreenRecordingEvent;
+
+ internal static ScreenRecordingEvent? FromRaw(in native_screen_recording_event_t raw)
+ {
+ switch (raw.type)
+ {
+ case 0: return new Started();
+ case 1: return new Completed(Marshal.PtrToStringUTF8(raw.data.completed.file_path), raw.data.completed.duration);
+ case 2: return new Cancelled();
+ case 3: return new Failed(Marshal.PtrToStringUTF8(raw.data.failed.message));
+ default: return null;
+ }
+ }
+}
+
+/// Owned handle to a native ScreenRecorder.
+public sealed partial class ScreenRecorder : IDisposable
+{
+ public ulong NativeHandle { get; private set; }
+ private readonly bool _ownsHandle;
+
+ public ScreenRecorder(ulong nativeHandle, bool ownsHandle = true)
+ {
+ NativeHandle = nativeHandle;
+ _ownsHandle = ownsHandle;
+ }
+
+ ~ScreenRecorder() => ReleaseHandle();
+
+ public void Dispose()
+ {
+ ReleaseHandle();
+ GC.SuppressFinalize(this);
+ }
+
+ private void ReleaseHandle()
+ {
+ if (_ownsHandle && NativeHandle != 0)
+ {
+ Interop.native_screen_recorder_free(NativeHandle);
+ NativeHandle = 0;
+ }
+ }
+
+ /// Creates a new ScreenRecorder; returns null if the native side failed.
+ public static ScreenRecorder? Create()
+ {
+ var handle = Interop.native_screen_recorder_create();
+ return handle == 0 ? null : new ScreenRecorder(handle);
+ }
+
+ public static bool IsSupported()
+ {
+ var rawResult = Interop.native_screen_recorder_is_supported();
+ return rawResult;
+ }
+
+ public bool Start(CaptureSource? source, string filePath, ScreenRecordingOptions options)
+ {
+ var rawOptions = options.ToRaw();
+ var rawResult = Interop.native_screen_recorder_start(NativeHandle, source?.NativeHandle ?? 0, filePath, rawOptions);
+ ScreenRecordingOptions.ReleaseRaw(ref rawOptions);
+ return rawResult;
+ }
+
+ public bool Stop()
+ {
+ var rawResult = Interop.native_screen_recorder_stop(NativeHandle);
+ return rawResult;
+ }
+
+ public bool Cancel()
+ {
+ var rawResult = Interop.native_screen_recorder_cancel(NativeHandle);
+ return rawResult;
+ }
+
+ public ScreenRecordingState State
+ {
+ get
+ {
+ var rawResult = Interop.native_screen_recorder_get_state(NativeHandle);
+ return (ScreenRecordingState)rawResult;
+ }
+ }
+
+ public bool IsActive
+ {
+ get
+ {
+ var rawResult = Interop.native_screen_recorder_is_active(NativeHandle);
+ return rawResult;
+ }
+ }
+
+ public double Duration
+ {
+ get
+ {
+ var rawResult = Interop.native_screen_recorder_get_duration(NativeHandle);
+ return rawResult;
+ }
+ }
+
+ public string? FilePath
+ {
+ get
+ {
+ var rawResult = Interop.native_screen_recorder_get_file_path(NativeHandle);
+ return Interop.ConsumeString(rawResult);
+ }
+ }
+
+ /// Registers for every ScreenRecordingEvent this ScreenRecorder emits.
+ ///
+ /// The delegate is kept alive until the listener is removed or its emitter
+ /// destroyed; the core releases it then.
+ ///
+ public ulong AddListener(Action callback)
+ {
+ ScreenRecordingEventNativeCallback native = (evt, userData) =>
+ {
+ if (evt == IntPtr.Zero)
+ {
+ return;
+ }
+ var value = ScreenRecordingEvent.FromRaw(Marshal.PtrToStructure(evt));
+ if (value is not null)
+ {
+ callback(value);
+ }
+ };
+ return Interop.native_screen_recorder_add_listener(NativeHandle, native, CallbackKeeper.Hold(native), CallbackKeeper.Release);
+ }
+
+ /// Unregisters a listener. Returns false if unknown.
+ public bool RemoveListener(ulong listenerId)
+ {
+ return Interop.native_screen_recorder_remove_listener(NativeHandle, listenerId);
+ }
+
+}
+
diff --git a/bindings/dart/cnativeapi/ffigen.yaml b/bindings/dart/cnativeapi/ffigen.yaml
index a8c55ff1..4a4bbd04 100644
--- a/bindings/dart/cnativeapi/ffigen.yaml
+++ b/bindings/dart/cnativeapi/ffigen.yaml
@@ -13,6 +13,7 @@ headers:
- "../../../core/src/capi/accessibility_manager_c.h"
- "../../../core/src/capi/app_info_c.h"
- "../../../core/src/capi/application_c.h"
+ - "../../../core/src/capi/capture_source_c.h"
- "../../../core/src/capi/clipboard_c.h"
- "../../../core/src/capi/color_c.h"
- "../../../core/src/capi/common_c.h"
@@ -36,6 +37,8 @@ headers:
- "../../../core/src/capi/positioning_strategy_c.h"
- "../../../core/src/capi/preferences_c.h"
- "../../../core/src/capi/protocol_handler_c.h"
+ - "../../../core/src/capi/screen_capturer_c.h"
+ - "../../../core/src/capi/screen_recorder_c.h"
- "../../../core/src/capi/secure_storage_c.h"
- "../../../core/src/capi/shortcut_c.h"
- "../../../core/src/capi/shortcut_manager_c.h"
@@ -55,6 +58,7 @@ headers:
- "../../../core/src/capi/accessibility_manager_c.h"
- "../../../core/src/capi/app_info_c.h"
- "../../../core/src/capi/application_c.h"
+ - "../../../core/src/capi/capture_source_c.h"
- "../../../core/src/capi/clipboard_c.h"
- "../../../core/src/capi/color_c.h"
- "../../../core/src/capi/common_c.h"
@@ -78,6 +82,8 @@ headers:
- "../../../core/src/capi/positioning_strategy_c.h"
- "../../../core/src/capi/preferences_c.h"
- "../../../core/src/capi/protocol_handler_c.h"
+ - "../../../core/src/capi/screen_capturer_c.h"
+ - "../../../core/src/capi/screen_recorder_c.h"
- "../../../core/src/capi/secure_storage_c.h"
- "../../../core/src/capi/shortcut_c.h"
- "../../../core/src/capi/shortcut_manager_c.h"
diff --git a/bindings/dart/cnativeapi/hook/build.dart b/bindings/dart/cnativeapi/hook/build.dart
index 5177b311..ee5cc392 100644
--- a/bindings/dart/cnativeapi/hook/build.dart
+++ b/bindings/dart/cnativeapi/hook/build.dart
@@ -76,6 +76,7 @@ void main(List args) async {
// normal link dyld refuses to load the whole library on macOS 12,
// even when the app never calls launch-at-login.
flags.addAll(['-weak_framework', 'ServiceManagement']);
+ flags.addAll(['-weak_framework', 'ScreenCaptureKit']);
frameworks = [
'Cocoa',
'QuartzCore',
@@ -83,6 +84,10 @@ void main(List args) async {
'IOKit',
'CoreGraphics',
'ApplicationServices',
+ 'AVFoundation',
+ 'CoreMedia',
+ 'CoreVideo',
+ 'VideoToolbox',
];
case OS.iOS:
flags.addAll(_objectiveCpp);
@@ -133,6 +138,14 @@ void main(List args) async {
'advapi32',
'version',
'gdi32',
+ 'd3d11',
+ 'dxgi',
+ 'windowsapp',
+ 'runtimeobject',
+ 'mfplat',
+ 'mfreadwrite',
+ 'mfuuid',
+ 'windowscodecs',
]);
if (winui3) {
winui3Paths = await _prepareWinUI3(input, output, core);
diff --git a/bindings/dart/cnativeapi/lib/src/bindings_generated.dart b/bindings/dart/cnativeapi/lib/src/bindings_generated.dart
index 8968d666..eea45432 100644
--- a/bindings/dart/cnativeapi/lib/src/bindings_generated.dart
+++ b/bindings/dart/cnativeapi/lib/src/bindings_generated.dart
@@ -219,6 +219,46 @@ external void native_button_set_font_weight(int button, int weight);
@ffi.Native)>()
external void native_button_set_text(int button, ffi.Pointer text);
+/// Releases the caller's reference. Safe to call with an invalid or
+/// already-released handle.
+@ffi.Native()
+external void native_capture_source_free(int capture_source);
+
+/// Caller owns the returned handle; release it with native_capture_source_free().
+@ffi.Native()
+external int native_capture_source_from_display(int display);
+
+/// Caller owns the returned handle; release it with native_capture_source_free().
+@ffi.Native()
+external int native_capture_source_from_window(int window);
+
+/// Caller owns the returned string; free it with free_c_str().
+@ffi.Native Function(native_capture_source_t)>()
+external ffi.Pointer native_capture_source_get_name(
+ int capture_source,
+);
+
+@ffi.Native(
+ symbol: 'native_capture_source_get_type',
+)
+external int _native_capture_source_get_type(int capture_source);
+
+native_capture_source_type_t native_capture_source_get_type(
+ Dartnative_capture_source_t capture_source,
+) {
+ return native_capture_source_type_t.fromValue(
+ _native_capture_source_get_type(capture_source),
+ );
+}
+
+/// Frees everything the struct owns.
+@ffi.Native<
+ ffi.Void Function(ffi.Pointer)
+>()
+external void native_capture_source_selection_options_free(
+ ffi.Pointer value,
+);
+
/// Registers @p callback for every ClipboardEvent this Clipboard emits.
/// @return the listener id, or NATIVE_INVALID_LISTENER_ID on failure.
@ffi.Native<
@@ -415,6 +455,10 @@ external bool native_clipboard_write_rtf(ffi.Pointer rtf);
@ffi.Native)>()
external bool native_clipboard_write_text(ffi.Pointer text);
+/// Frees everything the struct owns.
+@ffi.Native)>()
+external void native_color_free(ffi.Pointer value);
+
@ffi.Native)>()
external native_color_t native_color_from_hex(ffi.Pointer hex);
@@ -695,7 +739,7 @@ external void native_drag_source_set_text(
ffi.Pointer text,
);
-@ffi.Native()
+@ffi.Native()
external bool native_drag_source_start_dragging(int drag_source, int window);
/// Registers @p callback for every DropTargetEvent this DropTarget emits.
@@ -734,7 +778,7 @@ external int native_drop_target_add_listener_async(
);
/// Creates a DropTarget instance; release it with native_drop_target_free().
-@ffi.Native()
+@ffi.Native()
external int native_drop_target_create(int window);
/// Releases the caller's reference. Safe to call with an invalid or
@@ -789,6 +833,10 @@ void native_drop_target_set_drop_operation(
@ffi.Native()
external native_edge_insets_t native_edge_insets_all(double value);
+/// Frees everything the struct owns.
+@ffi.Native)>()
+external void native_edge_insets_free(ffi.Pointer value);
+
@ffi.Native()
external native_edge_insets_t native_edge_insets_symmetric(
double vertical,
@@ -918,7 +966,7 @@ void native_file_dialog_set_modality(
return _native_file_dialog_set_modality(file_dialog, modality.value);
}
-@ffi.Native()
+@ffi.Native()
external bool native_file_dialog_set_parent_window(int file_dialog, int window);
@ffi.Native)>()
@@ -1704,7 +1752,7 @@ void native_message_dialog_set_modality(
return _native_message_dialog_set_modality(message_dialog, modality.value);
}
-@ffi.Native()
+@ffi.Native()
external bool native_message_dialog_set_parent_window(
int message_dialog,
int window,
@@ -1788,6 +1836,10 @@ external bool native_notification_manager_show(
@ffi.Native()
external void native_notification_manager_shutdown();
+/// Frees everything the struct owns.
+@ffi.Native)>()
+external void native_point_free(ffi.Pointer value);
+
/// Caller owns the returned handle; release it with native_positioning_strategy_free().
@ffi.Native()
external int native_positioning_strategy_absolute(native_point_t point);
@@ -1966,6 +2018,171 @@ external bool native_protocol_handler_register(ffi.Pointer scheme);
@ffi.Native()
external bool native_protocol_handler_remove_listener(int listener_id);
+/// Frees everything the struct owns.
+@ffi.Native)>()
+external void native_rectangle_free(ffi.Pointer value);
+
+/// Frees everything the struct owns.
+@ffi.Native)>()
+external void native_screen_capture_options_free(
+ ffi.Pointer value,
+);
+
+@ffi.Native<
+ ffi.Void Function(
+ native_capture_source_t$1,
+ native_screen_capture_options_t,
+ native_screen_capturer_capture_callback_t,
+ ffi.Pointer,
+ native_release_user_data_t,
+ )
+>()
+external void native_screen_capturer_capture(
+ int source,
+ native_screen_capture_options_t options,
+ native_screen_capturer_capture_callback_t callback,
+ ffi.Pointer callback_user_data,
+ native_release_user_data_t callback_release_user_data,
+);
+
+@ffi.Native(
+ symbol: 'native_screen_capturer_is_direct_capture_supported',
+)
+external bool _native_screen_capturer_is_direct_capture_supported(int type);
+
+bool native_screen_capturer_is_direct_capture_supported(
+ native_capture_source_type_t type,
+) {
+ return _native_screen_capturer_is_direct_capture_supported(type.value);
+}
+
+@ffi.Native()
+external bool native_screen_capturer_is_source_selection_supported();
+
+@ffi.Native()
+external bool native_screen_capturer_is_supported();
+
+@ffi.Native<
+ ffi.Void Function(
+ native_capture_source_selection_options_t,
+ native_screen_capturer_select_source_callback_t,
+ ffi.Pointer,
+ native_release_user_data_t,
+ )
+>()
+external void native_screen_capturer_select_source(
+ native_capture_source_selection_options_t options,
+ native_screen_capturer_select_source_callback_t callback,
+ ffi.Pointer callback_user_data,
+ native_release_user_data_t callback_release_user_data,
+);
+
+/// Registers @p callback for every ScreenRecordingEvent this ScreenRecorder emits.
+/// @return the listener id, or NATIVE_INVALID_LISTENER_ID on failure.
+@ffi.Native<
+ native_listener_id_t Function(
+ native_screen_recorder_t,
+ native_screen_recording_event_callback_t,
+ ffi.Pointer,
+ native_release_user_data_t,
+ )
+>()
+external int native_screen_recorder_add_listener(
+ int screen_recorder,
+ native_screen_recording_event_callback_t callback,
+ ffi.Pointer user_data,
+ native_release_user_data_t release_user_data,
+);
+
+/// Registers an asynchronous callback. Its event, borrowed handles and user_data
+/// remain valid until event_delivery_complete is called, including after removal.
+/// Every delivered payload must be acknowledged. Check is_active before invoking a queued callback.
+@ffi.Native<
+ native_listener_id_t Function(
+ native_screen_recorder_t,
+ native_screen_recording_event_callback_t_async,
+ ffi.Pointer,
+ native_release_user_data_t,
+ )
+>()
+external int native_screen_recorder_add_listener_async(
+ int screen_recorder,
+ native_screen_recording_event_callback_t_async callback,
+ ffi.Pointer user_data,
+ native_release_user_data_t release_user_data,
+);
+
+@ffi.Native()
+external bool native_screen_recorder_cancel(int screen_recorder);
+
+/// Creates a ScreenRecorder instance; release it with native_screen_recorder_free().
+@ffi.Native()
+external int native_screen_recorder_create();
+
+/// Releases the caller's reference. Safe to call with an invalid or
+/// already-released handle.
+@ffi.Native()
+external void native_screen_recorder_free(int screen_recorder);
+
+@ffi.Native()
+external double native_screen_recorder_get_duration(int screen_recorder);
+
+/// Caller owns the returned string; free it with free_c_str().
+@ffi.Native Function(native_screen_recorder_t)>()
+external ffi.Pointer native_screen_recorder_get_file_path(
+ int screen_recorder,
+);
+
+@ffi.Native(
+ symbol: 'native_screen_recorder_get_state',
+)
+external int _native_screen_recorder_get_state(int screen_recorder);
+
+native_screen_recording_state_t native_screen_recorder_get_state(
+ Dartnative_screen_recorder_t screen_recorder,
+) {
+ return native_screen_recording_state_t.fromValue(
+ _native_screen_recorder_get_state(screen_recorder),
+ );
+}
+
+@ffi.Native()
+external bool native_screen_recorder_is_active(int screen_recorder);
+
+@ffi.Native()
+external bool native_screen_recorder_is_supported();
+
+/// Unregisters a listener. Returns false if unknown.
+@ffi.Native()
+external bool native_screen_recorder_remove_listener(
+ int screen_recorder,
+ int listener_id,
+);
+
+@ffi.Native<
+ ffi.Bool Function(
+ native_screen_recorder_t,
+ native_capture_source_t$2,
+ ffi.Pointer,
+ native_screen_recording_options_t,
+ )
+>()
+external bool native_screen_recorder_start(
+ int screen_recorder,
+ int source,
+ ffi.Pointer file_path,
+ native_screen_recording_options_t options,
+);
+
+@ffi.Native()
+external bool native_screen_recorder_stop(int screen_recorder);
+
+/// Frees everything the struct owns.
+@ffi.Native)>()
+external void native_screen_recording_options_free(
+ ffi.Pointer value,
+);
+
@ffi.Native()
external bool native_secure_storage_clear(int secure_storage);
@@ -2300,6 +2517,10 @@ external void native_shortcut_set_description(
@ffi.Native()
external void native_shortcut_set_enabled(int shortcut, bool enabled);
+/// Frees everything the struct owns.
+@ffi.Native)>()
+external void native_size_free(ffi.Pointer value);
+
/// Free a string list allocated by to_c_string_list
/// @param list The list to free (can be nullptr)
@ffi.Native)>()
@@ -2310,6 +2531,12 @@ external void native_string_list_free(ffi.Pointer list);
@ffi.Native)>()
external void native_string_map_free(ffi.Pointer map);
+/// Frees everything the struct owns.
+@ffi.Native)>()
+external void native_taskbar_flash_options_free(
+ ffi.Pointer value,
+);
+
/// Registers @p callback for every TaskbarEvent this TaskbarThumbnailButton emits.
/// @return the listener id, or NATIVE_INVALID_LISTENER_ID on failure.
@ffi.Native<
@@ -2612,6 +2839,10 @@ external void native_text_field_set_text_color(
native_color_t color,
);
+/// Frees everything the struct owns.
+@ffi.Native)>()
+external void native_text_range_free(ffi.Pointer value);
+
/// Registers @p callback for every TrayIconEvent this TrayIcon emits.
/// @return the listener id, or NATIVE_INVALID_LISTENER_ID on failure.
@ffi.Native<
@@ -2694,7 +2925,7 @@ native_context_menu_trigger_t native_tray_icon_get_context_menu_trigger(
}
/// Caller owns the returned handle; release it with native_image_free().
-@ffi.Native()
+@ffi.Native()
external int native_tray_icon_get_icon(int tray_icon);
@ffi.Native(
@@ -2780,7 +3011,7 @@ void native_tray_icon_set_context_menu_trigger(
return _native_tray_icon_set_context_menu_trigger(tray_icon, trigger.value);
}
-@ffi.Native()
+@ffi.Native()
external void native_tray_icon_set_icon(int tray_icon, int image);
@ffi.Native(
@@ -3276,7 +3507,7 @@ external bool native_window_drag_session_remove_listener(
@ffi.Native<
ffi.Bool Function(
native_window_drag_session_t,
- native_window_t$5,
+ native_window_t$7,
native_point_t,
)
>()
@@ -3619,18 +3850,18 @@ external bool native_window_manager_call_original_hide(int id);
external bool native_window_manager_call_original_show(int id);
/// Caller owns the returned handle; release it with native_window_free().
-@ffi.Native()
+@ffi.Native()
external int native_window_manager_get(int id);
@ffi.Native()
external native_window_list_t native_window_manager_get_all();
/// Caller owns the returned handle; release it with native_window_free().
-@ffi.Native()
+@ffi.Native()
external int native_window_manager_get_current();
/// Caller owns the returned handle; release it with native_window_free().
-@ffi.Native()
+@ffi.Native()
external int native_window_manager_get_window_at_point(
native_point_t point,
int excluded_window_id,
@@ -4224,6 +4455,8 @@ external void native_window_unmaximize(int window);
const int NATIVE_INVALID_BUTTON = 0;
+const int NATIVE_INVALID_CAPTURE_SOURCE = 0;
+
const int NATIVE_INVALID_DISPLAY = 0;
const int NATIVE_INVALID_DRAG_SOURCE = 0;
@@ -4258,6 +4491,8 @@ const int NATIVE_INVALID_POSITIONING_STRATEGY = 0;
const int NATIVE_INVALID_PREFERENCES = 0;
+const int NATIVE_INVALID_SCREEN_RECORDER = 0;
+
const int NATIVE_INVALID_SECURE_STORAGE = 0;
const int NATIVE_INVALID_SHORTCUT = 0;
@@ -4339,42 +4574,46 @@ final class UnnamedStruct$13 extends ffi.Struct {
}
final class UnnamedStruct$14 extends ffi.Struct {
- external ffi.Pointer error_message;
+ external ffi.Pointer file_path;
+
+ @ffi.Double()
+ external double duration;
static ffi.Pointer $allocate(
ffi.Allocator $allocator, {
- required ffi.Pointer error_message,
- }) => $allocator()..ref.error_message = error_message;
+ required ffi.Pointer file_path,
+ required double duration,
+ }) => $allocator()
+ ..ref.file_path = file_path
+ ..ref.duration = duration;
}
final class UnnamedStruct$15 extends ffi.Struct {
- @native_taskbar_thumbnail_button_id_t()
- external int button_id;
+ external ffi.Pointer message;
static ffi.Pointer $allocate(
ffi.Allocator $allocator, {
- required int button_id,
- }) => $allocator()..ref.button_id = button_id;
+ required ffi.Pointer message,
+ }) => $allocator()..ref.message = message;
}
final class UnnamedStruct$16 extends ffi.Struct {
- @native_tray_icon_id_t()
- external int tray_icon_id;
+ external ffi.Pointer error_message;
static ffi.Pointer $allocate(
ffi.Allocator $allocator, {
- required int tray_icon_id,
- }) => $allocator()..ref.tray_icon_id = tray_icon_id;
+ required ffi.Pointer error_message,
+ }) => $allocator()..ref.error_message = error_message;
}
final class UnnamedStruct$17 extends ffi.Struct {
- @native_tray_icon_id_t()
- external int tray_icon_id;
+ @native_taskbar_thumbnail_button_id_t()
+ external int button_id;
static ffi.Pointer $allocate(
ffi.Allocator $allocator, {
- required int tray_icon_id,
- }) => $allocator()..ref.tray_icon_id = tray_icon_id;
+ required int button_id,
+ }) => $allocator()..ref.button_id = button_id;
}
final class UnnamedStruct$18 extends ffi.Struct {
@@ -4388,12 +4627,13 @@ final class UnnamedStruct$18 extends ffi.Struct {
}
final class UnnamedStruct$19 extends ffi.Struct {
- external ffi.Pointer text;
+ @native_tray_icon_id_t()
+ external int tray_icon_id;
static ffi.Pointer $allocate(
ffi.Allocator $allocator, {
- required ffi.Pointer text,
- }) => $allocator()..ref.text = text;
+ required int tray_icon_id,
+ }) => $allocator()..ref.tray_icon_id = tray_icon_id;
}
final class UnnamedStruct$2 extends ffi.Struct {
@@ -4411,11 +4651,22 @@ final class UnnamedStruct$2 extends ffi.Struct {
}
final class UnnamedStruct$20 extends ffi.Struct {
- external native_size_t new_size;
+ @native_tray_icon_id_t()
+ external int tray_icon_id;
+
+ static ffi.Pointer $allocate(
+ ffi.Allocator $allocator, {
+ required int tray_icon_id,
+ }) => $allocator()..ref.tray_icon_id = tray_icon_id;
}
final class UnnamedStruct$21 extends ffi.Struct {
- external native_point_t new_position;
+ external ffi.Pointer text;
+
+ static ffi.Pointer $allocate(
+ ffi.Allocator $allocator, {
+ required ffi.Pointer text,
+ }) => $allocator()..ref.text = text;
}
final class UnnamedStruct$22 extends ffi.Struct {
@@ -4423,16 +4674,24 @@ final class UnnamedStruct$22 extends ffi.Struct {
}
final class UnnamedStruct$23 extends ffi.Struct {
+ external native_point_t new_position;
+}
+
+final class UnnamedStruct$24 extends ffi.Struct {
+ external native_size_t new_size;
+}
+
+final class UnnamedStruct$25 extends ffi.Struct {
@native_event_request_t()
external int request;
- static ffi.Pointer $allocate(
+ static ffi.Pointer $allocate(
ffi.Allocator $allocator, {
required int request,
- }) => $allocator()..ref.request = request;
+ }) => $allocator()..ref.request = request;
}
-final class UnnamedStruct$24 extends ffi.Struct {
+final class UnnamedStruct$26 extends ffi.Struct {
@ffi.UnsignedInt()
external int propertyAsInt;
@@ -4440,13 +4699,13 @@ final class UnnamedStruct$24 extends ffi.Struct {
native_window_property_t.fromValue(propertyAsInt);
set property(native_window_property_t value) => propertyAsInt = value.value;
- static ffi.Pointer $allocate(
+ static ffi.Pointer $allocate(
ffi.Allocator $allocator, {
required native_window_property_t property,
- }) => $allocator()..ref.property = property;
+ }) => $allocator()..ref.property = property;
}
-final class UnnamedStruct$25 extends ffi.Struct {
+final class UnnamedStruct$27 extends ffi.Struct {
@ffi.UnsignedInt()
external int occlusion_stateAsInt;
@@ -4455,13 +4714,13 @@ final class UnnamedStruct$25 extends ffi.Struct {
set occlusion_state(native_window_occlusion_state_t value) =>
occlusion_stateAsInt = value.value;
- static ffi.Pointer $allocate(
+ static ffi.Pointer $allocate(
ffi.Allocator $allocator, {
required native_window_occlusion_state_t occlusion_state,
- }) => $allocator()..ref.occlusion_state = occlusion_state;
+ }) => $allocator()..ref.occlusion_state = occlusion_state;
}
-final class UnnamedStruct$26 extends ffi.Struct {
+final class UnnamedStruct$28 extends ffi.Struct {
@ffi.UnsignedInt()
external int sideAsInt;
@@ -4469,20 +4728,20 @@ final class UnnamedStruct$26 extends ffi.Struct {
native_window_dock_side_t.fromValue(sideAsInt);
set side(native_window_dock_side_t value) => sideAsInt = value.value;
- static ffi.Pointer $allocate(
+ static ffi.Pointer $allocate(
ffi.Allocator $allocator, {
required native_window_dock_side_t side,
- }) => $allocator()..ref.side = side;
+ }) => $allocator()..ref.side = side;
}
-final class UnnamedStruct$27 extends ffi.Struct {
+final class UnnamedStruct$29 extends ffi.Struct {
@ffi.Double()
external double scale_factor;
- static ffi.Pointer $allocate(
+ static ffi.Pointer $allocate(
ffi.Allocator $allocator, {
required double scale_factor,
- }) => $allocator()..ref.scale_factor = scale_factor;
+ }) => $allocator()..ref.scale_factor = scale_factor;
}
final class UnnamedStruct$3 extends ffi.Struct {
@@ -4566,25 +4825,33 @@ final class UnnamedUnion$1 extends ffi.Union {
}
final class UnnamedUnion$10 extends ffi.Union {
- external UnnamedStruct$19 text_field_changed;
+ external UnnamedStruct$18 clicked;
+
+ external UnnamedStruct$19 right_clicked;
- external UnnamedStruct$20 resized;
+ external UnnamedStruct$20 double_clicked;
}
final class UnnamedUnion$11 extends ffi.Union {
- external UnnamedStruct$21 moved;
+ external UnnamedStruct$21 text_field_changed;
external UnnamedStruct$22 resized;
+}
+
+final class UnnamedUnion$12 extends ffi.Union {
+ external UnnamedStruct$23 moved;
- external UnnamedStruct$23 close_requested;
+ external UnnamedStruct$24 resized;
- external UnnamedStruct$24 property_changed;
+ external UnnamedStruct$25 close_requested;
- external UnnamedStruct$25 occlusion_changed;
+ external UnnamedStruct$26 property_changed;
- external UnnamedStruct$26 docked;
+ external UnnamedStruct$27 occlusion_changed;
- external UnnamedStruct$27 scale_factor_changed;
+ external UnnamedStruct$28 docked;
+
+ external UnnamedStruct$29 scale_factor_changed;
}
final class UnnamedUnion$2 extends ffi.Union {
@@ -4616,19 +4883,17 @@ final class UnnamedUnion$6 extends ffi.Union {
}
final class UnnamedUnion$7 extends ffi.Union {
- external UnnamedStruct$14 registration_failed;
+ external UnnamedStruct$14 completed;
+
+ external UnnamedStruct$15 failed;
}
final class UnnamedUnion$8 extends ffi.Union {
- external UnnamedStruct$15 thumbnail_button_clicked;
+ external UnnamedStruct$16 registration_failed;
}
final class UnnamedUnion$9 extends ffi.Union {
- external UnnamedStruct$16 clicked;
-
- external UnnamedStruct$17 right_clicked;
-
- external UnnamedStruct$18 double_clicked;
+ external UnnamedStruct$17 thumbnail_button_clicked;
}
typedef native_application_event_callback_t =
@@ -4729,6 +4994,60 @@ enum native_brightness_t {
typedef native_button_t = ffi.Uint64;
typedef Dartnative_button_t = int;
+final class native_capture_source_selection_options_t extends ffi.Struct {
+ @ffi.Bool()
+ external bool allow_displays;
+
+ @ffi.Bool()
+ external bool allow_windows;
+
+ @native_window_t$2()
+ external int parent_window;
+
+ static ffi.Pointer $allocate(
+ ffi.Allocator $allocator, {
+ required bool allow_displays,
+ required bool allow_windows,
+ required int parent_window,
+ }) => $allocator()
+ ..ref.allow_displays = allow_displays
+ ..ref.allow_windows = allow_windows
+ ..ref.parent_window = parent_window;
+}
+
+/// Opaque CaptureSource handle.
+///
+/// A generational index into the library's handle table, NOT a pointer:
+/// never dereference it, and compare it against NATIVE_INVALID_CAPTURE_SOURCE rather than NULL.
+/// Releasing a handle invalidates it; later calls fail safely instead of
+/// touching freed memory.
+typedef native_capture_source_t = ffi.Uint64;
+typedef Dartnative_capture_source_t = int;
+typedef native_capture_source_t$1 = ffi.Uint64;
+typedef Dartnative_capture_source_t$1 = int;
+typedef native_capture_source_t$2 = ffi.Uint64;
+typedef Dartnative_capture_source_t$2 = int;
+
+enum native_capture_source_type_t {
+ NATIVE_CAPTURE_SOURCE_TYPE_NONE(0),
+ NATIVE_CAPTURE_SOURCE_TYPE_DISPLAY(1),
+ NATIVE_CAPTURE_SOURCE_TYPE_WINDOW(2),
+ NATIVE_CAPTURE_SOURCE_TYPE_UNKNOWN(3);
+
+ final int value;
+ const native_capture_source_type_t(this.value);
+
+ static native_capture_source_type_t fromValue(int value) => switch (value) {
+ 0 => NATIVE_CAPTURE_SOURCE_TYPE_NONE,
+ 1 => NATIVE_CAPTURE_SOURCE_TYPE_DISPLAY,
+ 2 => NATIVE_CAPTURE_SOURCE_TYPE_WINDOW,
+ 3 => NATIVE_CAPTURE_SOURCE_TYPE_UNKNOWN,
+ _ => throw ArgumentError(
+ 'Unknown value for native_capture_source_type_t: $value',
+ ),
+ };
+}
+
final class native_clipboard_data_t extends ffi.Struct {
external ffi.Pointer text;
@@ -5107,6 +5426,8 @@ typedef native_display_t = ffi.Uint64;
typedef Dartnative_display_t = int;
typedef native_display_t$1 = ffi.Uint64;
typedef Dartnative_display_t$1 = int;
+typedef native_display_t$2 = ffi.Uint64;
+typedef Dartnative_display_t$2 = int;
enum native_drag_operation_t {
NATIVE_DRAG_OPERATION_NONE(0),
@@ -5398,6 +5719,8 @@ typedef native_image_t$5 = ffi.Uint64;
typedef Dartnative_image_t$5 = int;
typedef native_image_t$6 = ffi.Uint64;
typedef Dartnative_image_t$6 = int;
+typedef native_image_t$7 = ffi.Uint64;
+typedef Dartnative_image_t$7 = int;
/// Opaque ImageView handle.
///
@@ -6017,6 +6340,168 @@ enum native_resize_edge_t {
};
}
+final class native_screen_capture_options_t extends ffi.Struct {
+ @ffi.Bool()
+ external bool include_cursor;
+
+ @ffi.Bool()
+ external bool crop_enabled;
+
+ external native_rectangle_t crop;
+}
+
+/// Arguments are borrowed until event_delivery_complete(delivery, ...), which is required exactly once.
+typedef native_screen_capturer_capture_callback_t =
+ ffi.Pointer<
+ ffi.NativeFunction
+ >;
+typedef native_screen_capturer_capture_callback_tFunction = ffi.Void Function(
+ ffi.Bool arg0,
+ native_image_t$3 arg1,
+ native_event_delivery_t delivery,
+ ffi.Pointer user_data,
+);
+typedef Dartnative_screen_capturer_capture_callback_tFunction = void Function(
+ bool arg0,
+ Dartnative_image_t$3 arg1,
+ Dartnative_event_delivery_t delivery,
+ ffi.Pointer user_data,
+);
+
+/// Arguments are borrowed until event_delivery_complete(delivery, ...), which is required exactly once.
+typedef native_screen_capturer_select_source_callback_t =
+ ffi.Pointer<
+ ffi.NativeFunction<
+ native_screen_capturer_select_source_callback_tFunction
+ >
+ >;
+typedef native_screen_capturer_select_source_callback_tFunction =
+ ffi.Void Function(
+ ffi.Bool arg0,
+ native_capture_source_t$1 arg1,
+ native_event_delivery_t delivery,
+ ffi.Pointer user_data,
+ );
+typedef Dartnative_screen_capturer_select_source_callback_tFunction =
+ void Function(
+ bool arg0,
+ Dartnative_capture_source_t$1 arg1,
+ Dartnative_event_delivery_t delivery,
+ ffi.Pointer user_data,
+ );
+
+/// Opaque ScreenRecorder handle.
+///
+/// A generational index into the library's handle table, NOT a pointer:
+/// never dereference it, and compare it against NATIVE_INVALID_SCREEN_RECORDER rather than NULL.
+/// Releasing a handle invalidates it; later calls fail safely instead of
+/// touching freed memory.
+typedef native_screen_recorder_t = ffi.Uint64;
+typedef Dartnative_screen_recorder_t = int;
+typedef native_screen_recording_event_callback_t =
+ ffi.Pointer<
+ ffi.NativeFunction
+ >;
+typedef native_screen_recording_event_callback_tFunction = ffi.Void Function(
+ ffi.Pointer event,
+ ffi.Pointer user_data,
+);
+typedef Dartnative_screen_recording_event_callback_tFunction = void Function(
+ ffi.Pointer event,
+ ffi.Pointer user_data,
+);
+typedef native_screen_recording_event_callback_t_async =
+ ffi.Pointer<
+ ffi.NativeFunction
+ >;
+typedef native_screen_recording_event_callback_t_asyncFunction =
+ ffi.Void Function(
+ ffi.Pointer event,
+ native_event_delivery_t delivery,
+ ffi.Pointer user_data,
+ );
+typedef Dartnative_screen_recording_event_callback_t_asyncFunction =
+ void Function(
+ ffi.Pointer event,
+ Dartnative_event_delivery_t delivery,
+ ffi.Pointer user_data,
+ );
+
+/// One ScreenRecordingEvent, tagged by its concrete type.
+///
+/// Synchronous callbacks borrow this payload until they return. Async callbacks
+/// borrow it until event_delivery_complete. Copy anything needed after that.
+final class native_screen_recording_event_t extends ffi.Struct {
+ @ffi.UnsignedInt()
+ external int typeAsInt;
+
+ native_screen_recording_event_type_t get type =>
+ native_screen_recording_event_type_t.fromValue(typeAsInt);
+ set type(native_screen_recording_event_type_t value) =>
+ typeAsInt = value.value;
+
+ external UnnamedUnion$7 data;
+}
+
+/// Which concrete ScreenRecordingEvent arrived.
+enum native_screen_recording_event_type_t {
+ NATIVE_SCREEN_RECORDING_EVENT_TYPE_STARTED(0),
+ NATIVE_SCREEN_RECORDING_EVENT_TYPE_COMPLETED(1),
+ NATIVE_SCREEN_RECORDING_EVENT_TYPE_CANCELLED(2),
+ NATIVE_SCREEN_RECORDING_EVENT_TYPE_FAILED(3);
+
+ final int value;
+ const native_screen_recording_event_type_t(this.value);
+
+ static native_screen_recording_event_type_t fromValue(int value) =>
+ switch (value) {
+ 0 => NATIVE_SCREEN_RECORDING_EVENT_TYPE_STARTED,
+ 1 => NATIVE_SCREEN_RECORDING_EVENT_TYPE_COMPLETED,
+ 2 => NATIVE_SCREEN_RECORDING_EVENT_TYPE_CANCELLED,
+ 3 => NATIVE_SCREEN_RECORDING_EVENT_TYPE_FAILED,
+ _ => throw ArgumentError(
+ 'Unknown value for native_screen_recording_event_type_t: $value',
+ ),
+ };
+}
+
+final class native_screen_recording_options_t extends ffi.Struct {
+ external native_screen_capture_options_t capture;
+
+ @ffi.Double()
+ external double frame_rate;
+
+ @ffi.UnsignedLong()
+ external int video_bitrate;
+}
+
+enum native_screen_recording_state_t {
+ NATIVE_SCREEN_RECORDING_STATE_IDLE(0),
+ NATIVE_SCREEN_RECORDING_STATE_STARTING(1),
+ NATIVE_SCREEN_RECORDING_STATE_RECORDING(2),
+ NATIVE_SCREEN_RECORDING_STATE_STOPPING(3),
+ NATIVE_SCREEN_RECORDING_STATE_COMPLETED(4),
+ NATIVE_SCREEN_RECORDING_STATE_CANCELLED(5),
+ NATIVE_SCREEN_RECORDING_STATE_FAILED(6);
+
+ final int value;
+ const native_screen_recording_state_t(this.value);
+
+ static native_screen_recording_state_t fromValue(int value) =>
+ switch (value) {
+ 0 => NATIVE_SCREEN_RECORDING_STATE_IDLE,
+ 1 => NATIVE_SCREEN_RECORDING_STATE_STARTING,
+ 2 => NATIVE_SCREEN_RECORDING_STATE_RECORDING,
+ 3 => NATIVE_SCREEN_RECORDING_STATE_STOPPING,
+ 4 => NATIVE_SCREEN_RECORDING_STATE_COMPLETED,
+ 5 => NATIVE_SCREEN_RECORDING_STATE_CANCELLED,
+ 6 => NATIVE_SCREEN_RECORDING_STATE_FAILED,
+ _ => throw ArgumentError(
+ 'Unknown value for native_screen_recording_state_t: $value',
+ ),
+ };
+}
+
/// Opaque SecureStorage handle.
///
/// A generational index into the library's handle table, NOT a pointer:
@@ -6077,7 +6562,7 @@ final class native_shortcut_event_t extends ffi.Struct {
external ffi.Pointer accelerator;
- external UnnamedUnion$7 data;
+ external UnnamedUnion$8 data;
}
/// Which concrete ShortcutEvent arrived.
@@ -6311,7 +6796,7 @@ final class native_taskbar_event_t extends ffi.Struct {
native_taskbar_event_type_t.fromValue(typeAsInt);
set type(native_taskbar_event_type_t value) => typeAsInt = value.value;
- external UnnamedUnion$8 data;
+ external UnnamedUnion$9 data;
}
/// Which concrete TaskbarEvent arrived.
@@ -6529,7 +7014,7 @@ final class native_tray_icon_event_t extends ffi.Struct {
native_tray_icon_event_type_t.fromValue(typeAsInt);
set type(native_tray_icon_event_type_t value) => typeAsInt = value.value;
- external UnnamedUnion$9 data;
+ external UnnamedUnion$10 data;
}
/// Which concrete TrayIconEvent arrived.
@@ -6718,7 +7203,7 @@ final class native_view_event_t extends ffi.Struct {
@native_view_id_t()
external int view_id;
- external UnnamedUnion$10 data;
+ external UnnamedUnion$11 data;
}
/// Which concrete ViewEvent arrived.
@@ -6975,7 +7460,7 @@ final class native_window_event_t extends ffi.Struct {
@native_window_id_t()
external int window_id;
- external UnnamedUnion$11 data;
+ external UnnamedUnion$12 data;
}
/// Which concrete WindowEvent arrived.
@@ -7154,6 +7639,8 @@ typedef native_window_t = ffi.Uint64;
typedef Dartnative_window_t = int;
typedef native_window_t$1 = ffi.Uint64;
typedef Dartnative_window_t$1 = int;
+typedef native_window_t$10 = ffi.Uint64;
+typedef Dartnative_window_t$10 = int;
typedef native_window_t$2 = ffi.Uint64;
typedef Dartnative_window_t$2 = int;
typedef native_window_t$3 = ffi.Uint64;
@@ -7168,6 +7655,8 @@ typedef native_window_t$7 = ffi.Uint64;
typedef Dartnative_window_t$7 = int;
typedef native_window_t$8 = ffi.Uint64;
typedef Dartnative_window_t$8 = int;
+typedef native_window_t$9 = ffi.Uint64;
+typedef Dartnative_window_t$9 = int;
/// Opaque WindowTaskbar handle.
///
diff --git a/bindings/dart/nativeapi/lib/src/capture_source.dart b/bindings/dart/nativeapi/lib/src/capture_source.dart
new file mode 100644
index 00000000..c096c6ec
--- /dev/null
+++ b/bindings/dart/nativeapi/lib/src/capture_source.dart
@@ -0,0 +1,92 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+// ignore_for_file: unused_import, unnecessary_import
+
+import 'dart:ffi' as ffi;
+
+import 'package:cnativeapi/cnativeapi.dart' as c;
+import 'package:ffi/ffi.dart' as pkg_ffi;
+
+import 'display.dart';
+import 'window.dart';
+
+enum CaptureSourceType {
+ none(0),
+ display(1),
+ window(2),
+ unknown(3);
+
+ const CaptureSourceType(this.value);
+ final int value;
+
+ static CaptureSourceType fromValue(int value) => switch (value) {
+ 0 => CaptureSourceType.none,
+ 1 => CaptureSourceType.display,
+ 2 => CaptureSourceType.window,
+ 3 => CaptureSourceType.unknown,
+ _ => CaptureSourceType.none,
+ };
+
+ c.native_capture_source_type_t get raw =>
+ c.native_capture_source_type_t.fromValue(value);
+}
+
+class CaptureSource implements ffi.Finalizable {
+ /// Adopts a handle returned by the C API and releases it when this
+ /// object becomes unreachable.
+ CaptureSource.fromHandle(this.nativeHandle) {
+ _finalizer.attach(
+ this,
+ ffi.Pointer.fromAddress(nativeHandle),
+ detach: this,
+ );
+ }
+
+ /// Wraps a handle owned elsewhere; releasing it stays the owner's job.
+ CaptureSource.borrowed(this.nativeHandle);
+
+ /// The underlying handle-table entry.
+ final int nativeHandle;
+
+ static final _finalizer = ffi.NativeFinalizer(
+ ffi.Native.addressOf<
+ ffi.NativeFunction)>
+ >(c.native_handle_finalize),
+ );
+
+ /// Releases the handle now instead of at collection.
+ void dispose() {
+ _finalizer.detach(this);
+ c.native_capture_source_free(nativeHandle);
+ }
+
+ static CaptureSource? fromDisplay(Display? display) {
+ final handle = c.native_capture_source_from_display(
+ display?.nativeHandle ?? 0,
+ );
+ if (handle == 0) return null;
+ return CaptureSource.fromHandle(handle);
+ }
+
+ static CaptureSource? fromWindow(Window? window) {
+ final handle = c.native_capture_source_from_window(
+ window?.nativeHandle ?? 0,
+ );
+ if (handle == 0) return null;
+ return CaptureSource.fromHandle(handle);
+ }
+
+ CaptureSourceType get type {
+ final raw = c.native_capture_source_get_type(nativeHandle);
+ return CaptureSourceType.fromValue(raw.value);
+ }
+
+ String? get name {
+ final resultPointer = c.native_capture_source_get_name(nativeHandle);
+ if (resultPointer == ffi.nullptr) return null;
+ final result = resultPointer.cast().toDartString();
+ c.free_c_str(resultPointer);
+ return result;
+ }
+}
diff --git a/bindings/dart/nativeapi/lib/src/generated.dart b/bindings/dart/nativeapi/lib/src/generated.dart
index ac772894..e3fd16f8 100644
--- a/bindings/dart/nativeapi/lib/src/generated.dart
+++ b/bindings/dart/nativeapi/lib/src/generated.dart
@@ -4,6 +4,7 @@
export 'accessibility_manager.dart';
export 'app_info.dart';
export 'application.dart';
+export 'capture_source.dart';
export 'clipboard.dart';
export 'device_info.dart';
export 'dialog.dart';
@@ -26,6 +27,8 @@ export 'placement.dart';
export 'positioning_strategy.dart';
export 'preferences.dart';
export 'protocol_handler.dart';
+export 'screen_capturer.dart';
+export 'screen_recorder.dart';
export 'secure_storage.dart';
export 'shortcut.dart';
export 'shortcut_manager.dart';
diff --git a/bindings/dart/nativeapi/lib/src/screen_capturer.dart b/bindings/dart/nativeapi/lib/src/screen_capturer.dart
new file mode 100644
index 00000000..f7ce1a44
--- /dev/null
+++ b/bindings/dart/nativeapi/lib/src/screen_capturer.dart
@@ -0,0 +1,220 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+// ignore_for_file: unused_import, unnecessary_import
+
+import 'dart:ffi' as ffi;
+
+import 'package:cnativeapi/cnativeapi.dart' as c;
+import 'package:ffi/ffi.dart' as pkg_ffi;
+
+import 'capture_source.dart';
+import 'foundation/geometry.dart';
+import 'image.dart';
+import 'window.dart';
+
+import 'callbacks.dart';
+
+class CaptureSourceSelectionOptions {
+ const CaptureSourceSelectionOptions({
+ required this.allowDisplays,
+ required this.allowWindows,
+ this.parentWindow,
+ });
+
+ final bool allowDisplays;
+ final bool allowWindows;
+ final Window? parentWindow;
+
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ (other is CaptureSourceSelectionOptions &&
+ other.allowDisplays == allowDisplays &&
+ other.allowWindows == allowWindows &&
+ other.parentWindow == parentWindow);
+
+ @override
+ int get hashCode => Object.hash(allowDisplays, allowWindows, parentWindow);
+
+ @override
+ String toString() =>
+ 'CaptureSourceSelectionOptions(allowDisplays: $allowDisplays, allowWindows: $allowWindows, parentWindow: $parentWindow)';
+
+ factory CaptureSourceSelectionOptions.fromNative(
+ c.native_capture_source_selection_options_t raw,
+ ) => CaptureSourceSelectionOptions(
+ allowDisplays: raw.allow_displays,
+ allowWindows: raw.allow_windows,
+ parentWindow: raw.parent_window == 0
+ ? null
+ : Window.fromHandle(c.native_handle_retain(raw.parent_window)),
+ );
+
+ /// Allocates the C form; free it with [freeNative].
+ ffi.Pointer allocNative() {
+ final pointer = pkg_ffi
+ .calloc();
+ pointer.ref.allow_displays = allowDisplays;
+ pointer.ref.allow_windows = allowWindows;
+ pointer.ref.parent_window = parentWindow?.nativeHandle ?? 0;
+ return pointer;
+ }
+
+ static void freeNative(
+ ffi.Pointer pointer,
+ ) {
+ pkg_ffi.calloc.free(pointer);
+ }
+}
+
+class ScreenCaptureOptions {
+ const ScreenCaptureOptions({
+ required this.includeCursor,
+ required this.cropEnabled,
+ required this.crop,
+ });
+
+ final bool includeCursor;
+ final bool cropEnabled;
+ final Rectangle crop;
+
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ (other is ScreenCaptureOptions &&
+ other.includeCursor == includeCursor &&
+ other.cropEnabled == cropEnabled &&
+ other.crop == crop);
+
+ @override
+ int get hashCode => Object.hash(includeCursor, cropEnabled, crop);
+
+ @override
+ String toString() =>
+ 'ScreenCaptureOptions(includeCursor: $includeCursor, cropEnabled: $cropEnabled, crop: $crop)';
+
+ factory ScreenCaptureOptions.fromNative(
+ c.native_screen_capture_options_t raw,
+ ) => ScreenCaptureOptions(
+ includeCursor: raw.include_cursor,
+ cropEnabled: raw.crop_enabled,
+ crop: Rectangle.fromNative(raw.crop),
+ );
+
+ /// Allocates the C form; free it with [freeNative].
+ ffi.Pointer allocNative() {
+ final pointer = pkg_ffi.calloc();
+ pointer.ref.include_cursor = includeCursor;
+ pointer.ref.crop_enabled = cropEnabled;
+ final cropPointer = crop.allocNative();
+ pointer.ref.crop = cropPointer.ref;
+ pkg_ffi.calloc.free(cropPointer);
+ return pointer;
+ }
+
+ static void freeNative(
+ ffi.Pointer pointer,
+ ) {
+ pkg_ffi.calloc.free(pointer);
+ }
+}
+
+class ScreenCapturer {
+ ScreenCapturer._();
+ static bool isSupported() {
+ return c.native_screen_capturer_is_supported();
+ }
+
+ static bool isSourceSelectionSupported() {
+ return c.native_screen_capturer_is_source_selection_supported();
+ }
+
+ static bool isDirectCaptureSupported(CaptureSourceType type) {
+ return c.native_screen_capturer_is_direct_capture_supported(type.raw);
+ }
+
+ static void selectSource(
+ CaptureSourceSelectionOptions options,
+ void Function(bool, CaptureSource?) callback,
+ ) {
+ final optionsPointer = options.allocNative();
+ final callbackCallable =
+ ffi.NativeCallable<
+ ffi.Void Function(
+ ffi.Bool,
+ ffi.Uint64,
+ ffi.Uint64,
+ ffi.Pointer,
+ )
+ >.listener((
+ bool arg0,
+ int arg1,
+ int delivery,
+ ffi.Pointer _,
+ ) {
+ try {
+ if (c.native_event_delivery_is_active(delivery)) {
+ callback(
+ arg0,
+ arg1 == 0
+ ? null
+ : CaptureSource.fromHandle(c.native_handle_retain(arg1)),
+ );
+ }
+ } finally {
+ c.native_event_delivery_complete(delivery, true);
+ }
+ });
+ c.native_screen_capturer_select_source(
+ optionsPointer.ref,
+ callbackCallable.nativeFunction.cast(),
+ NativeCallbacks.userData(callbackCallable),
+ NativeCallbacks.release,
+ );
+ CaptureSourceSelectionOptions.freeNative(optionsPointer);
+ }
+
+ static void capture(
+ CaptureSource? source,
+ ScreenCaptureOptions options,
+ void Function(bool, Image?) callback,
+ ) {
+ final optionsPointer = options.allocNative();
+ final callbackCallable =
+ ffi.NativeCallable<
+ ffi.Void Function(
+ ffi.Bool,
+ ffi.Uint64,
+ ffi.Uint64,
+ ffi.Pointer,
+ )
+ >.listener((
+ bool arg0,
+ int arg1,
+ int delivery,
+ ffi.Pointer _,
+ ) {
+ try {
+ if (c.native_event_delivery_is_active(delivery)) {
+ callback(
+ arg0,
+ arg1 == 0
+ ? null
+ : Image.fromHandle(c.native_handle_retain(arg1)),
+ );
+ }
+ } finally {
+ c.native_event_delivery_complete(delivery, true);
+ }
+ });
+ c.native_screen_capturer_capture(
+ source?.nativeHandle ?? 0,
+ optionsPointer.ref,
+ callbackCallable.nativeFunction.cast(),
+ NativeCallbacks.userData(callbackCallable),
+ NativeCallbacks.release,
+ );
+ ScreenCaptureOptions.freeNative(optionsPointer);
+ }
+}
diff --git a/bindings/dart/nativeapi/lib/src/screen_recorder.dart b/bindings/dart/nativeapi/lib/src/screen_recorder.dart
new file mode 100644
index 00000000..8453e4fc
--- /dev/null
+++ b/bindings/dart/nativeapi/lib/src/screen_recorder.dart
@@ -0,0 +1,302 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+// ignore_for_file: unused_import, unnecessary_import
+
+import 'dart:async';
+import 'dart:ffi' as ffi;
+
+import 'package:cnativeapi/cnativeapi.dart' as c;
+import 'package:ffi/ffi.dart' as pkg_ffi;
+
+import 'capture_source.dart';
+import 'screen_capturer.dart';
+
+import 'support.dart';
+
+import 'callbacks.dart';
+
+enum ScreenRecordingState {
+ idle(0),
+ starting(1),
+ recording(2),
+ stopping(3),
+ completed(4),
+ cancelled(5),
+ failed(6);
+
+ const ScreenRecordingState(this.value);
+ final int value;
+
+ static ScreenRecordingState fromValue(int value) => switch (value) {
+ 0 => ScreenRecordingState.idle,
+ 1 => ScreenRecordingState.starting,
+ 2 => ScreenRecordingState.recording,
+ 3 => ScreenRecordingState.stopping,
+ 4 => ScreenRecordingState.completed,
+ 5 => ScreenRecordingState.cancelled,
+ 6 => ScreenRecordingState.failed,
+ _ => ScreenRecordingState.idle,
+ };
+
+ c.native_screen_recording_state_t get raw =>
+ c.native_screen_recording_state_t.fromValue(value);
+}
+
+class ScreenRecordingOptions {
+ const ScreenRecordingOptions({
+ required this.capture,
+ required this.frameRate,
+ required this.videoBitrate,
+ });
+
+ final ScreenCaptureOptions capture;
+ final double frameRate;
+ final int videoBitrate;
+
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ (other is ScreenRecordingOptions &&
+ other.capture == capture &&
+ other.frameRate == frameRate &&
+ other.videoBitrate == videoBitrate);
+
+ @override
+ int get hashCode => Object.hash(capture, frameRate, videoBitrate);
+
+ @override
+ String toString() =>
+ 'ScreenRecordingOptions(capture: $capture, frameRate: $frameRate, videoBitrate: $videoBitrate)';
+
+ factory ScreenRecordingOptions.fromNative(
+ c.native_screen_recording_options_t raw,
+ ) => ScreenRecordingOptions(
+ capture: ScreenCaptureOptions.fromNative(raw.capture),
+ frameRate: raw.frame_rate,
+ videoBitrate: raw.video_bitrate,
+ );
+
+ /// Allocates the C form; free it with [freeNative].
+ ffi.Pointer allocNative() {
+ final pointer = pkg_ffi.calloc();
+ final capturePointer = capture.allocNative();
+ pointer.ref.capture = capturePointer.ref;
+ pkg_ffi.calloc.free(capturePointer);
+ pointer.ref.frame_rate = frameRate;
+ pointer.ref.video_bitrate = videoBitrate;
+ return pointer;
+ }
+
+ static void freeNative(
+ ffi.Pointer pointer,
+ ) {
+ pkg_ffi.calloc.free(pointer);
+ }
+}
+
+/// One `ScreenRecordingEvent`, in its concrete form.
+sealed class ScreenRecordingEvent {
+ const ScreenRecordingEvent();
+
+ /// Reads the event out of its C form. Returns null for a variant this
+ /// binding does not know about.
+ static ScreenRecordingEvent? fromNative(
+ c.native_screen_recording_event_t raw,
+ ) {
+ if (raw.typeAsInt ==
+ c
+ .native_screen_recording_event_type_t
+ .NATIVE_SCREEN_RECORDING_EVENT_TYPE_STARTED
+ .value) {
+ return ScreenRecordingStartedEvent();
+ }
+ if (raw.typeAsInt ==
+ c
+ .native_screen_recording_event_type_t
+ .NATIVE_SCREEN_RECORDING_EVENT_TYPE_COMPLETED
+ .value) {
+ return ScreenRecordingCompletedEvent(
+ filePath: raw.data.completed.file_path == ffi.nullptr
+ ? null
+ : raw.data.completed.file_path.cast().toDartString(),
+ duration: raw.data.completed.duration,
+ );
+ }
+ if (raw.typeAsInt ==
+ c
+ .native_screen_recording_event_type_t
+ .NATIVE_SCREEN_RECORDING_EVENT_TYPE_CANCELLED
+ .value) {
+ return ScreenRecordingCancelledEvent();
+ }
+ if (raw.typeAsInt ==
+ c
+ .native_screen_recording_event_type_t
+ .NATIVE_SCREEN_RECORDING_EVENT_TYPE_FAILED
+ .value) {
+ return ScreenRecordingFailedEvent(
+ message: raw.data.failed.message == ffi.nullptr
+ ? null
+ : raw.data.failed.message.cast().toDartString(),
+ );
+ }
+ return null;
+ }
+}
+
+final class ScreenRecordingStartedEvent extends ScreenRecordingEvent {
+ const ScreenRecordingStartedEvent();
+}
+
+final class ScreenRecordingCompletedEvent extends ScreenRecordingEvent {
+ const ScreenRecordingCompletedEvent({
+ required this.filePath,
+ required this.duration,
+ });
+
+ final String? filePath;
+ final double duration;
+}
+
+final class ScreenRecordingCancelledEvent extends ScreenRecordingEvent {
+ const ScreenRecordingCancelledEvent();
+}
+
+final class ScreenRecordingFailedEvent extends ScreenRecordingEvent {
+ const ScreenRecordingFailedEvent({required this.message});
+
+ final String? message;
+}
+
+class ScreenRecorder implements ffi.Finalizable {
+ /// Adopts a handle returned by the C API and releases it when this
+ /// object becomes unreachable.
+ ScreenRecorder.fromHandle(this.nativeHandle) {
+ _finalizer.attach(
+ this,
+ ffi.Pointer.fromAddress(nativeHandle),
+ detach: this,
+ );
+ }
+
+ /// Wraps a handle owned elsewhere; releasing it stays the owner's job.
+ ScreenRecorder.borrowed(this.nativeHandle);
+
+ /// The underlying handle-table entry.
+ final int nativeHandle;
+
+ static final _finalizer = ffi.NativeFinalizer(
+ ffi.Native.addressOf<
+ ffi.NativeFunction)>
+ >(c.native_handle_finalize),
+ );
+
+ /// Releases the handle now instead of at collection.
+ void dispose() {
+ _finalizer.detach(this);
+ c.native_screen_recorder_free(nativeHandle);
+ }
+
+ /// Creates a new `ScreenRecorder`; returns null if the native side failed.
+ static ScreenRecorder? create() {
+ final handle = c.native_screen_recorder_create();
+ if (handle == 0) return null;
+ return ScreenRecorder.fromHandle(handle);
+ }
+
+ static bool isSupported() {
+ return c.native_screen_recorder_is_supported();
+ }
+
+ bool start(
+ CaptureSource? source,
+ String filePath,
+ ScreenRecordingOptions options,
+ ) {
+ final filePathNative = filePath.toNativeUtf8().cast();
+ final optionsPointer = options.allocNative();
+ final result = c.native_screen_recorder_start(
+ nativeHandle,
+ source?.nativeHandle ?? 0,
+ filePathNative,
+ optionsPointer.ref,
+ );
+ pkg_ffi.calloc.free(filePathNative);
+ ScreenRecordingOptions.freeNative(optionsPointer);
+ return result;
+ }
+
+ bool stop() {
+ return c.native_screen_recorder_stop(nativeHandle);
+ }
+
+ bool cancel() {
+ return c.native_screen_recorder_cancel(nativeHandle);
+ }
+
+ ScreenRecordingState get state {
+ final raw = c.native_screen_recorder_get_state(nativeHandle);
+ return ScreenRecordingState.fromValue(raw.value);
+ }
+
+ bool get isActive {
+ return c.native_screen_recorder_is_active(nativeHandle);
+ }
+
+ double get duration {
+ return c.native_screen_recorder_get_duration(nativeHandle);
+ }
+
+ String? get filePath {
+ final resultPointer = c.native_screen_recorder_get_file_path(nativeHandle);
+ if (resultPointer == ffi.nullptr) return null;
+ final result = resultPointer.cast().toDartString();
+ c.free_c_str(resultPointer);
+ return result;
+ }
+
+ /// Registers [callback] for every `ScreenRecordingEvent` this `ScreenRecorder` emits.
+ ///
+ /// Delivered on the registering isolate, including events from native UI threads.
+ /// The callback may return a Future; borrowed handles stay valid until it completes.
+ /// Events queued before removal are skipped if their callback has not started.
+ ListenerId addListener(
+ FutureOr Function(ScreenRecordingEvent) callback,
+ ) {
+ final callable =
+ ffi.NativeCallable<
+ ffi.Void Function(
+ ffi.Pointer,
+ ffi.Uint64,
+ ffi.Pointer,
+ )
+ >.listener((
+ ffi.Pointer event,
+ int delivery,
+ ffi.Pointer _,
+ ) {
+ unawaited(
+ NativeCallbacks.deliverEvent(
+ delivery,
+ () => event == ffi.nullptr
+ ? null
+ : ScreenRecordingEvent.fromNative(
+ event.cast().ref,
+ ),
+ callback,
+ ),
+ );
+ });
+ return c.native_screen_recorder_add_listener_async(
+ nativeHandle,
+ callable.nativeFunction.cast(),
+ NativeCallbacks.userData(callable),
+ NativeCallbacks.release,
+ );
+ }
+
+ /// Unregisters a listener. Returns false if unknown.
+ bool removeListener(ListenerId listenerId) =>
+ c.native_screen_recorder_remove_listener(nativeHandle, listenerId);
+}
diff --git a/bindings/dart/nativeapi/lib/src/web/capture_source.dart b/bindings/dart/nativeapi/lib/src/web/capture_source.dart
new file mode 100644
index 00000000..8312dc1f
--- /dev/null
+++ b/bindings/dart/nativeapi/lib/src/web/capture_source.dart
@@ -0,0 +1,43 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+// ignore_for_file: unused_import, unnecessary_import
+
+import 'display.dart';
+import 'window.dart';
+import 'unsupported.dart';
+
+enum CaptureSourceType {
+ none(0),
+ display(1),
+ window(2),
+ unknown(3);
+
+ const CaptureSourceType(this.value);
+ final int value;
+
+ static CaptureSourceType fromValue(int value) => switch (value) {
+ 0 => CaptureSourceType.none,
+ 1 => CaptureSourceType.display,
+ 2 => CaptureSourceType.window,
+ 3 => CaptureSourceType.unknown,
+ _ => CaptureSourceType.none,
+ };
+}
+
+class CaptureSource {
+ CaptureSource.fromHandle(this.nativeHandle);
+ CaptureSource.borrowed(this.nativeHandle);
+
+ final int nativeHandle;
+
+ void dispose() => unsupported();
+
+ static CaptureSource? fromDisplay(Display? display) => unsupported();
+
+ static CaptureSource? fromWindow(Window? window) => unsupported();
+
+ CaptureSourceType get type => unsupported();
+
+ String? get name => unsupported();
+}
diff --git a/bindings/dart/nativeapi/lib/src/web/generated.dart b/bindings/dart/nativeapi/lib/src/web/generated.dart
index ac772894..e3fd16f8 100644
--- a/bindings/dart/nativeapi/lib/src/web/generated.dart
+++ b/bindings/dart/nativeapi/lib/src/web/generated.dart
@@ -4,6 +4,7 @@
export 'accessibility_manager.dart';
export 'app_info.dart';
export 'application.dart';
+export 'capture_source.dart';
export 'clipboard.dart';
export 'device_info.dart';
export 'dialog.dart';
@@ -26,6 +27,8 @@ export 'placement.dart';
export 'positioning_strategy.dart';
export 'preferences.dart';
export 'protocol_handler.dart';
+export 'screen_capturer.dart';
+export 'screen_recorder.dart';
export 'secure_storage.dart';
export 'shortcut.dart';
export 'shortcut_manager.dart';
diff --git a/bindings/dart/nativeapi/lib/src/web/screen_capturer.dart b/bindings/dart/nativeapi/lib/src/web/screen_capturer.dart
new file mode 100644
index 00000000..98be96ab
--- /dev/null
+++ b/bindings/dart/nativeapi/lib/src/web/screen_capturer.dart
@@ -0,0 +1,87 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+// ignore_for_file: unused_import, unnecessary_import
+
+import 'capture_source.dart';
+import 'foundation/geometry.dart';
+import 'image.dart';
+import 'window.dart';
+import 'unsupported.dart';
+
+class CaptureSourceSelectionOptions {
+ const CaptureSourceSelectionOptions({
+ required this.allowDisplays,
+ required this.allowWindows,
+ this.parentWindow,
+ });
+
+ final bool allowDisplays;
+ final bool allowWindows;
+ final Window? parentWindow;
+
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ (other is CaptureSourceSelectionOptions &&
+ other.allowDisplays == allowDisplays &&
+ other.allowWindows == allowWindows &&
+ other.parentWindow == parentWindow);
+
+ @override
+ int get hashCode => Object.hash(allowDisplays, allowWindows, parentWindow);
+
+ @override
+ String toString() =>
+ 'CaptureSourceSelectionOptions(allowDisplays: $allowDisplays, allowWindows: $allowWindows, parentWindow: $parentWindow)';
+}
+
+class ScreenCaptureOptions {
+ const ScreenCaptureOptions({
+ required this.includeCursor,
+ required this.cropEnabled,
+ required this.crop,
+ });
+
+ final bool includeCursor;
+ final bool cropEnabled;
+ final Rectangle crop;
+
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ (other is ScreenCaptureOptions &&
+ other.includeCursor == includeCursor &&
+ other.cropEnabled == cropEnabled &&
+ other.crop == crop);
+
+ @override
+ int get hashCode => Object.hash(includeCursor, cropEnabled, crop);
+
+ @override
+ String toString() =>
+ 'ScreenCaptureOptions(includeCursor: $includeCursor, cropEnabled: $cropEnabled, crop: $crop)';
+}
+
+class ScreenCapturer {
+ const ScreenCapturer._();
+
+ static const ScreenCapturer instance = ScreenCapturer._();
+
+ static bool isSupported() => unsupported();
+
+ static bool isSourceSelectionSupported() => unsupported();
+
+ static bool isDirectCaptureSupported(CaptureSourceType type) => unsupported();
+
+ static void selectSource(
+ CaptureSourceSelectionOptions options,
+ void Function(bool, CaptureSource?) callback,
+ ) => unsupported();
+
+ static void capture(
+ CaptureSource? source,
+ ScreenCaptureOptions options,
+ void Function(bool, Image?) callback,
+ ) => unsupported();
+}
diff --git a/bindings/dart/nativeapi/lib/src/web/screen_recorder.dart b/bindings/dart/nativeapi/lib/src/web/screen_recorder.dart
new file mode 100644
index 00000000..f56fafa8
--- /dev/null
+++ b/bindings/dart/nativeapi/lib/src/web/screen_recorder.dart
@@ -0,0 +1,128 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+// ignore_for_file: unused_import, unnecessary_import
+
+import 'dart:async';
+
+import 'capture_source.dart';
+import 'screen_capturer.dart';
+import 'support.dart';
+import 'unsupported.dart';
+
+enum ScreenRecordingState {
+ idle(0),
+ starting(1),
+ recording(2),
+ stopping(3),
+ completed(4),
+ cancelled(5),
+ failed(6);
+
+ const ScreenRecordingState(this.value);
+ final int value;
+
+ static ScreenRecordingState fromValue(int value) => switch (value) {
+ 0 => ScreenRecordingState.idle,
+ 1 => ScreenRecordingState.starting,
+ 2 => ScreenRecordingState.recording,
+ 3 => ScreenRecordingState.stopping,
+ 4 => ScreenRecordingState.completed,
+ 5 => ScreenRecordingState.cancelled,
+ 6 => ScreenRecordingState.failed,
+ _ => ScreenRecordingState.idle,
+ };
+}
+
+class ScreenRecordingOptions {
+ const ScreenRecordingOptions({
+ required this.capture,
+ required this.frameRate,
+ required this.videoBitrate,
+ });
+
+ final ScreenCaptureOptions capture;
+ final double frameRate;
+ final int videoBitrate;
+
+ @override
+ bool operator ==(Object other) =>
+ identical(this, other) ||
+ (other is ScreenRecordingOptions &&
+ other.capture == capture &&
+ other.frameRate == frameRate &&
+ other.videoBitrate == videoBitrate);
+
+ @override
+ int get hashCode => Object.hash(capture, frameRate, videoBitrate);
+
+ @override
+ String toString() =>
+ 'ScreenRecordingOptions(capture: $capture, frameRate: $frameRate, videoBitrate: $videoBitrate)';
+}
+
+/// One `ScreenRecordingEvent`, in its concrete form.
+sealed class ScreenRecordingEvent {
+ const ScreenRecordingEvent();
+}
+
+final class ScreenRecordingStartedEvent extends ScreenRecordingEvent {
+ const ScreenRecordingStartedEvent();
+}
+
+final class ScreenRecordingCompletedEvent extends ScreenRecordingEvent {
+ const ScreenRecordingCompletedEvent({
+ required this.filePath,
+ required this.duration,
+ });
+
+ final String? filePath;
+ final double duration;
+}
+
+final class ScreenRecordingCancelledEvent extends ScreenRecordingEvent {
+ const ScreenRecordingCancelledEvent();
+}
+
+final class ScreenRecordingFailedEvent extends ScreenRecordingEvent {
+ const ScreenRecordingFailedEvent({required this.message});
+
+ final String? message;
+}
+
+class ScreenRecorder {
+ ScreenRecorder.fromHandle(this.nativeHandle);
+ ScreenRecorder.borrowed(this.nativeHandle);
+
+ final int nativeHandle;
+
+ void dispose() => unsupported();
+
+ static ScreenRecorder? create() => unsupported();
+
+ static bool isSupported() => unsupported();
+
+ bool start(
+ CaptureSource? source,
+ String filePath,
+ ScreenRecordingOptions options,
+ ) => unsupported();
+
+ bool stop() => unsupported();
+
+ bool cancel() => unsupported();
+
+ ScreenRecordingState get state => unsupported();
+
+ bool get isActive => unsupported();
+
+ double get duration => unsupported();
+
+ String? get filePath => unsupported();
+
+ ListenerId addListener(
+ FutureOr Function(ScreenRecordingEvent) callback,
+ ) => unsupported();
+
+ bool removeListener(ListenerId listenerId) => unsupported();
+}
diff --git a/bindings/go/bridge.gen.h b/bindings/go/bridge.gen.h
index 5ae81f87..7242f78c 100644
--- a/bindings/go/bridge.gen.h
+++ b/bindings/go/bridge.gen.h
@@ -29,6 +29,12 @@ static inline char* go_native_notification_event_t_activated_Argument(const nati
extern void goEvent_native_notification_event_t(uintptr_t handle, native_notification_event_t* event);
static inline void go_native_notification_event_callback_t(const native_notification_event_t* event, void* data) { goEvent_native_notification_event_t(*(uintptr_t*)data, (native_notification_event_t*)event); }
static inline native_notification_event_callback_t go_get_native_notification_event_callback_t(void) { return go_native_notification_event_callback_t; }
+static inline char* go_native_screen_recording_event_t_completed_FilePath(const native_screen_recording_event_t* event) { return event->data.completed.file_path; }
+static inline double go_native_screen_recording_event_t_completed_Duration(const native_screen_recording_event_t* event) { return event->data.completed.duration; }
+static inline char* go_native_screen_recording_event_t_failed_Message(const native_screen_recording_event_t* event) { return event->data.failed.message; }
+extern void goEvent_native_screen_recording_event_t(uintptr_t handle, native_screen_recording_event_t* event);
+static inline void go_native_screen_recording_event_callback_t(const native_screen_recording_event_t* event, void* data) { goEvent_native_screen_recording_event_t(*(uintptr_t*)data, (native_screen_recording_event_t*)event); }
+static inline native_screen_recording_event_callback_t go_get_native_screen_recording_event_callback_t(void) { return go_native_screen_recording_event_callback_t; }
static inline char* go_native_view_event_t_text_field_changed_Text(const native_view_event_t* event) { return event->data.text_field_changed.text; }
static inline native_size_t go_native_view_event_t_resized_NewSize(const native_view_event_t* event) { return event->data.resized.new_size; }
extern void goEvent_native_view_event_t(uintptr_t handle, native_view_event_t* event);
@@ -107,6 +113,12 @@ static inline native_clipboard_read_rtf_callback_t go_get_native_clipboard_read_
extern void goCall_native_clipboard_read_text_callback_t(uintptr_t handle, bool arg0, void* arg1, native_event_delivery_t delivery);
static inline void go_native_clipboard_read_text_callback_t(bool arg0, const char* arg1, native_event_delivery_t delivery, void* data) { goCall_native_clipboard_read_text_callback_t(*(uintptr_t*)data, arg0, (void*)arg1, delivery); }
static inline native_clipboard_read_text_callback_t go_get_native_clipboard_read_text_callback_t(void) { return go_native_clipboard_read_text_callback_t; }
+extern void goCall_native_screen_capturer_capture_callback_t(uintptr_t handle, bool arg0, native_image_t arg1, native_event_delivery_t delivery);
+static inline void go_native_screen_capturer_capture_callback_t(bool arg0, native_image_t arg1, native_event_delivery_t delivery, void* data) { goCall_native_screen_capturer_capture_callback_t(*(uintptr_t*)data, arg0, arg1, delivery); }
+static inline native_screen_capturer_capture_callback_t go_get_native_screen_capturer_capture_callback_t(void) { return go_native_screen_capturer_capture_callback_t; }
+extern void goCall_native_screen_capturer_select_source_callback_t(uintptr_t handle, bool arg0, native_capture_source_t arg1, native_event_delivery_t delivery);
+static inline void go_native_screen_capturer_select_source_callback_t(bool arg0, native_capture_source_t arg1, native_event_delivery_t delivery, void* data) { goCall_native_screen_capturer_select_source_callback_t(*(uintptr_t*)data, arg0, arg1, delivery); }
+static inline native_screen_capturer_select_source_callback_t go_get_native_screen_capturer_select_source_callback_t(void) { return go_native_screen_capturer_select_source_callback_t; }
extern void goCall_native_shortcut_create_with_id_and_accelerator_and_callback_t(uintptr_t handle);
static inline void go_native_shortcut_create_with_id_and_accelerator_and_callback_t(void* data) { goCall_native_shortcut_create_with_id_and_accelerator_and_callback_t(*(uintptr_t*)data); }
static inline native_shortcut_create_with_id_and_accelerator_and_callback_t go_get_native_shortcut_create_with_id_and_accelerator_and_callback_t(void) { return go_native_shortcut_create_with_id_and_accelerator_and_callback_t; }
diff --git a/bindings/go/nativeapi.gen.go b/bindings/go/nativeapi.gen.go
index 26c24f59..34a2656c 100644
--- a/bindings/go/nativeapi.gen.go
+++ b/bindings/go/nativeapi.gen.go
@@ -2284,6 +2284,388 @@ func (i *Image) NativeObject() unsafe.Pointer {
return C.native_image_get_native_object(C.native_image_t(i.nativeHandleValue()))
}
+// CaptureSourceType represents native CaptureSourceType values.
+type CaptureSourceType int32
+
+const (
+ CaptureSourceTypeNone CaptureSourceType = 0
+ CaptureSourceTypeDisplay CaptureSourceType = 1
+ CaptureSourceTypeWindow CaptureSourceType = 2
+ CaptureSourceTypeUnknown CaptureSourceType = 3
+)
+
+// CaptureSource owns a native handle. Call Release on the UI thread when done.
+// Copies share ownership state; borrowed event handles must not outlive their callback.
+type CaptureSource struct{ *nativeHandle }
+
+func wrapCaptureSource(value uint64, borrowed bool) *CaptureSource {
+ if value == 0 {
+ return nil
+ }
+ return wrapCaptureSourceState(&nativeHandle{value: value, borrowed: borrowed})
+}
+func wrapCaptureSourceState(state *nativeHandle) *CaptureSource {
+ return &CaptureSource{state}
+}
+func (cs *CaptureSource) nativeHandleValue() uint64 {
+ if cs == nil || cs.nativeHandle == nil {
+ return 0
+ }
+ return cs.nativeHandle.nativeHandleValue()
+}
+
+// Release drops this owned reference. Repeated calls and nil receivers are safe.
+func (cs *CaptureSource) Release() {
+ if cs.nativeHandleValue() == 0 || cs.borrowed {
+ return
+ }
+ C.native_capture_source_free(C.native_capture_source_t(cs.value))
+ cs.value = 0
+}
+
+// CaptureSourceFromDisplay invokes the native FromDisplay operation.
+// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
+func CaptureSourceFromDisplay(display *Display) (*CaptureSource, error) {
+ result := C.native_capture_source_from_display(C.native_display_t(display.nativeHandleValue()))
+ if result == 0 {
+ return nil, nativeError("CaptureSourceFromDisplay")
+ }
+ return wrapCaptureSource(uint64(result), false), nil
+}
+
+// CaptureSourceFromWindow invokes the native FromWindow operation.
+// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
+func CaptureSourceFromWindow(window *Window) (*CaptureSource, error) {
+ result := C.native_capture_source_from_window(C.native_window_t(window.nativeHandleValue()))
+ if result == 0 {
+ return nil, nativeError("CaptureSourceFromWindow")
+ }
+ return wrapCaptureSource(uint64(result), false), nil
+}
+
+// Type invokes the native GetType operation.
+func (cs *CaptureSource) Type() CaptureSourceType {
+ result := C.native_capture_source_get_type(C.native_capture_source_t(cs.nativeHandleValue()))
+ return CaptureSourceType(result)
+}
+
+// Name invokes the native GetName operation.
+func (cs *CaptureSource) Name() string {
+ result := C.native_capture_source_get_name(C.native_capture_source_t(cs.nativeHandleValue()))
+ defer C.free_c_str(result)
+ return C.GoString(result)
+}
+
+// CaptureSourceSelectionOptions holds the native CaptureSourceSelectionOptions value.
+type CaptureSourceSelectionOptions struct {
+ AllowDisplays bool
+ AllowWindows bool
+ ParentWindow *Window
+}
+
+func fromCCaptureSourceSelectionOptions(raw C.native_capture_source_selection_options_t) CaptureSourceSelectionOptions {
+ return CaptureSourceSelectionOptions{
+ AllowDisplays: bool(raw.allow_displays),
+ AllowWindows: bool(raw.allow_windows),
+ ParentWindow: wrapWindow(uint64(C.native_handle_retain(raw.parent_window)), false),
+ }
+}
+func toCCaptureSourceSelectionOptions(value CaptureSourceSelectionOptions) (C.native_capture_source_selection_options_t, func()) {
+ var raw C.native_capture_source_selection_options_t
+ var cleanup []func()
+ raw.allow_displays = C.bool(value.AllowDisplays)
+ raw.allow_windows = C.bool(value.AllowWindows)
+ raw.parent_window = C.native_window_t(value.ParentWindow.nativeHandleValue())
+ return raw, func() {
+ for i := len(cleanup) - 1; i >= 0; i-- {
+ cleanup[i]()
+ }
+ }
+}
+
+// ScreenCaptureOptions holds the native ScreenCaptureOptions value.
+type ScreenCaptureOptions struct {
+ IncludeCursor bool
+ CropEnabled bool
+ Crop Rectangle
+}
+
+func fromCScreenCaptureOptions(raw C.native_screen_capture_options_t) ScreenCaptureOptions {
+ return ScreenCaptureOptions{
+ IncludeCursor: bool(raw.include_cursor),
+ CropEnabled: bool(raw.crop_enabled),
+ Crop: fromCRectangle(raw.crop),
+ }
+}
+func toCScreenCaptureOptions(value ScreenCaptureOptions) (C.native_screen_capture_options_t, func()) {
+ var raw C.native_screen_capture_options_t
+ var cleanup []func()
+ raw.include_cursor = C.bool(value.IncludeCursor)
+ raw.crop_enabled = C.bool(value.CropEnabled)
+ cField2, cField2Cleanup := toCRectangle(value.Crop)
+ cleanup = append(cleanup, func() { cField2Cleanup() })
+ raw.crop = cField2
+ return raw, func() {
+ for i := len(cleanup) - 1; i >= 0; i-- {
+ cleanup[i]()
+ }
+ }
+}
+
+// ScreenCapturerIsSupported invokes the native IsSupported operation.
+func ScreenCapturerIsSupported() bool {
+ result := C.native_screen_capturer_is_supported()
+ return bool(result)
+}
+
+// ScreenCapturerIsSourceSelectionSupported invokes the native IsSourceSelectionSupported operation.
+func ScreenCapturerIsSourceSelectionSupported() bool {
+ result := C.native_screen_capturer_is_source_selection_supported()
+ return bool(result)
+}
+
+// ScreenCapturerIsDirectCaptureSupported invokes the native IsDirectCaptureSupported operation.
+func ScreenCapturerIsDirectCaptureSupported(kind CaptureSourceType) bool {
+ result := C.native_screen_capturer_is_direct_capture_supported(C.native_capture_source_type_t(kind))
+ return bool(result)
+}
+
+// ScreenCapturerSelectSource invokes the native SelectSource operation.
+func ScreenCapturerSelectSource(options CaptureSourceSelectionOptions, callback func(bool, *CaptureSource)) {
+ cArg0, cArg0Cleanup := toCCaptureSourceSelectionOptions(options)
+ defer cArg0Cleanup()
+ var cArg1Fn C.native_screen_capturer_select_source_callback_t
+ var cArg1Data unsafe.Pointer
+ var cArg1Release C.native_release_user_data_t
+ if callback != nil {
+ cArg1Data = newCallback(callback)
+ cArg1Fn = C.native_screen_capturer_select_source_callback_t(C.go_get_native_screen_capturer_select_source_callback_t())
+ cArg1Release = C.native_release_user_data_t(C.go_get_release_callback())
+ }
+ C.native_screen_capturer_select_source(cArg0, cArg1Fn, cArg1Data, cArg1Release)
+}
+
+// ScreenCapturerCapture invokes the native Capture operation.
+func ScreenCapturerCapture(source *CaptureSource, options ScreenCaptureOptions, callback func(bool, *Image)) {
+ cArg1, cArg1Cleanup := toCScreenCaptureOptions(options)
+ defer cArg1Cleanup()
+ var cArg2Fn C.native_screen_capturer_capture_callback_t
+ var cArg2Data unsafe.Pointer
+ var cArg2Release C.native_release_user_data_t
+ if callback != nil {
+ cArg2Data = newCallback(callback)
+ cArg2Fn = C.native_screen_capturer_capture_callback_t(C.go_get_native_screen_capturer_capture_callback_t())
+ cArg2Release = C.native_release_user_data_t(C.go_get_release_callback())
+ }
+ C.native_screen_capturer_capture(C.native_capture_source_t(source.nativeHandleValue()), cArg1, cArg2Fn, cArg2Data, cArg2Release)
+}
+
+// ScreenRecordingState represents native ScreenRecordingState values.
+type ScreenRecordingState int32
+
+const (
+ ScreenRecordingStateIdle ScreenRecordingState = 0
+ ScreenRecordingStateStarting ScreenRecordingState = 1
+ ScreenRecordingStateRecording ScreenRecordingState = 2
+ ScreenRecordingStateStopping ScreenRecordingState = 3
+ ScreenRecordingStateCompleted ScreenRecordingState = 4
+ ScreenRecordingStateCancelled ScreenRecordingState = 5
+ ScreenRecordingStateFailed ScreenRecordingState = 6
+)
+
+// ScreenRecordingOptions holds the native ScreenRecordingOptions value.
+type ScreenRecordingOptions struct {
+ Capture ScreenCaptureOptions
+ FrameRate float64
+ VideoBitrate uint64
+}
+
+func fromCScreenRecordingOptions(raw C.native_screen_recording_options_t) ScreenRecordingOptions {
+ return ScreenRecordingOptions{
+ Capture: fromCScreenCaptureOptions(raw.capture),
+ FrameRate: float64(raw.frame_rate),
+ VideoBitrate: uint64(raw.video_bitrate),
+ }
+}
+func toCScreenRecordingOptions(value ScreenRecordingOptions) (C.native_screen_recording_options_t, func()) {
+ var raw C.native_screen_recording_options_t
+ var cleanup []func()
+ cField0, cField0Cleanup := toCScreenCaptureOptions(value.Capture)
+ cleanup = append(cleanup, func() { cField0Cleanup() })
+ raw.capture = cField0
+ raw.frame_rate = C.double(value.FrameRate)
+ raw.video_bitrate = C.ulong(value.VideoBitrate)
+ return raw, func() {
+ for i := len(cleanup) - 1; i >= 0; i-- {
+ cleanup[i]()
+ }
+ }
+}
+
+// ScreenRecordingEventType identifies the active event variant.
+type ScreenRecordingEventType int32
+
+const (
+ ScreenRecordingEventStarted ScreenRecordingEventType = 0
+ ScreenRecordingEventCompleted ScreenRecordingEventType = 1
+ ScreenRecordingEventCancelled ScreenRecordingEventType = 2
+ ScreenRecordingEventFailed ScreenRecordingEventType = 3
+)
+
+// ScreenRecordingEvent copies an event payload. Handle fields are borrowed until the callback returns.
+// Only fields belonging to Type are populated.
+type ScreenRecordingEvent struct {
+ Type ScreenRecordingEventType
+ FilePath string
+ Duration float64
+ Message string
+}
+
+func fromCScreenRecordingEvent(raw *C.native_screen_recording_event_t) ScreenRecordingEvent {
+ value := ScreenRecordingEvent{Type: ScreenRecordingEventType(raw._type)}
+ switch value.Type {
+ case ScreenRecordingEventStarted:
+ case ScreenRecordingEventCompleted:
+ value.FilePath = C.GoString(C.go_native_screen_recording_event_t_completed_FilePath(raw))
+ value.Duration = float64(C.go_native_screen_recording_event_t_completed_Duration(raw))
+ case ScreenRecordingEventCancelled:
+ case ScreenRecordingEventFailed:
+ value.Message = C.GoString(C.go_native_screen_recording_event_t_failed_Message(raw))
+ }
+ return value
+}
+
+//export goEvent_native_screen_recording_event_t
+func goEvent_native_screen_recording_event_t(handle C.uintptr_t, event *C.native_screen_recording_event_t) {
+ cgo.Handle(handle).Value().(func(ScreenRecordingEvent))(fromCScreenRecordingEvent(event))
+}
+
+// ScreenRecorder owns a native handle. Call Release on the UI thread when done.
+// Copies share ownership state; borrowed event handles must not outlive their callback.
+type ScreenRecorder struct{ *nativeHandle }
+
+func wrapScreenRecorder(value uint64, borrowed bool) *ScreenRecorder {
+ if value == 0 {
+ return nil
+ }
+ return wrapScreenRecorderState(&nativeHandle{value: value, borrowed: borrowed})
+}
+func wrapScreenRecorderState(state *nativeHandle) *ScreenRecorder {
+ return &ScreenRecorder{state}
+}
+func (sr *ScreenRecorder) nativeHandleValue() uint64 {
+ if sr == nil || sr.nativeHandle == nil {
+ return 0
+ }
+ return sr.nativeHandle.nativeHandleValue()
+}
+
+// Release drops this owned reference. Repeated calls and nil receivers are safe.
+func (sr *ScreenRecorder) Release() {
+ if sr.nativeHandleValue() == 0 || sr.borrowed {
+ return
+ }
+ C.native_screen_recorder_free(C.native_screen_recorder_t(sr.value))
+ sr.value = 0
+}
+
+// NewScreenRecorder creates an owned ScreenRecorder.
+// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
+func NewScreenRecorder() (*ScreenRecorder, error) {
+ result := C.native_screen_recorder_create()
+ if result == 0 {
+ return nil, nativeError("NewScreenRecorder")
+ }
+ return wrapScreenRecorder(uint64(result), false), nil
+}
+
+// ScreenRecorderIsSupported invokes the native IsSupported operation.
+func ScreenRecorderIsSupported() bool {
+ result := C.native_screen_recorder_is_supported()
+ return bool(result)
+}
+
+// Start invokes the native Start operation.
+// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
+func (sr *ScreenRecorder) Start(source *CaptureSource, filePath string, options ScreenRecordingOptions) error {
+ cArg1 := C.CString(filePath)
+ defer C.free(unsafe.Pointer(cArg1))
+ cArg2, cArg2Cleanup := toCScreenRecordingOptions(options)
+ defer cArg2Cleanup()
+ result := C.native_screen_recorder_start(C.native_screen_recorder_t(sr.nativeHandleValue()), C.native_capture_source_t(source.nativeHandleValue()), cArg1, cArg2)
+ if !bool(result) {
+ return nativeError("ScreenRecorder.Start")
+ }
+ return nil
+}
+
+// Stop invokes the native Stop operation.
+// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
+func (sr *ScreenRecorder) Stop() error {
+ result := C.native_screen_recorder_stop(C.native_screen_recorder_t(sr.nativeHandleValue()))
+ if !bool(result) {
+ return nativeError("ScreenRecorder.Stop")
+ }
+ return nil
+}
+
+// Cancel invokes the native Cancel operation.
+// Failure wraps ErrOperationFailed; the native ABI provides no detailed cause.
+func (sr *ScreenRecorder) Cancel() error {
+ result := C.native_screen_recorder_cancel(C.native_screen_recorder_t(sr.nativeHandleValue()))
+ if !bool(result) {
+ return nativeError("ScreenRecorder.Cancel")
+ }
+ return nil
+}
+
+// State invokes the native GetState operation.
+func (sr *ScreenRecorder) State() ScreenRecordingState {
+ result := C.native_screen_recorder_get_state(C.native_screen_recorder_t(sr.nativeHandleValue()))
+ return ScreenRecordingState(result)
+}
+
+// IsActive invokes the native IsActive operation.
+func (sr *ScreenRecorder) IsActive() bool {
+ result := C.native_screen_recorder_is_active(C.native_screen_recorder_t(sr.nativeHandleValue()))
+ return bool(result)
+}
+
+// Duration invokes the native GetDuration operation.
+func (sr *ScreenRecorder) Duration() float64 {
+ result := C.native_screen_recorder_get_duration(C.native_screen_recorder_t(sr.nativeHandleValue()))
+ return float64(result)
+}
+
+// FilePath invokes the native GetFilePath operation.
+func (sr *ScreenRecorder) FilePath() string {
+ result := C.native_screen_recorder_get_file_path(C.native_screen_recorder_t(sr.nativeHandleValue()))
+ defer C.free_c_str(result)
+ return C.GoString(result)
+}
+
+// AddListener invokes callback synchronously on the native UI thread.
+// Remove the listener before releasing its owner. A nil callback is invalid.
+func (sr *ScreenRecorder) AddListener(callback func(ScreenRecordingEvent)) (ListenerID, error) {
+ if callback == nil {
+ return 0, invalidArgument("ScreenRecorder.AddListener")
+ }
+ data := newCallback(callback)
+ id := C.native_screen_recorder_add_listener(C.native_screen_recorder_t(sr.nativeHandleValue()), C.native_screen_recording_event_callback_t(C.go_get_native_screen_recording_event_callback_t()), data, C.native_release_user_data_t(C.go_get_release_callback()))
+ if id == 0 {
+ return 0, nativeError("ScreenRecorder.AddListener")
+ }
+ return ListenerID(id), nil
+}
+
+// RemoveListener unregisters id; an unknown id returns an error.
+func (sr *ScreenRecorder) RemoveListener(id ListenerID) error {
+ if !bool(C.native_screen_recorder_remove_listener(C.native_screen_recorder_t(sr.nativeHandleValue()), C.native_listener_id_t(id))) {
+ return nativeError("ScreenRecorder.RemoveListener")
+ }
+ return nil
+}
+
// WindowShape owns a native handle. Call Release on the UI thread when done.
// Copies share ownership state; borrowed event handles must not outlive their callback.
type WindowShape struct{ *nativeHandle }
@@ -7372,6 +7754,24 @@ func goCall_native_clipboard_read_text_callback_t(handle C.uintptr_t, arg0 C.boo
cgo.Handle(handle).Value().(func(bool, *string))(bool(arg0), optionalStringFromC((*C.char)(arg1)))
}
+//export goCall_native_screen_capturer_capture_callback_t
+func goCall_native_screen_capturer_capture_callback_t(handle C.uintptr_t, arg0 C.bool, arg1 C.native_image_t, delivery C.native_event_delivery_t) {
+ defer C.native_event_delivery_complete(delivery, true)
+ if !bool(C.native_event_delivery_is_active(delivery)) {
+ return
+ }
+ cgo.Handle(handle).Value().(func(bool, *Image))(bool(arg0), wrapImage(uint64(C.native_handle_retain(arg1)), false))
+}
+
+//export goCall_native_screen_capturer_select_source_callback_t
+func goCall_native_screen_capturer_select_source_callback_t(handle C.uintptr_t, arg0 C.bool, arg1 C.native_capture_source_t, delivery C.native_event_delivery_t) {
+ defer C.native_event_delivery_complete(delivery, true)
+ if !bool(C.native_event_delivery_is_active(delivery)) {
+ return
+ }
+ cgo.Handle(handle).Value().(func(bool, *CaptureSource))(bool(arg0), wrapCaptureSource(uint64(C.native_handle_retain(arg1)), false))
+}
+
//export goCall_native_shortcut_create_with_id_and_accelerator_and_callback_t
func goCall_native_shortcut_create_with_id_and_accelerator_and_callback_t(handle C.uintptr_t) {
cgo.Handle(handle).Value().(func())()
diff --git a/bindings/go/screen_capture_test.go b/bindings/go/screen_capture_test.go
new file mode 100644
index 00000000..c1f3f091
--- /dev/null
+++ b/bindings/go/screen_capture_test.go
@@ -0,0 +1,26 @@
+package nativeapi
+
+import "testing"
+
+// No desktop or permission: exercise the real cgo nested-value conversion.
+func TestRecordingRejectionKeepsIdle(t *testing.T) {
+ recorder, err := NewScreenRecorder()
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer recorder.Release()
+ options := ScreenRecordingOptions{
+ Capture: ScreenCaptureOptions{IncludeCursor: false, CropEnabled: true,
+ Crop: Rectangle{X: 1, Y: 2, Width: 32, Height: 48}},
+ FrameRate: 30, VideoBitrate: 1000000,
+ }
+ if recorder.Start(nil, "relative.mp4", options) == nil {
+ t.Fatal("invalid request accepted")
+ }
+ if recorder.State() != ScreenRecordingStateIdle || recorder.IsActive() || recorder.Duration() != 0 {
+ t.Fatal("rejected request changed recorder state")
+ }
+ if recorder.Stop() == nil || recorder.Cancel() == nil {
+ t.Fatal("idle recorder accepted a termination action")
+ }
+}
diff --git a/bindings/js/lib/capture_source.ts b/bindings/js/lib/capture_source.ts
new file mode 100644
index 00000000..7539b25d
--- /dev/null
+++ b/bindings/js/lib/capture_source.ts
@@ -0,0 +1,38 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+import { native, NativeObject, wrapHandle } from "./runtime.ts";
+import { Display } from "./display.ts";
+import { Window } from "./window.ts";
+
+export const CaptureSourceType = {
+ None: 0,
+ Display: 1,
+ Window: 2,
+ Unknown: 3,
+} as const;
+export type CaptureSourceType = (typeof CaptureSourceType)[keyof typeof CaptureSourceType];
+
+/** A native CaptureSource, held through an owned handle. */
+export class CaptureSource extends NativeObject {
+ /** Wraps a raw handle; an owned one is released on `dispose()` or collection. */
+ constructor(handle: bigint, owned = true) {
+ super(handle, owned ? native.native_capture_source_free : undefined);
+ }
+
+ static fromDisplay(display: Display | null): CaptureSource | null {
+ return wrapHandle(CaptureSource, native.native_capture_source_from_display(display?.nativeHandle ?? 0n));
+ }
+
+ static fromWindow(window: Window | null): CaptureSource | null {
+ return wrapHandle(CaptureSource, native.native_capture_source_from_window(window?.nativeHandle ?? 0n));
+ }
+
+ get type(): CaptureSourceType {
+ return native.native_capture_source_get_type(this.nativeHandle);
+ }
+
+ get name(): string {
+ return native.native_capture_source_get_name(this.nativeHandle);
+ }
+}
diff --git a/bindings/js/lib/modules.ts b/bindings/js/lib/modules.ts
index e99d60c1..950ceee2 100644
--- a/bindings/js/lib/modules.ts
+++ b/bindings/js/lib/modules.ts
@@ -22,6 +22,9 @@ export * from "./message_dialog.ts";
export * from "./file_dialog.ts";
export * from "./notification_manager.ts";
export * from "./image.ts";
+export * from "./capture_source.ts";
+export * from "./screen_capturer.ts";
+export * from "./screen_recorder.ts";
export * from "./window_shape.ts";
export * from "./window_shadow.ts";
export * from "./view.ts";
diff --git a/bindings/js/lib/screen_capturer.ts b/bindings/js/lib/screen_capturer.ts
new file mode 100644
index 00000000..f16d3900
--- /dev/null
+++ b/bindings/js/lib/screen_capturer.ts
@@ -0,0 +1,44 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+import { native, deliverEvent } from "./runtime.ts";
+import { CaptureSource, CaptureSourceType } from "./capture_source.ts";
+import { type Rectangle } from "./geometry.ts";
+import { Image } from "./image.ts";
+import { Window } from "./window.ts";
+
+export interface CaptureSourceSelectionOptions {
+ allowDisplays: boolean;
+ allowWindows: boolean;
+ parentWindow?: Window | null;
+}
+
+export interface ScreenCaptureOptions {
+ includeCursor: boolean;
+ cropEnabled: boolean;
+ crop: Rectangle;
+}
+
+export class ScreenCapturer {
+ private constructor() {}
+
+ static isSupported(): boolean {
+ return native.native_screen_capturer_is_supported();
+ }
+
+ static isSourceSelectionSupported(): boolean {
+ return native.native_screen_capturer_is_source_selection_supported();
+ }
+
+ static isDirectCaptureSupported(type: CaptureSourceType): boolean {
+ return native.native_screen_capturer_is_direct_capture_supported(type);
+ }
+
+ static selectSource(options: CaptureSourceSelectionOptions, callback: (arg0: boolean, arg1: CaptureSource | null) => void): void {
+ native.native_screen_capturer_select_source(({ ...options, parentWindow: options.parentWindow?.nativeHandle ?? 0n }), (arg0: any, arg1: any, delivery: bigint) => deliverEvent(delivery, () => [arg0, (arg1 ? new CaptureSource(native.retainHandle(arg1)) : null)] as const, (values) => callback(...values)));
+ }
+
+ static capture(source: CaptureSource | null, options: ScreenCaptureOptions, callback: (arg0: boolean, arg1: Image | null) => void): void {
+ native.native_screen_capturer_capture(source?.nativeHandle ?? 0n, ({ ...options, crop: options.crop }), (arg0: any, arg1: any, delivery: bigint) => deliverEvent(delivery, () => [arg0, (arg1 ? new Image(native.retainHandle(arg1)) : null)] as const, (values) => callback(...values)));
+ }
+}
diff --git a/bindings/js/lib/screen_recorder.ts b/bindings/js/lib/screen_recorder.ts
new file mode 100644
index 00000000..f517e1f5
--- /dev/null
+++ b/bindings/js/lib/screen_recorder.ts
@@ -0,0 +1,87 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+import { native, NativeObject, deliverEvent } from "./runtime.ts";
+import { CaptureSource } from "./capture_source.ts";
+import { type ScreenCaptureOptions } from "./screen_capturer.ts";
+
+export const ScreenRecordingState = {
+ Idle: 0,
+ Starting: 1,
+ Recording: 2,
+ Stopping: 3,
+ Completed: 4,
+ Cancelled: 5,
+ Failed: 6,
+} as const;
+export type ScreenRecordingState = (typeof ScreenRecordingState)[keyof typeof ScreenRecordingState];
+
+export interface ScreenRecordingOptions {
+ capture: ScreenCaptureOptions;
+ frameRate: number;
+ videoBitrate: number;
+}
+
+export type ScreenRecordingEvent =
+ | { type: "started" }
+ | { type: "completed"; filePath: string | null; duration: number }
+ | { type: "cancelled" }
+ | { type: "failed"; message: string | null };
+
+/** A native ScreenRecorder, held through an owned handle. */
+export class ScreenRecorder extends NativeObject {
+ /** Wraps a raw handle; an owned one is released on `dispose()` or collection. */
+ constructor(handle: bigint, owned = true) {
+ super(handle, owned ? native.native_screen_recorder_free : undefined);
+ }
+
+ static create(): ScreenRecorder | null {
+ const handle: bigint = native.native_screen_recorder_create();
+ return handle ? new ScreenRecorder(handle) : null;
+ }
+
+ static isSupported(): boolean {
+ return native.native_screen_recorder_is_supported();
+ }
+
+ start(source: CaptureSource | null, filePath: string, options: ScreenRecordingOptions): boolean {
+ return native.native_screen_recorder_start(this.nativeHandle, source?.nativeHandle ?? 0n, filePath, ({ ...options, capture: ({ ...options.capture, crop: options.capture.crop }) }));
+ }
+
+ stop(): boolean {
+ return native.native_screen_recorder_stop(this.nativeHandle);
+ }
+
+ cancel(): boolean {
+ return native.native_screen_recorder_cancel(this.nativeHandle);
+ }
+
+ get state(): ScreenRecordingState {
+ return native.native_screen_recorder_get_state(this.nativeHandle);
+ }
+
+ get isActive(): boolean {
+ return native.native_screen_recorder_is_active(this.nativeHandle);
+ }
+
+ get duration(): number {
+ return native.native_screen_recorder_get_duration(this.nativeHandle);
+ }
+
+ get filePath(): string {
+ return native.native_screen_recorder_get_file_path(this.nativeHandle);
+ }
+
+ /** Receives events on the JS thread. Borrowed objects stay valid until the returned Promise settles. */
+ addListener(listener: (event: ScreenRecordingEvent) => void | Promise): number {
+ return native.native_screen_recorder_add_listener(this.nativeHandle, (event: Record, delivery: bigint) =>
+ deliverEvent(delivery, () => {
+ return event as unknown as ScreenRecordingEvent;
+ }, listener));
+ }
+
+ /** Unregisters a listener; returns false if the id is unknown. */
+ removeListener(listenerId: number): boolean {
+ return native.native_screen_recorder_remove_listener(this.nativeHandle, listenerId);
+ }
+}
diff --git a/bindings/js/src/generated/capture_source.cc b/bindings/js/src/generated/capture_source.cc
new file mode 100644
index 00000000..77c4cb85
--- /dev/null
+++ b/bindings/js/src/generated/capture_source.cc
@@ -0,0 +1,96 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+#include "types.h"
+
+namespace nativeapi_js {
+namespace {
+
+napi_value Js_native_capture_source_free(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ uint64_t self = 0;
+ if (!GetHandle(env, args[0], &self)) {
+ return nullptr;
+ }
+ OnMainThread([&] { return native_capture_source_free(self); });
+ return Undefined(env);
+}
+
+napi_value Js_native_capture_source_from_display(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ native_display_t p0 = {};
+ if (!GetHandle(env, args[0], &p0)) {
+ return nullptr;
+ }
+ auto result = OnMainThread([&] { return native_capture_source_from_display(p0); });
+ return Value::BigInt(result).ToJs(env);
+}
+
+napi_value Js_native_capture_source_from_window(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ native_window_t p0 = {};
+ if (!GetHandle(env, args[0], &p0)) {
+ return nullptr;
+ }
+ auto result = OnMainThread([&] { return native_capture_source_from_window(p0); });
+ return Value::BigInt(result).ToJs(env);
+}
+
+napi_value Js_native_capture_source_get_type(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ uint64_t self = 0;
+ if (!GetHandle(env, args[0], &self)) {
+ return nullptr;
+ }
+ auto result = OnMainThread([&] { return native_capture_source_get_type(self); });
+ return Value::Number(static_cast(result)).ToJs(env);
+}
+
+napi_value Js_native_capture_source_get_name(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ uint64_t self = 0;
+ if (!GetHandle(env, args[0], &self)) {
+ return nullptr;
+ }
+ auto result = OnMainThread([&] { return native_capture_source_get_name(self); });
+ Value value = Value::String(result ? result : "");
+ free_c_str(result);
+ return value.ToJs(env);
+}
+
+} // namespace
+
+void RegisterCaptureSource(napi_env env, napi_value exports) {
+ Export(env, exports, "native_capture_source_free", Js_native_capture_source_free);
+ Export(env, exports, "native_capture_source_from_display", Js_native_capture_source_from_display);
+ Export(env, exports, "native_capture_source_from_window", Js_native_capture_source_from_window);
+ Export(env, exports, "native_capture_source_get_type", Js_native_capture_source_get_type);
+ Export(env, exports, "native_capture_source_get_name", Js_native_capture_source_get_name);
+}
+
+} // namespace nativeapi_js
diff --git a/bindings/js/src/generated/modules.cc b/bindings/js/src/generated/modules.cc
index bdf44935..e441a9b2 100644
--- a/bindings/js/src/generated/modules.cc
+++ b/bindings/js/src/generated/modules.cc
@@ -26,6 +26,9 @@ void RegisterMessageDialog(napi_env env, napi_value exports);
void RegisterFileDialog(napi_env env, napi_value exports);
void RegisterNotificationManager(napi_env env, napi_value exports);
void RegisterImage(napi_env env, napi_value exports);
+void RegisterCaptureSource(napi_env env, napi_value exports);
+void RegisterScreenCapturer(napi_env env, napi_value exports);
+void RegisterScreenRecorder(napi_env env, napi_value exports);
void RegisterWindowShape(napi_env env, napi_value exports);
void RegisterWindowShadow(napi_env env, napi_value exports);
void RegisterView(napi_env env, napi_value exports);
@@ -66,6 +69,9 @@ void RegisterGenerated(napi_env env, napi_value exports) {
RegisterFileDialog(env, exports);
RegisterNotificationManager(env, exports);
RegisterImage(env, exports);
+ RegisterCaptureSource(env, exports);
+ RegisterScreenCapturer(env, exports);
+ RegisterScreenRecorder(env, exports);
RegisterWindowShape(env, exports);
RegisterWindowShadow(env, exports);
RegisterView(env, exports);
diff --git a/bindings/js/src/generated/screen_capturer.cc b/bindings/js/src/generated/screen_capturer.cc
new file mode 100644
index 00000000..30c23d09
--- /dev/null
+++ b/bindings/js/src/generated/screen_capturer.cc
@@ -0,0 +1,98 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+#include "types.h"
+
+namespace nativeapi_js {
+namespace {
+
+napi_value Js_native_screen_capturer_is_supported(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ auto result = OnMainThread([&] { return native_screen_capturer_is_supported(); });
+ return Value::Bool(result).ToJs(env);
+}
+
+napi_value Js_native_screen_capturer_is_source_selection_supported(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ auto result = OnMainThread([&] { return native_screen_capturer_is_source_selection_supported(); });
+ return Value::Bool(result).ToJs(env);
+}
+
+napi_value Js_native_screen_capturer_is_direct_capture_supported(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ native_capture_source_type_t p0 = {};
+ if (!GetNumber(env, args[0], &p0)) {
+ return nullptr;
+ }
+ auto result = OnMainThread([&] { return native_screen_capturer_is_direct_capture_supported(p0); });
+ return Value::Bool(result).ToJs(env);
+}
+
+napi_value Js_native_screen_capturer_select_source(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ native_capture_source_selection_options_t p0 = {};
+ if (!FromJs(env, args[0], &p0, arena)) {
+ return nullptr;
+ }
+ Callback* p1 = nullptr;
+ if (!GetCallback(env, args[1], /*optional=*/false, &p1)) {
+ return nullptr;
+ }
+ OnMainThread([&] { return native_screen_capturer_select_source(p0, +[](bool arg0, native_capture_source_t arg1, native_event_delivery_t delivery, void* user_data) { Callback::DispatchEvent(user_data, {Value::Bool(arg0), Value::BigInt(arg1)}, delivery); }, p1, &Callback::ReleaseUserData); });
+ return Undefined(env);
+}
+
+napi_value Js_native_screen_capturer_capture(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ native_capture_source_t p0 = {};
+ if (!GetHandle(env, args[0], &p0)) {
+ return nullptr;
+ }
+ native_screen_capture_options_t p1 = {};
+ if (!FromJs(env, args[1], &p1, arena)) {
+ return nullptr;
+ }
+ Callback* p2 = nullptr;
+ if (!GetCallback(env, args[2], /*optional=*/false, &p2)) {
+ return nullptr;
+ }
+ OnMainThread([&] { return native_screen_capturer_capture(p0, p1, +[](bool arg0, native_image_t arg1, native_event_delivery_t delivery, void* user_data) { Callback::DispatchEvent(user_data, {Value::Bool(arg0), Value::BigInt(arg1)}, delivery); }, p2, &Callback::ReleaseUserData); });
+ return Undefined(env);
+}
+
+} // namespace
+
+void RegisterScreenCapturer(napi_env env, napi_value exports) {
+ Export(env, exports, "native_screen_capturer_is_supported", Js_native_screen_capturer_is_supported);
+ Export(env, exports, "native_screen_capturer_is_source_selection_supported", Js_native_screen_capturer_is_source_selection_supported);
+ Export(env, exports, "native_screen_capturer_is_direct_capture_supported", Js_native_screen_capturer_is_direct_capture_supported);
+ Export(env, exports, "native_screen_capturer_select_source", Js_native_screen_capturer_select_source);
+ Export(env, exports, "native_screen_capturer_capture", Js_native_screen_capturer_capture);
+}
+
+} // namespace nativeapi_js
diff --git a/bindings/js/src/generated/screen_recorder.cc b/bindings/js/src/generated/screen_recorder.cc
new file mode 100644
index 00000000..beb0626c
--- /dev/null
+++ b/bindings/js/src/generated/screen_recorder.cc
@@ -0,0 +1,221 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+#include "types.h"
+
+namespace nativeapi_js {
+namespace {
+
+napi_value Js_native_screen_recorder_create(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ auto result = OnMainThread([&] { return native_screen_recorder_create(); });
+ return Value::BigInt(result).ToJs(env);
+}
+
+napi_value Js_native_screen_recorder_free(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ uint64_t self = 0;
+ if (!GetHandle(env, args[0], &self)) {
+ return nullptr;
+ }
+ OnMainThread([&] { return native_screen_recorder_free(self); });
+ return Undefined(env);
+}
+
+napi_value Js_native_screen_recorder_is_supported(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ auto result = OnMainThread([&] { return native_screen_recorder_is_supported(); });
+ return Value::Bool(result).ToJs(env);
+}
+
+napi_value Js_native_screen_recorder_start(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ uint64_t self = 0;
+ if (!GetHandle(env, args[0], &self)) {
+ return nullptr;
+ }
+ native_capture_source_t p0 = {};
+ if (!GetHandle(env, args[1], &p0)) {
+ return nullptr;
+ }
+ const char* p1 = {};
+ if (!GetString(env, args[2], arena, &p1)) {
+ return nullptr;
+ }
+ native_screen_recording_options_t p2 = {};
+ if (!FromJs(env, args[3], &p2, arena)) {
+ return nullptr;
+ }
+ auto result = OnMainThread([&] { return native_screen_recorder_start(self, p0, p1, p2); });
+ return Value::Bool(result).ToJs(env);
+}
+
+napi_value Js_native_screen_recorder_stop(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ uint64_t self = 0;
+ if (!GetHandle(env, args[0], &self)) {
+ return nullptr;
+ }
+ auto result = OnMainThread([&] { return native_screen_recorder_stop(self); });
+ return Value::Bool(result).ToJs(env);
+}
+
+napi_value Js_native_screen_recorder_cancel(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ uint64_t self = 0;
+ if (!GetHandle(env, args[0], &self)) {
+ return nullptr;
+ }
+ auto result = OnMainThread([&] { return native_screen_recorder_cancel(self); });
+ return Value::Bool(result).ToJs(env);
+}
+
+napi_value Js_native_screen_recorder_get_state(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ uint64_t self = 0;
+ if (!GetHandle(env, args[0], &self)) {
+ return nullptr;
+ }
+ auto result = OnMainThread([&] { return native_screen_recorder_get_state(self); });
+ return Value::Number(static_cast(result)).ToJs(env);
+}
+
+napi_value Js_native_screen_recorder_is_active(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ uint64_t self = 0;
+ if (!GetHandle(env, args[0], &self)) {
+ return nullptr;
+ }
+ auto result = OnMainThread([&] { return native_screen_recorder_is_active(self); });
+ return Value::Bool(result).ToJs(env);
+}
+
+napi_value Js_native_screen_recorder_get_duration(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ uint64_t self = 0;
+ if (!GetHandle(env, args[0], &self)) {
+ return nullptr;
+ }
+ auto result = OnMainThread([&] { return native_screen_recorder_get_duration(self); });
+ return Value::Number(static_cast(result)).ToJs(env);
+}
+
+napi_value Js_native_screen_recorder_get_file_path(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ Arena arena;
+ (void)arena;
+ uint64_t self = 0;
+ if (!GetHandle(env, args[0], &self)) {
+ return nullptr;
+ }
+ auto result = OnMainThread([&] { return native_screen_recorder_get_file_path(self); });
+ Value value = Value::String(result ? result : "");
+ free_c_str(result);
+ return value.ToJs(env);
+}
+
+napi_value Js_native_screen_recorder_add_listener(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ uint64_t self = 0;
+ if (!GetHandle(env, args[0], &self)) {
+ return nullptr;
+ }
+ Callback* callback = nullptr;
+ if (!GetCallback(env, args[1], /*optional=*/false, &callback)) {
+ return nullptr;
+ }
+ native_listener_id_t id = OnMainThread([&] { return native_screen_recorder_add_listener_async(self, +[](const native_screen_recording_event_t* event, native_event_delivery_t delivery, void* user_data) {
+ if (event != nullptr) {
+ Callback::DispatchEvent(user_data, {ToValue(*event)}, delivery);
+ } else { native_event_delivery_complete(delivery, false); }
+ }, callback, &Callback::ReleaseUserData); });
+ if (id) Callback::AttachRegistration(callback, [self, id] { (void)native_screen_recorder_remove_listener(self, id); });
+ return Value::Number(static_cast(id)).ToJs(env);
+}
+
+napi_value Js_native_screen_recorder_remove_listener(napi_env env, napi_callback_info info) {
+ Args args(env, info);
+ if (!args.ok()) {
+ return nullptr;
+ }
+ uint64_t self = 0;
+ if (!GetHandle(env, args[0], &self)) {
+ return nullptr;
+ }
+ native_listener_id_t id = 0;
+ if (!GetNumber(env, args[1], &id)) {
+ return nullptr;
+ }
+ bool removed = OnMainThread([&] { return native_screen_recorder_remove_listener(self, id); });
+ return Value::Bool(removed).ToJs(env);
+}
+
+} // namespace
+
+void RegisterScreenRecorder(napi_env env, napi_value exports) {
+ Export(env, exports, "native_screen_recorder_create", Js_native_screen_recorder_create);
+ Export(env, exports, "native_screen_recorder_free", Js_native_screen_recorder_free);
+ Export(env, exports, "native_screen_recorder_is_supported", Js_native_screen_recorder_is_supported);
+ Export(env, exports, "native_screen_recorder_start", Js_native_screen_recorder_start);
+ Export(env, exports, "native_screen_recorder_stop", Js_native_screen_recorder_stop);
+ Export(env, exports, "native_screen_recorder_cancel", Js_native_screen_recorder_cancel);
+ Export(env, exports, "native_screen_recorder_get_state", Js_native_screen_recorder_get_state);
+ Export(env, exports, "native_screen_recorder_is_active", Js_native_screen_recorder_is_active);
+ Export(env, exports, "native_screen_recorder_get_duration", Js_native_screen_recorder_get_duration);
+ Export(env, exports, "native_screen_recorder_get_file_path", Js_native_screen_recorder_get_file_path);
+ Export(env, exports, "native_screen_recorder_add_listener", Js_native_screen_recorder_add_listener);
+ Export(env, exports, "native_screen_recorder_remove_listener", Js_native_screen_recorder_remove_listener);
+}
+
+} // namespace nativeapi_js
diff --git a/bindings/js/src/generated/types.h b/bindings/js/src/generated/types.h
index 33d3f829..27461aa0 100644
--- a/bindings/js/src/generated/types.h
+++ b/bindings/js/src/generated/types.h
@@ -26,6 +26,9 @@
#include "capi/file_dialog_c.h"
#include "capi/notification_manager_c.h"
#include "capi/image_c.h"
+#include "capi/capture_source_c.h"
+#include "capi/screen_capturer_c.h"
+#include "capi/screen_recorder_c.h"
#include "capi/window_shape_c.h"
#include "capi/window_shadow_c.h"
#include "capi/view_c.h"
@@ -67,6 +70,13 @@ inline Value ToValue(const native_url_open_result_t& value);
inline bool FromJs(napi_env env, napi_value value, native_url_open_result_t* out, Arena& arena);
inline Value ToValue(const native_protocol_handler_event_t& event);
inline Value ToValue(const native_notification_event_t& event);
+inline Value ToValue(const native_capture_source_selection_options_t& value);
+inline bool FromJs(napi_env env, napi_value value, native_capture_source_selection_options_t* out, Arena& arena);
+inline Value ToValue(const native_screen_capture_options_t& value);
+inline bool FromJs(napi_env env, napi_value value, native_screen_capture_options_t* out, Arena& arena);
+inline Value ToValue(const native_screen_recording_options_t& value);
+inline bool FromJs(napi_env env, napi_value value, native_screen_recording_options_t* out, Arena& arena);
+inline Value ToValue(const native_screen_recording_event_t& event);
inline Value ToValue(const native_text_range_t& value);
inline bool FromJs(napi_env env, napi_value value, native_text_range_t* out, Arena& arena);
inline Value ToValue(const native_view_event_t& event);
@@ -499,6 +509,150 @@ inline Value ToValue(const native_notification_event_t& event) {
return result;
}
+inline Value ToValue(const native_capture_source_selection_options_t& value) {
+ Value result = Value::Object();
+ result.Set("allowDisplays", Value::Bool(value.allow_displays));
+ result.Set("allowWindows", Value::Bool(value.allow_windows));
+ result.Set("parentWindow", Value::BigInt(value.parent_window));
+ return result;
+}
+
+inline bool FromJs(napi_env env, napi_value value, native_capture_source_selection_options_t* out, Arena& arena) {
+ if (!ExpectObject(env, value, "CaptureSourceSelectionOptions")) {
+ return false;
+ }
+ napi_value field = nullptr;
+ if (!GetField(env, value, "allowDisplays", &field)) {
+ return false;
+ }
+ if (field != nullptr) {
+ if (!GetBool(env, field, &out->allow_displays)) {
+ return false;
+ }
+ }
+ if (!GetField(env, value, "allowWindows", &field)) {
+ return false;
+ }
+ if (field != nullptr) {
+ if (!GetBool(env, field, &out->allow_windows)) {
+ return false;
+ }
+ }
+ if (!GetField(env, value, "parentWindow", &field)) {
+ return false;
+ }
+ if (field != nullptr) {
+ if (!GetHandle(env, field, &out->parent_window)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+inline Value ToValue(const native_screen_capture_options_t& value) {
+ Value result = Value::Object();
+ result.Set("includeCursor", Value::Bool(value.include_cursor));
+ result.Set("cropEnabled", Value::Bool(value.crop_enabled));
+ result.Set("crop", ToValue(value.crop));
+ return result;
+}
+
+inline bool FromJs(napi_env env, napi_value value, native_screen_capture_options_t* out, Arena& arena) {
+ if (!ExpectObject(env, value, "ScreenCaptureOptions")) {
+ return false;
+ }
+ napi_value field = nullptr;
+ if (!GetField(env, value, "includeCursor", &field)) {
+ return false;
+ }
+ if (field != nullptr) {
+ if (!GetBool(env, field, &out->include_cursor)) {
+ return false;
+ }
+ }
+ if (!GetField(env, value, "cropEnabled", &field)) {
+ return false;
+ }
+ if (field != nullptr) {
+ if (!GetBool(env, field, &out->crop_enabled)) {
+ return false;
+ }
+ }
+ if (!GetField(env, value, "crop", &field)) {
+ return false;
+ }
+ if (field != nullptr) {
+ if (!FromJs(env, field, &out->crop, arena)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+inline Value ToValue(const native_screen_recording_options_t& value) {
+ Value result = Value::Object();
+ result.Set("capture", ToValue(value.capture));
+ result.Set("frameRate", Value::Number(static_cast(value.frame_rate)));
+ result.Set("videoBitrate", Value::Number(static_cast(value.video_bitrate)));
+ return result;
+}
+
+inline bool FromJs(napi_env env, napi_value value, native_screen_recording_options_t* out, Arena& arena) {
+ if (!ExpectObject(env, value, "ScreenRecordingOptions")) {
+ return false;
+ }
+ napi_value field = nullptr;
+ if (!GetField(env, value, "capture", &field)) {
+ return false;
+ }
+ if (field != nullptr) {
+ if (!FromJs(env, field, &out->capture, arena)) {
+ return false;
+ }
+ }
+ if (!GetField(env, value, "frameRate", &field)) {
+ return false;
+ }
+ if (field != nullptr) {
+ if (!GetNumber(env, field, &out->frame_rate)) {
+ return false;
+ }
+ }
+ if (!GetField(env, value, "videoBitrate", &field)) {
+ return false;
+ }
+ if (field != nullptr) {
+ if (!GetNumber(env, field, &out->video_bitrate)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+inline Value ToValue(const native_screen_recording_event_t& event) {
+ Value result = Value::Object();
+ switch (event.type) {
+ case NATIVE_SCREEN_RECORDING_EVENT_TYPE_STARTED:
+ result.Set("type", Value::String("started"));
+ break;
+ case NATIVE_SCREEN_RECORDING_EVENT_TYPE_COMPLETED:
+ result.Set("type", Value::String("completed"));
+ result.Set("filePath", Value::String(event.data.completed.file_path));
+ result.Set("duration", Value::Number(static_cast(event.data.completed.duration)));
+ break;
+ case NATIVE_SCREEN_RECORDING_EVENT_TYPE_CANCELLED:
+ result.Set("type", Value::String("cancelled"));
+ break;
+ case NATIVE_SCREEN_RECORDING_EVENT_TYPE_FAILED:
+ result.Set("type", Value::String("failed"));
+ result.Set("message", Value::String(event.data.failed.message));
+ break;
+ default:
+ return Value::Null();
+ }
+ return result;
+}
+
inline Value ToValue(const native_text_range_t& value) {
Value result = Value::Object();
result.Set("start", Value::Number(static_cast(value.start)));
diff --git a/bindings/js/test/screen_capture.test.ts b/bindings/js/test/screen_capture.test.ts
new file mode 100644
index 00000000..8b5ccf79
--- /dev/null
+++ b/bindings/js/test/screen_capture.test.ts
@@ -0,0 +1,28 @@
+// No UI or permission request: real addon conversions and rejected lifecycle.
+import assert from "node:assert/strict";
+import { test } from "node:test";
+import { CaptureSourceType, ScreenCapturer, ScreenRecorder, ScreenRecordingState } from "../lib/index.ts";
+
+test("static capture entry rejects invalid direct types", () => {
+ assert.equal(ScreenCapturer.isDirectCaptureSupported(CaptureSourceType.None), false);
+ assert.equal(ScreenCapturer.isDirectCaptureSupported(CaptureSourceType.Unknown), false);
+});
+
+test("nested recording options cross the ABI without creating an output", () => {
+ const recorder = ScreenRecorder.create()!;
+ try {
+ assert.equal(recorder.state, ScreenRecordingState.Idle);
+ assert.equal(recorder.start(null, "relative.mp4", {
+ capture: { includeCursor: false, cropEnabled: true, crop: { x: 1, y: 2, width: 32, height: 48 } },
+ frameRate: 30,
+ videoBitrate: 1_000_000,
+ }), false);
+ assert.equal(recorder.state, ScreenRecordingState.Idle);
+ assert.equal(recorder.isActive, false);
+ assert.equal(recorder.duration, 0);
+ assert.equal(recorder.stop(), false);
+ assert.equal(recorder.cancel(), false);
+ } finally {
+ recorder.dispose();
+ }
+});
diff --git a/bindings/python/nativeapi/__init__.py b/bindings/python/nativeapi/__init__.py
index 50f66cab..0a83e331 100644
--- a/bindings/python/nativeapi/__init__.py
+++ b/bindings/python/nativeapi/__init__.py
@@ -26,6 +26,10 @@
ApplicationSystemBrightnessChangedEvent,
Brightness,
)
+from .capture_source import (
+ CaptureSource,
+ CaptureSourceType,
+)
from .clipboard import (
Clipboard,
ClipboardChangedEvent,
@@ -138,6 +142,21 @@
ProtocolHandlerEvent,
ProtocolUrlReceivedEvent,
)
+from .screen_capturer import (
+ CaptureSourceSelectionOptions,
+ ScreenCaptureOptions,
+ ScreenCapturer,
+)
+from .screen_recorder import (
+ ScreenRecorder,
+ ScreenRecordingCancelledEvent,
+ ScreenRecordingCompletedEvent,
+ ScreenRecordingEvent,
+ ScreenRecordingFailedEvent,
+ ScreenRecordingOptions,
+ ScreenRecordingStartedEvent,
+ ScreenRecordingState,
+)
from .secure_storage import (
SecureStorage,
)
@@ -267,6 +286,9 @@
"Brightness",
"Button",
"ButtonClickedEvent",
+ "CaptureSource",
+ "CaptureSourceSelectionOptions",
+ "CaptureSourceType",
"Clipboard",
"ClipboardChangedEvent",
"ClipboardData",
@@ -340,6 +362,16 @@
"ProtocolUrlReceivedEvent",
"Rectangle",
"ResizeEdge",
+ "ScreenCaptureOptions",
+ "ScreenCapturer",
+ "ScreenRecorder",
+ "ScreenRecordingCancelledEvent",
+ "ScreenRecordingCompletedEvent",
+ "ScreenRecordingEvent",
+ "ScreenRecordingFailedEvent",
+ "ScreenRecordingOptions",
+ "ScreenRecordingStartedEvent",
+ "ScreenRecordingState",
"SecureStorage",
"Shortcut",
"ShortcutActivatedEvent",
diff --git a/bindings/python/nativeapi/_capi.py b/bindings/python/nativeapi/_capi.py
index 82638183..19bda99e 100644
--- a/bindings/python/nativeapi/_capi.py
+++ b/bindings/python/nativeapi/_capi.py
@@ -134,6 +134,34 @@ class native_notification_event_t(Structure):
pass
+class native_capture_source_selection_options_t(Structure):
+ pass
+
+
+class native_screen_capture_options_t(Structure):
+ pass
+
+
+class native_screen_recording_options_t(Structure):
+ pass
+
+
+class native_screen_recording_event_completed_t(Structure):
+ pass
+
+
+class native_screen_recording_event_failed_t(Structure):
+ pass
+
+
+class native_screen_recording_event_data_t(Union):
+ pass
+
+
+class native_screen_recording_event_t(Structure):
+ pass
+
+
class native_text_range_t(Structure):
pass
@@ -357,6 +385,13 @@ class native_window_list_t(Structure):
POINTER(native_application_event_t),
c_void_p,
)
+native_callback_bool_capture_source_payload_t = CFUNCTYPE(
+ None,
+ c_bool,
+ c_uint64,
+ c_uint64,
+ c_void_p,
+)
native_callback_bool_clipboard_data_payload_t = CFUNCTYPE(
None,
c_bool,
@@ -422,6 +457,11 @@ class native_window_list_t(Structure):
c_void_p,
)
native_release_user_data_t = CFUNCTYPE(None, c_void_p)
+native_screen_recording_event_callback_t = CFUNCTYPE(
+ None,
+ POINTER(native_screen_recording_event_t),
+ c_void_p,
+)
native_shortcut_event_callback_t = CFUNCTYPE(
None,
POINTER(native_shortcut_event_t),
@@ -533,6 +573,36 @@ class native_window_list_t(Structure):
("type", c_int),
("data", native_notification_event_data_t),
]
+native_capture_source_selection_options_t._fields_ = [
+ ("allow_displays", c_bool),
+ ("allow_windows", c_bool),
+ ("parent_window", c_uint64),
+]
+native_screen_capture_options_t._fields_ = [
+ ("include_cursor", c_bool),
+ ("crop_enabled", c_bool),
+ ("crop", native_rectangle_t),
+]
+native_screen_recording_options_t._fields_ = [
+ ("capture", native_screen_capture_options_t),
+ ("frame_rate", c_double),
+ ("video_bitrate", c_ulong),
+]
+native_screen_recording_event_completed_t._fields_ = [
+ ("file_path", c_char_p),
+ ("duration", c_double),
+]
+native_screen_recording_event_failed_t._fields_ = [
+ ("message", c_char_p),
+]
+native_screen_recording_event_data_t._fields_ = [
+ ("completed", native_screen_recording_event_completed_t),
+ ("failed", native_screen_recording_event_failed_t),
+]
+native_screen_recording_event_t._fields_ = [
+ ("type", c_int),
+ ("data", native_screen_recording_event_data_t),
+]
native_text_range_t._fields_ = [
("start", c_ulong),
("length", c_ulong),
@@ -1852,6 +1922,183 @@ class native_window_list_t(Structure):
],
)
+# capture_source.h
+
+native_capture_source_free = function("native_capture_source_free", None, [c_uint64])
+native_capture_source_from_display = function(
+ "native_capture_source_from_display",
+ c_uint64,
+ [
+ c_uint64,
+ ],
+)
+native_capture_source_from_window = function(
+ "native_capture_source_from_window",
+ c_uint64,
+ [
+ c_uint64,
+ ],
+)
+native_capture_source_get_type = function(
+ "native_capture_source_get_type",
+ c_int,
+ [
+ c_uint64,
+ ],
+)
+native_capture_source_get_name = function(
+ "native_capture_source_get_name",
+ c_void_p,
+ [
+ c_uint64,
+ ],
+)
+
+# screen_capturer.h
+
+native_capture_source_selection_options_free = function(
+ "native_capture_source_selection_options_free",
+ None,
+ [
+ POINTER(native_capture_source_selection_options_t),
+ ],
+)
+native_screen_capture_options_free = function(
+ "native_screen_capture_options_free",
+ None,
+ [
+ POINTER(native_screen_capture_options_t),
+ ],
+)
+native_screen_capturer_is_supported = function(
+ "native_screen_capturer_is_supported",
+ c_bool,
+ [
+ ],
+)
+native_screen_capturer_is_source_selection_supported = function(
+ "native_screen_capturer_is_source_selection_supported",
+ c_bool,
+ [
+ ],
+)
+native_screen_capturer_is_direct_capture_supported = function(
+ "native_screen_capturer_is_direct_capture_supported",
+ c_bool,
+ [
+ c_int,
+ ],
+)
+native_screen_capturer_select_source = function(
+ "native_screen_capturer_select_source",
+ None,
+ [
+ native_capture_source_selection_options_t,
+ native_callback_bool_capture_source_payload_t,
+ c_void_p,
+ native_release_user_data_t,
+ ],
+)
+native_screen_capturer_capture = function(
+ "native_screen_capturer_capture",
+ None,
+ [
+ c_uint64,
+ native_screen_capture_options_t,
+ native_callback_bool_image_payload_t,
+ c_void_p,
+ native_release_user_data_t,
+ ],
+)
+
+# screen_recorder.h
+
+native_screen_recording_options_free = function(
+ "native_screen_recording_options_free",
+ None,
+ [
+ POINTER(native_screen_recording_options_t),
+ ],
+)
+native_screen_recorder_free = function("native_screen_recorder_free", None, [c_uint64])
+native_screen_recorder_create = function("native_screen_recorder_create", c_uint64, [])
+native_screen_recorder_is_supported = function(
+ "native_screen_recorder_is_supported",
+ c_bool,
+ [
+ ],
+)
+native_screen_recorder_start = function(
+ "native_screen_recorder_start",
+ c_bool,
+ [
+ c_uint64,
+ c_uint64,
+ c_char_p,
+ native_screen_recording_options_t,
+ ],
+)
+native_screen_recorder_stop = function(
+ "native_screen_recorder_stop",
+ c_bool,
+ [
+ c_uint64,
+ ],
+)
+native_screen_recorder_cancel = function(
+ "native_screen_recorder_cancel",
+ c_bool,
+ [
+ c_uint64,
+ ],
+)
+native_screen_recorder_get_state = function(
+ "native_screen_recorder_get_state",
+ c_int,
+ [
+ c_uint64,
+ ],
+)
+native_screen_recorder_is_active = function(
+ "native_screen_recorder_is_active",
+ c_bool,
+ [
+ c_uint64,
+ ],
+)
+native_screen_recorder_get_duration = function(
+ "native_screen_recorder_get_duration",
+ c_double,
+ [
+ c_uint64,
+ ],
+)
+native_screen_recorder_get_file_path = function(
+ "native_screen_recorder_get_file_path",
+ c_void_p,
+ [
+ c_uint64,
+ ],
+)
+native_screen_recorder_add_listener = function(
+ "native_screen_recorder_add_listener",
+ c_uint64,
+ [
+ c_uint64,
+ native_screen_recording_event_callback_t,
+ c_void_p,
+ native_release_user_data_t,
+ ],
+)
+native_screen_recorder_remove_listener = function(
+ "native_screen_recorder_remove_listener",
+ c_bool,
+ [
+ c_uint64,
+ c_uint64,
+ ],
+)
+
# window_shape.h
native_window_shape_free = function("native_window_shape_free", None, [c_uint64])
diff --git a/bindings/python/nativeapi/capture_source.py b/bindings/python/nativeapi/capture_source.py
new file mode 100644
index 00000000..a6cae08e
--- /dev/null
+++ b/bindings/python/nativeapi/capture_source.py
@@ -0,0 +1,50 @@
+# AUTO-GENERATED. DO NOT EDIT.
+# Any manual changes WILL BE LOST when this file is regenerated.
+"""Generated from capture_source.h."""
+
+from __future__ import annotations
+
+import enum
+
+from . import _capi as _C
+from . import _runtime as _rt
+from . import display as _display
+from . import window as _window
+
+
+class CaptureSourceType(enum.IntEnum):
+ NONE = 0
+ DISPLAY = 1
+ WINDOW = 2
+ UNKNOWN = 3
+
+
+class CaptureSource(_rt.NativeObject):
+ """Owned reference to a native CaptureSource.
+
+ `dispose()` (or `with`) releases it; otherwise it is released when the
+ wrapper is garbage collected.
+ """
+
+ __slots__ = ()
+ _free = staticmethod(_C.native_capture_source_free)
+
+ @staticmethod
+ def from_display(display: _display.Display | None) -> CaptureSource | None:
+ raw = _C.native_capture_source_from_display(_rt.handle_of(display))
+ return CaptureSource._owned(raw)
+
+ @staticmethod
+ def from_window(window: _window.Window | None) -> CaptureSource | None:
+ raw = _C.native_capture_source_from_window(_rt.handle_of(window))
+ return CaptureSource._owned(raw)
+
+ @property
+ def type(self) -> CaptureSourceType:
+ raw = _C.native_capture_source_get_type(self._handle)
+ return _rt.to_enum(CaptureSourceType, raw)
+
+ @property
+ def name(self) -> str:
+ raw = _C.native_capture_source_get_name(self._handle)
+ return _rt.take_str(raw)
diff --git a/bindings/python/nativeapi/screen_capturer.py b/bindings/python/nativeapi/screen_capturer.py
new file mode 100644
index 00000000..ec04c18f
--- /dev/null
+++ b/bindings/python/nativeapi/screen_capturer.py
@@ -0,0 +1,128 @@
+# AUTO-GENERATED. DO NOT EDIT.
+# Any manual changes WILL BE LOST when this file is regenerated.
+"""Generated from screen_capturer.h."""
+
+from __future__ import annotations
+
+from collections.abc import Callable
+from dataclasses import dataclass, field
+
+from . import _capi as _C
+from . import _runtime as _rt
+from . import capture_source as _capture_source
+from . import geometry as _geometry
+from . import image as _image
+from . import window as _window
+
+
+@dataclass
+class CaptureSourceSelectionOptions:
+ allow_displays: bool = False
+ allow_windows: bool = False
+ parent_window: _window.Window | None = None
+
+ @classmethod
+ def _from_c(
+ cls,
+ raw: _C.native_capture_source_selection_options_t,
+ ) -> CaptureSourceSelectionOptions:
+ return cls(
+ bool(raw.allow_displays),
+ bool(raw.allow_windows),
+ _window.Window._owned(_rt.retain_handle(raw.parent_window)),
+ )
+
+ def _to_c(self) -> _C.native_capture_source_selection_options_t:
+ raw = _C.native_capture_source_selection_options_t()
+ raw.allow_displays = self.allow_displays
+ raw.allow_windows = self.allow_windows
+ raw.parent_window = _rt.handle_of(self.parent_window)
+ return raw
+
+
+@dataclass
+class ScreenCaptureOptions:
+ include_cursor: bool = False
+ crop_enabled: bool = False
+ crop: _geometry.Rectangle = field(default_factory=lambda: _geometry.Rectangle())
+
+ @classmethod
+ def _from_c(cls, raw: _C.native_screen_capture_options_t) -> ScreenCaptureOptions:
+ return cls(
+ bool(raw.include_cursor),
+ bool(raw.crop_enabled),
+ _geometry.Rectangle._from_c(raw.crop),
+ )
+
+ def _to_c(self) -> _C.native_screen_capture_options_t:
+ raw = _C.native_screen_capture_options_t()
+ raw.include_cursor = self.include_cursor
+ raw.crop_enabled = self.crop_enabled
+ raw.crop = self.crop._to_c()
+ return raw
+
+
+class ScreenCapturer:
+ def __init__(self) -> None:
+ raise TypeError("ScreenCapturer contains only static methods")
+
+ @staticmethod
+ def is_supported() -> bool:
+ raw = _C.native_screen_capturer_is_supported()
+ return raw
+
+ @staticmethod
+ def is_source_selection_supported() -> bool:
+ raw = _C.native_screen_capturer_is_source_selection_supported()
+ return raw
+
+ @staticmethod
+ def is_direct_capture_supported(type: _capture_source.CaptureSourceType) -> bool:
+ raw = _C.native_screen_capturer_is_direct_capture_supported(int(type))
+ return raw
+
+ @staticmethod
+ def select_source(
+ options: CaptureSourceSelectionOptions,
+ callback: Callable[[bool, _capture_source.CaptureSource | None], None],
+ ) -> None:
+ native_callback = _rt.make_callback(
+ _C.native_callback_bool_capture_source_payload_t,
+ lambda a0, a1, delivery, _user_data: _rt.deliver_callback(
+ delivery,
+ lambda: callback(
+ bool(a0),
+ _capture_source.CaptureSource._owned(_rt.retain_handle(a1))
+ ),
+ ),
+ )
+ _C.native_screen_capturer_select_source(
+ options._to_c(),
+ native_callback,
+ _rt.user_data(native_callback),
+ _rt.release_user_data,
+ )
+
+ @staticmethod
+ def capture(
+ source: _capture_source.CaptureSource | None,
+ options: ScreenCaptureOptions,
+ callback: Callable[[bool, _image.Image | None], None],
+ ) -> None:
+ native_callback = _rt.make_callback(
+ _C.native_callback_bool_image_payload_t,
+ lambda a0, a1, delivery, _user_data: _rt.deliver_callback(
+ delivery,
+ lambda: callback(
+ bool(a0),
+ _image.Image._owned(_rt.retain_handle(a1))
+ ),
+ ),
+ )
+ _C.native_screen_capturer_capture(
+ _rt.handle_of(source),
+ options._to_c(),
+ native_callback,
+ _rt.user_data(native_callback),
+ _rt.release_user_data,
+ )
diff --git a/bindings/python/nativeapi/screen_recorder.py b/bindings/python/nativeapi/screen_recorder.py
new file mode 100644
index 00000000..d2634ce8
--- /dev/null
+++ b/bindings/python/nativeapi/screen_recorder.py
@@ -0,0 +1,184 @@
+# AUTO-GENERATED. DO NOT EDIT.
+# Any manual changes WILL BE LOST when this file is regenerated.
+"""Generated from screen_recorder.h."""
+
+from __future__ import annotations
+
+import enum
+from collections.abc import Callable
+from dataclasses import dataclass, field
+
+from . import _capi as _C
+from . import _runtime as _rt
+from . import capture_source as _capture_source
+from . import screen_capturer as _screen_capturer
+
+
+class ScreenRecordingState(enum.IntEnum):
+ IDLE = 0
+ STARTING = 1
+ RECORDING = 2
+ STOPPING = 3
+ COMPLETED = 4
+ CANCELLED = 5
+ FAILED = 6
+
+
+@dataclass
+class ScreenRecordingOptions:
+ capture: _screen_capturer.ScreenCaptureOptions = (
+ field(default_factory=lambda: _screen_capturer.ScreenCaptureOptions())
+ )
+ frame_rate: float = 0.0
+ video_bitrate: int = 0
+
+ @classmethod
+ def _from_c(
+ cls,
+ raw: _C.native_screen_recording_options_t,
+ ) -> ScreenRecordingOptions:
+ return cls(
+ _screen_capturer.ScreenCaptureOptions._from_c(raw.capture),
+ raw.frame_rate,
+ raw.video_bitrate,
+ )
+
+ def _to_c(self) -> _C.native_screen_recording_options_t:
+ raw = _C.native_screen_recording_options_t()
+ raw.capture = self.capture._to_c()
+ raw.frame_rate = self.frame_rate
+ raw.video_bitrate = self.video_bitrate
+ return raw
+
+
+@dataclass(frozen=True)
+class ScreenRecordingEvent:
+ """Base of every ScreenRecordingEvent; listeners receive one of its subclasses."""
+
+ @staticmethod
+ def _from_c(raw: _C.native_screen_recording_event_t) -> ScreenRecordingEvent | None:
+ if raw.type == 0:
+ return ScreenRecordingStartedEvent()
+ if raw.type == 1:
+ return ScreenRecordingCompletedEvent(
+ _rt.decode(raw.data.completed.file_path),
+ raw.data.completed.duration,
+ )
+ if raw.type == 2:
+ return ScreenRecordingCancelledEvent()
+ if raw.type == 3:
+ return ScreenRecordingFailedEvent(_rt.decode(raw.data.failed.message))
+ return None
+
+
+@dataclass(frozen=True)
+class ScreenRecordingStartedEvent(ScreenRecordingEvent):
+ pass
+
+
+@dataclass(frozen=True)
+class ScreenRecordingCompletedEvent(ScreenRecordingEvent):
+ file_path: str
+ duration: float
+
+
+@dataclass(frozen=True)
+class ScreenRecordingCancelledEvent(ScreenRecordingEvent):
+ pass
+
+
+@dataclass(frozen=True)
+class ScreenRecordingFailedEvent(ScreenRecordingEvent):
+ message: str
+
+
+class ScreenRecorder(_rt.NativeObject):
+ """Owned reference to a native ScreenRecorder.
+
+ `dispose()` (or `with`) releases it; otherwise it is released when the
+ wrapper is garbage collected.
+ """
+
+ __slots__ = ()
+ _free = staticmethod(_C.native_screen_recorder_free)
+
+ def __init__(self) -> None:
+ handle = _C.native_screen_recorder_create()
+ if not handle:
+ raise _rt.NativeApiError("failed to create a ScreenRecorder")
+ self._adopt(handle)
+
+ @staticmethod
+ def is_supported() -> bool:
+ raw = _C.native_screen_recorder_is_supported()
+ return raw
+
+ def start(
+ self,
+ source: _capture_source.CaptureSource | None,
+ file_path: str,
+ options: ScreenRecordingOptions,
+ ) -> bool:
+ raw = _C.native_screen_recorder_start(
+ self._handle,
+ _rt.handle_of(source),
+ _rt.encode(file_path),
+ options._to_c(),
+ )
+ return raw
+
+ def stop(self) -> bool:
+ raw = _C.native_screen_recorder_stop(self._handle)
+ return raw
+
+ def cancel(self) -> bool:
+ raw = _C.native_screen_recorder_cancel(self._handle)
+ return raw
+
+ @property
+ def state(self) -> ScreenRecordingState:
+ raw = _C.native_screen_recorder_get_state(self._handle)
+ return _rt.to_enum(ScreenRecordingState, raw)
+
+ @property
+ def is_active(self) -> bool:
+ raw = _C.native_screen_recorder_is_active(self._handle)
+ return raw
+
+ @property
+ def duration(self) -> float:
+ raw = _C.native_screen_recorder_get_duration(self._handle)
+ return raw
+
+ @property
+ def file_path(self) -> str:
+ raw = _C.native_screen_recorder_get_file_path(self._handle)
+ return _rt.take_str(raw)
+
+ def add_listener(self, callback: Callable[[ScreenRecordingEvent], None]) -> int:
+ """Calls `callback` with every ScreenRecordingEvent this ScreenRecorder emits.
+
+ Callbacks run synchronously; coroutine callbacks are not accepted.
+ Use an owned EventDecision for asynchronous request confirmation.
+ Returns the listener id for `remove_listener()`.
+ """
+
+ def trampoline(raw, _user_data):
+ event = ScreenRecordingEvent._from_c(raw.contents)
+ if event is not None:
+ _rt.deliver_event(callback, event)
+
+ return _rt.add_listener(
+ _C.native_screen_recorder_add_listener,
+ _C.native_screen_recording_event_callback_t,
+ trampoline,
+ self._handle,
+ )
+
+ def remove_listener(self, listener_id: int) -> bool:
+ """Unregisters a listener. Returns False if unknown."""
+ return _rt.remove_listener(
+ _C.native_screen_recorder_remove_listener,
+ listener_id,
+ self._handle,
+ )
diff --git a/bindings/python/tests/test_screen_capture.py b/bindings/python/tests/test_screen_capture.py
new file mode 100644
index 00000000..6b13ca9b
--- /dev/null
+++ b/bindings/python/tests/test_screen_capture.py
@@ -0,0 +1,35 @@
+"""No capture/UI: validate nested options and recorder state across the real ABI."""
+
+import pytest
+
+from nativeapi import (
+ CaptureSourceType,
+ Rectangle,
+ ScreenCaptureOptions,
+ ScreenCapturer,
+ ScreenRecorder,
+ ScreenRecordingOptions,
+ ScreenRecordingState,
+)
+
+
+def test_static_entry_and_invalid_direct_types():
+ with pytest.raises(TypeError):
+ ScreenCapturer()
+ assert not ScreenCapturer.is_direct_capture_supported(CaptureSourceType.NONE)
+ assert not ScreenCapturer.is_direct_capture_supported(CaptureSourceType.UNKNOWN)
+
+
+def test_nested_options_rejection_keeps_idle_recorder():
+ capture = ScreenCaptureOptions(False, True, Rectangle(1, 2, 32, 48))
+ options = ScreenRecordingOptions(capture, 30.0, 1_000_000)
+ # Exercises the actual nested ctypes value conversion independently of a
+ # desktop/permission; a relative destination is rejected before any capture.
+ with ScreenRecorder() as recorder:
+ assert recorder.state == ScreenRecordingState.IDLE
+ assert not recorder.start(None, "relative.mp4", options)
+ assert recorder.state == ScreenRecordingState.IDLE
+ assert recorder.duration == 0
+ assert not recorder.is_active
+ assert not recorder.stop()
+ assert not recorder.cancel()
diff --git a/bindings/rust/cnativeapi/build.rs b/bindings/rust/cnativeapi/build.rs
index 83a32116..7ed640e4 100644
--- a/bindings/rust/cnativeapi/build.rs
+++ b/bindings/rust/cnativeapi/build.rs
@@ -34,6 +34,39 @@ fn main() {
match target_os.as_str() {
"macos" => {
cmake_config.define("CMAKE_SYSTEM_NAME", "Darwin");
+ // Match Rust's deployment target so availability-annotated native
+ // APIs remain weak imports on older macOS versions.
+ println!("cargo:rerun-if-env-changed=MACOSX_DEPLOYMENT_TARGET");
+ let deployment_target = env::var("MACOSX_DEPLOYMENT_TARGET")
+ .ok()
+ .or_else(|| {
+ let output = std::process::Command::new(env::var("RUSTC").ok()?)
+ .args([
+ "--print",
+ "deployment-target",
+ "--target",
+ &env::var("TARGET").ok()?,
+ ])
+ .output()
+ .ok()?;
+ if !output.status.success() {
+ return None;
+ }
+ String::from_utf8(output.stdout)
+ .ok()?
+ .trim()
+ .split_once('=')
+ .map(|(_, value)| value.to_owned())
+ })
+ .unwrap_or_else(|| {
+ if _target_arch == "aarch64" {
+ "11.0"
+ } else {
+ "10.12"
+ }
+ .into()
+ });
+ cmake_config.define("CMAKE_OSX_DEPLOYMENT_TARGET", deployment_target);
// The Objective-C++ implementations rely on ARC to retain native
// objects across the host's autorelease pools (notably tray items).
cmake_config.define("CMAKE_OBJCXX_FLAGS", "-fobjc-arc");
@@ -46,6 +79,11 @@ fn main() {
println!("cargo:rustc-link-lib=framework=Carbon");
println!("cargo:rustc-link-lib=framework=IOKit");
println!("cargo:rustc-link-lib=framework=ServiceManagement");
+ // ScreenCaptureKit is autolinked by the capture object so apps not
+ // using capture do not acquire an unconditional SCK dependency.
+ for framework in ["AVFoundation", "CoreMedia", "CoreVideo", "VideoToolbox"] {
+ println!("cargo:rustc-link-lib=framework={framework}");
+ }
}
"ios" => {
cmake_config.define("CMAKE_SYSTEM_NAME", "iOS");
@@ -78,7 +116,22 @@ fn main() {
println!("cargo:rustc-link-lib=dwmapi");
println!("cargo:rustc-link-lib=gdiplus");
println!("cargo:rustc-link-lib=crypt32");
- for library in ["comctl32", "advapi32", "version", "ole32", "uuid", "gdi32"] {
+ for library in [
+ "comctl32",
+ "advapi32",
+ "version",
+ "ole32",
+ "uuid",
+ "gdi32",
+ "d3d11",
+ "dxgi",
+ "windowsapp",
+ "runtimeobject",
+ "mfplat",
+ "mfreadwrite",
+ "mfuuid",
+ "windowscodecs",
+ ] {
println!("cargo:rustc-link-lib={library}");
}
}
diff --git a/bindings/rust/cnativeapi/src/bindings.rs b/bindings/rust/cnativeapi/src/bindings.rs
index e853f0fe..9b2b9f0b 100644
--- a/bindings/rust/cnativeapi/src/bindings.rs
+++ b/bindings/rust/cnativeapi/src/bindings.rs
@@ -173,12 +173,28 @@ pub struct native_edge_insets_t {
pub bottom: f64,
pub left: f64,
}
+unsafe extern "C" {
+ #[doc = " Frees everything the struct owns."]
+ pub fn native_point_free(value: *mut native_point_t);
+}
+unsafe extern "C" {
+ #[doc = " Frees everything the struct owns."]
+ pub fn native_size_free(value: *mut native_size_t);
+}
+unsafe extern "C" {
+ #[doc = " Frees everything the struct owns."]
+ pub fn native_rectangle_free(value: *mut native_rectangle_t);
+}
unsafe extern "C" {
pub fn native_edge_insets_all(value: f64) -> native_edge_insets_t;
}
unsafe extern "C" {
pub fn native_edge_insets_symmetric(vertical: f64, horizontal: f64) -> native_edge_insets_t;
}
+unsafe extern "C" {
+ #[doc = " Frees everything the struct owns."]
+ pub fn native_edge_insets_free(value: *mut native_edge_insets_t);
+}
unsafe extern "C" {
#[doc = " Caller owns the returned handle; release it with native_image_free()."]
pub fn native_image_from_file(file_path: *const ::std::os::raw::c_char) -> native_image_t;
@@ -221,7 +237,7 @@ pub const NATIVE_MODIFIER_KEY_FN: native_modifier_key_t = 16;
pub const NATIVE_MODIFIER_KEY_CAPS_LOCK: native_modifier_key_t = 32;
pub const NATIVE_MODIFIER_KEY_NUM_LOCK: native_modifier_key_t = 64;
pub const NATIVE_MODIFIER_KEY_SCROLL_LOCK: native_modifier_key_t = 128;
-pub type native_modifier_key_t = ::std::os::raw::c_int;
+pub type native_modifier_key_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct native_keyboard_accelerator_t {
@@ -241,7 +257,7 @@ pub const NATIVE_KEYBOARD_EVENT_TYPE_KEY_PRESSED: native_keyboard_event_type_t =
pub const NATIVE_KEYBOARD_EVENT_TYPE_KEY_RELEASED: native_keyboard_event_type_t = 1;
pub const NATIVE_KEYBOARD_EVENT_TYPE_MODIFIER_KEYS_CHANGED: native_keyboard_event_type_t = 2;
#[doc = " Which concrete KeyboardEvent arrived."]
-pub type native_keyboard_event_type_t = ::std::os::raw::c_int;
+pub type native_keyboard_event_type_t = ::std::os::raw::c_uint;
#[doc = " One KeyboardEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Copy, Clone)]
@@ -318,7 +334,7 @@ pub const NATIVE_PLACEMENT_BOTTOM_END: native_placement_t = 8;
pub const NATIVE_PLACEMENT_LEFT: native_placement_t = 9;
pub const NATIVE_PLACEMENT_LEFT_START: native_placement_t = 10;
pub const NATIVE_PLACEMENT_LEFT_END: native_placement_t = 11;
-pub type native_placement_t = ::std::os::raw::c_int;
+pub type native_placement_t = ::std::os::raw::c_uint;
#[doc = " Opaque View handle.\n\n A generational index into the library's handle table, NOT a pointer:\n never dereference it, and compare it against NATIVE_INVALID_VIEW rather than NULL.\n Releasing a handle invalidates it; later calls fail safely instead of\n touching freed memory."]
pub type native_view_t = u64;
#[doc = " Opaque WindowShadow handle.\n\n A generational index into the library's handle table, NOT a pointer:\n never dereference it, and compare it against NATIVE_INVALID_WINDOW_SHADOW rather than NULL.\n Releasing a handle invalidates it; later calls fail safely instead of\n touching freed memory."]
@@ -379,23 +395,27 @@ unsafe extern "C" {
unsafe extern "C" {
pub fn native_color_to_argb(color: native_color_t) -> ::std::os::raw::c_uint;
}
+unsafe extern "C" {
+ #[doc = " Frees everything the struct owns."]
+ pub fn native_color_free(value: *mut native_color_t);
+}
pub type native_view_id_t = ::std::os::raw::c_uint;
pub const NATIVE_VIEW_LAYOUT_ABSOLUTE: native_view_layout_t = 0;
pub const NATIVE_VIEW_LAYOUT_ROW: native_view_layout_t = 1;
pub const NATIVE_VIEW_LAYOUT_COLUMN: native_view_layout_t = 2;
-pub type native_view_layout_t = ::std::os::raw::c_int;
+pub type native_view_layout_t = ::std::os::raw::c_uint;
pub const NATIVE_VIEW_ALIGNMENT_STRETCH: native_view_alignment_t = 0;
pub const NATIVE_VIEW_ALIGNMENT_START: native_view_alignment_t = 1;
pub const NATIVE_VIEW_ALIGNMENT_CENTER: native_view_alignment_t = 2;
pub const NATIVE_VIEW_ALIGNMENT_END: native_view_alignment_t = 3;
-pub type native_view_alignment_t = ::std::os::raw::c_int;
+pub type native_view_alignment_t = ::std::os::raw::c_uint;
pub const NATIVE_TEXT_ALIGNMENT_START: native_text_alignment_t = 0;
pub const NATIVE_TEXT_ALIGNMENT_CENTER: native_text_alignment_t = 1;
pub const NATIVE_TEXT_ALIGNMENT_END: native_text_alignment_t = 2;
-pub type native_text_alignment_t = ::std::os::raw::c_int;
+pub type native_text_alignment_t = ::std::os::raw::c_uint;
pub const NATIVE_VIEW_BACKEND_NATIVE: native_view_backend_t = 0;
pub const NATIVE_VIEW_BACKEND_WIN_UI3: native_view_backend_t = 1;
-pub type native_view_backend_t = ::std::os::raw::c_int;
+pub type native_view_backend_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct native_text_range_t {
@@ -434,7 +454,7 @@ pub const NATIVE_VIEW_EVENT_TYPE_TEXT_FIELD_SUBMITTED: native_view_event_type_t
pub const NATIVE_VIEW_EVENT_TYPE_UPDATING: native_view_event_type_t = 5;
pub const NATIVE_VIEW_EVENT_TYPE_RESIZED: native_view_event_type_t = 6;
#[doc = " Which concrete ViewEvent arrived."]
-pub type native_view_event_type_t = ::std::os::raw::c_int;
+pub type native_view_event_type_t = ::std::os::raw::c_uint;
#[doc = " One ViewEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Copy, Clone)]
@@ -496,6 +516,10 @@ pub type native_view_event_callback_t_async = ::std::option::Option<
user_data: *mut ::std::os::raw::c_void,
),
>;
+unsafe extern "C" {
+ #[doc = " Frees everything the struct owns."]
+ pub fn native_text_range_free(value: *mut native_text_range_t);
+}
unsafe extern "C" {
#[doc = " Creates a View instance; release it with native_view_free()."]
pub fn native_view_create() -> native_view_t;
@@ -1003,11 +1027,11 @@ pub const NATIVE_TASKBAR_PROGRESS_STATE_INDETERMINATE: native_taskbar_progress_s
pub const NATIVE_TASKBAR_PROGRESS_STATE_NORMAL: native_taskbar_progress_state_t = 2;
pub const NATIVE_TASKBAR_PROGRESS_STATE_PAUSED: native_taskbar_progress_state_t = 3;
pub const NATIVE_TASKBAR_PROGRESS_STATE_ERROR: native_taskbar_progress_state_t = 4;
-pub type native_taskbar_progress_state_t = ::std::os::raw::c_int;
+pub type native_taskbar_progress_state_t = ::std::os::raw::c_uint;
pub const NATIVE_TASKBAR_FLASH_TARGET_ALL: native_taskbar_flash_target_t = 0;
pub const NATIVE_TASKBAR_FLASH_TARGET_CAPTION: native_taskbar_flash_target_t = 1;
pub const NATIVE_TASKBAR_FLASH_TARGET_TASKBAR: native_taskbar_flash_target_t = 2;
-pub type native_taskbar_flash_target_t = ::std::os::raw::c_int;
+pub type native_taskbar_flash_target_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct native_taskbar_flash_options_t {
@@ -1045,7 +1069,7 @@ impl Default for native_taskbar_thumbnail_button_list_t {
}
pub const NATIVE_TASKBAR_EVENT_TYPE_THUMBNAIL_BUTTON_CLICKED: native_taskbar_event_type_t = 0;
#[doc = " Which concrete TaskbarEvent arrived."]
-pub type native_taskbar_event_type_t = ::std::os::raw::c_int;
+pub type native_taskbar_event_type_t = ::std::os::raw::c_uint;
#[doc = " One TaskbarEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Copy, Clone)]
@@ -1094,6 +1118,10 @@ pub type native_taskbar_event_callback_t_async = ::std::option::Option<
user_data: *mut ::std::os::raw::c_void,
),
>;
+unsafe extern "C" {
+ #[doc = " Frees everything the struct owns."]
+ pub fn native_taskbar_flash_options_free(value: *mut native_taskbar_flash_options_t);
+}
unsafe extern "C" {
#[doc = " Creates a TaskbarThumbnailButton instance; release it with native_taskbar_thumbnail_button_free()."]
pub fn native_taskbar_thumbnail_button_create(
@@ -1389,16 +1417,16 @@ pub type native_window_id_t = ::std::os::raw::c_uint;
pub type native_window_number_t = ::std::os::raw::c_longlong;
pub const NATIVE_TITLE_BAR_STYLE_NORMAL: native_title_bar_style_t = 0;
pub const NATIVE_TITLE_BAR_STYLE_HIDDEN: native_title_bar_style_t = 1;
-pub type native_title_bar_style_t = ::std::os::raw::c_int;
+pub type native_title_bar_style_t = ::std::os::raw::c_uint;
pub const NATIVE_WINDOW_DOCK_SIDE_NONE: native_window_dock_side_t = 0;
pub const NATIVE_WINDOW_DOCK_SIDE_LEFT: native_window_dock_side_t = 1;
pub const NATIVE_WINDOW_DOCK_SIDE_RIGHT: native_window_dock_side_t = 2;
-pub type native_window_dock_side_t = ::std::os::raw::c_int;
+pub type native_window_dock_side_t = ::std::os::raw::c_uint;
pub const NATIVE_WINDOW_CORNER_PREFERENCE_DEFAULT: native_window_corner_preference_t = 0;
pub const NATIVE_WINDOW_CORNER_PREFERENCE_DO_NOT_ROUND: native_window_corner_preference_t = 1;
pub const NATIVE_WINDOW_CORNER_PREFERENCE_ROUND: native_window_corner_preference_t = 2;
pub const NATIVE_WINDOW_CORNER_PREFERENCE_ROUND_SMALL: native_window_corner_preference_t = 3;
-pub type native_window_corner_preference_t = ::std::os::raw::c_int;
+pub type native_window_corner_preference_t = ::std::os::raw::c_uint;
pub const NATIVE_WINDOW_PROPERTY_TITLE: native_window_property_t = 0;
pub const NATIVE_WINDOW_PROPERTY_RESIZABLE: native_window_property_t = 1;
pub const NATIVE_WINDOW_PROPERTY_MOVABLE: native_window_property_t = 2;
@@ -1411,11 +1439,11 @@ pub const NATIVE_WINDOW_PROPERTY_ALWAYS_ON_TOP: native_window_property_t = 8;
pub const NATIVE_WINDOW_PROPERTY_ALWAYS_ON_BOTTOM: native_window_property_t = 9;
pub const NATIVE_WINDOW_PROPERTY_TITLE_BAR_STYLE: native_window_property_t = 10;
pub const NATIVE_WINDOW_PROPERTY_FRAMELESS: native_window_property_t = 11;
-pub type native_window_property_t = ::std::os::raw::c_int;
+pub type native_window_property_t = ::std::os::raw::c_uint;
pub const NATIVE_WINDOW_OCCLUSION_STATE_UNKNOWN: native_window_occlusion_state_t = 0;
pub const NATIVE_WINDOW_OCCLUSION_STATE_VISIBLE: native_window_occlusion_state_t = 1;
pub const NATIVE_WINDOW_OCCLUSION_STATE_OCCLUDED: native_window_occlusion_state_t = 2;
-pub type native_window_occlusion_state_t = ::std::os::raw::c_int;
+pub type native_window_occlusion_state_t = ::std::os::raw::c_uint;
pub const NATIVE_VISUAL_EFFECT_NONE: native_visual_effect_t = 0;
pub const NATIVE_VISUAL_EFFECT_BLUR: native_visual_effect_t = 1;
pub const NATIVE_VISUAL_EFFECT_ACRYLIC: native_visual_effect_t = 2;
@@ -1424,7 +1452,7 @@ pub const NATIVE_VISUAL_EFFECT_MICA_ALT: native_visual_effect_t = 4;
pub const NATIVE_VISUAL_EFFECT_HUD: native_visual_effect_t = 5;
pub const NATIVE_VISUAL_EFFECT_POPOVER: native_visual_effect_t = 6;
pub const NATIVE_VISUAL_EFFECT_MENU: native_visual_effect_t = 7;
-pub type native_visual_effect_t = ::std::os::raw::c_int;
+pub type native_visual_effect_t = ::std::os::raw::c_uint;
pub const NATIVE_RESIZE_EDGE_TOP: native_resize_edge_t = 0;
pub const NATIVE_RESIZE_EDGE_LEFT: native_resize_edge_t = 1;
pub const NATIVE_RESIZE_EDGE_RIGHT: native_resize_edge_t = 2;
@@ -1433,7 +1461,7 @@ pub const NATIVE_RESIZE_EDGE_TOP_LEFT: native_resize_edge_t = 4;
pub const NATIVE_RESIZE_EDGE_TOP_RIGHT: native_resize_edge_t = 5;
pub const NATIVE_RESIZE_EDGE_BOTTOM_LEFT: native_resize_edge_t = 6;
pub const NATIVE_RESIZE_EDGE_BOTTOM_RIGHT: native_resize_edge_t = 7;
-pub type native_resize_edge_t = ::std::os::raw::c_int;
+pub type native_resize_edge_t = ::std::os::raw::c_uint;
#[doc = " Owning list of Window handles."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -1468,7 +1496,7 @@ pub const NATIVE_WINDOW_EVENT_TYPE_DOCKED: native_window_event_type_t = 14;
pub const NATIVE_WINDOW_EVENT_TYPE_UNDOCKED: native_window_event_type_t = 15;
pub const NATIVE_WINDOW_EVENT_TYPE_SCALE_FACTOR_CHANGED: native_window_event_type_t = 16;
#[doc = " Which concrete WindowEvent arrived."]
-pub type native_window_event_type_t = ::std::os::raw::c_int;
+pub type native_window_event_type_t = ::std::os::raw::c_uint;
#[doc = " One WindowEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Copy, Clone)]
@@ -2094,7 +2122,7 @@ unsafe extern "C" {
pub const NATIVE_POSITIONING_STRATEGY_TYPE_ABSOLUTE: native_positioning_strategy_type_t = 0;
pub const NATIVE_POSITIONING_STRATEGY_TYPE_CURSOR_POSITION: native_positioning_strategy_type_t = 1;
pub const NATIVE_POSITIONING_STRATEGY_TYPE_RELATIVE: native_positioning_strategy_type_t = 2;
-pub type native_positioning_strategy_type_t = ::std::os::raw::c_int;
+pub type native_positioning_strategy_type_t = ::std::os::raw::c_uint;
unsafe extern "C" {
#[doc = " Caller owns the returned handle; release it with native_positioning_strategy_free()."]
pub fn native_positioning_strategy_absolute(
@@ -2153,17 +2181,17 @@ pub type native_menu_id_t = ::std::os::raw::c_uint;
pub type native_menu_item_id_t = ::std::os::raw::c_uint;
pub const NATIVE_MENU_BACKEND_NATIVE: native_menu_backend_t = 0;
pub const NATIVE_MENU_BACKEND_WIN_UI3: native_menu_backend_t = 1;
-pub type native_menu_backend_t = ::std::os::raw::c_int;
+pub type native_menu_backend_t = ::std::os::raw::c_uint;
pub const NATIVE_MENU_ITEM_TYPE_NORMAL: native_menu_item_type_t = 0;
pub const NATIVE_MENU_ITEM_TYPE_CHECKBOX: native_menu_item_type_t = 1;
pub const NATIVE_MENU_ITEM_TYPE_RADIO: native_menu_item_type_t = 2;
pub const NATIVE_MENU_ITEM_TYPE_SEPARATOR: native_menu_item_type_t = 3;
pub const NATIVE_MENU_ITEM_TYPE_SUBMENU: native_menu_item_type_t = 4;
-pub type native_menu_item_type_t = ::std::os::raw::c_int;
+pub type native_menu_item_type_t = ::std::os::raw::c_uint;
pub const NATIVE_MENU_ITEM_STATE_UNCHECKED: native_menu_item_state_t = 0;
pub const NATIVE_MENU_ITEM_STATE_CHECKED: native_menu_item_state_t = 1;
pub const NATIVE_MENU_ITEM_STATE_MIXED: native_menu_item_state_t = 2;
-pub type native_menu_item_state_t = ::std::os::raw::c_int;
+pub type native_menu_item_state_t = ::std::os::raw::c_uint;
#[doc = " Opaque MenuItem handle.\n\n A generational index into the library's handle table, NOT a pointer:\n never dereference it, and compare it against NATIVE_INVALID_MENU_ITEM rather than NULL.\n Releasing a handle invalidates it; later calls fail safely instead of\n touching freed memory."]
pub type native_menu_item_t = u64;
#[doc = " Owning list of MenuItem handles."]
@@ -2188,7 +2216,7 @@ pub const NATIVE_MENU_EVENT_TYPE_ITEM_CLICKED: native_menu_event_type_t = 2;
pub const NATIVE_MENU_EVENT_TYPE_ITEM_SUBMENU_OPENED: native_menu_event_type_t = 3;
pub const NATIVE_MENU_EVENT_TYPE_ITEM_SUBMENU_CLOSED: native_menu_event_type_t = 4;
#[doc = " Which concrete MenuEvent arrived."]
-pub type native_menu_event_type_t = ::std::os::raw::c_int;
+pub type native_menu_event_type_t = ::std::os::raw::c_uint;
#[doc = " One MenuEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Copy, Clone)]
@@ -2512,7 +2540,7 @@ unsafe extern "C" {
pub const NATIVE_BRIGHTNESS_SYSTEM: native_brightness_t = 0;
pub const NATIVE_BRIGHTNESS_LIGHT: native_brightness_t = 1;
pub const NATIVE_BRIGHTNESS_DARK: native_brightness_t = 2;
-pub type native_brightness_t = ::std::os::raw::c_int;
+pub type native_brightness_t = ::std::os::raw::c_uint;
pub const NATIVE_APPLICATION_EVENT_TYPE_STARTED: native_application_event_type_t = 0;
pub const NATIVE_APPLICATION_EVENT_TYPE_EXITING: native_application_event_type_t = 1;
pub const NATIVE_APPLICATION_EVENT_TYPE_ACTIVATED: native_application_event_type_t = 2;
@@ -2522,7 +2550,7 @@ pub const NATIVE_APPLICATION_EVENT_TYPE_SYSTEM_BRIGHTNESS_CHANGED: native_applic
5;
pub const NATIVE_APPLICATION_EVENT_TYPE_SECOND_INSTANCE: native_application_event_type_t = 6;
#[doc = " Which concrete ApplicationEvent arrived."]
-pub type native_application_event_type_t = ::std::os::raw::c_int;
+pub type native_application_event_type_t = ::std::os::raw::c_uint;
#[doc = " One ApplicationEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Copy, Clone)]
@@ -2695,6 +2723,150 @@ unsafe extern "C" {
#[doc = " Unregisters a listener. Returns false if unknown."]
pub fn native_application_remove_listener(listener_id: native_listener_id_t) -> bool;
}
+#[doc = " Opaque Display handle.\n\n A generational index into the library's handle table, NOT a pointer:\n never dereference it, and compare it against NATIVE_INVALID_DISPLAY rather than NULL.\n Releasing a handle invalidates it; later calls fail safely instead of\n touching freed memory."]
+pub type native_display_t = u64;
+pub type native_display_id_t = ::std::os::raw::c_uint;
+pub const NATIVE_DISPLAY_ORIENTATION_PORTRAIT: native_display_orientation_t = 0;
+pub const NATIVE_DISPLAY_ORIENTATION_LANDSCAPE: native_display_orientation_t = 90;
+pub const NATIVE_DISPLAY_ORIENTATION_PORTRAIT_FLIPPED: native_display_orientation_t = 180;
+pub const NATIVE_DISPLAY_ORIENTATION_LANDSCAPE_FLIPPED: native_display_orientation_t = 270;
+pub type native_display_orientation_t = ::std::os::raw::c_uint;
+#[doc = " Owning list of Display handles."]
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct native_display_list_t {
+ pub displays: *mut native_display_t,
+ pub count: ::std::os::raw::c_long,
+}
+impl Default for native_display_list_t {
+ fn default() -> Self {
+ let mut s = ::std::mem::MaybeUninit::::uninit();
+ unsafe {
+ ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+ s.assume_init()
+ }
+ }
+}
+pub const NATIVE_DISPLAY_EVENT_TYPE_ADDED: native_display_event_type_t = 0;
+pub const NATIVE_DISPLAY_EVENT_TYPE_REMOVED: native_display_event_type_t = 1;
+pub const NATIVE_DISPLAY_EVENT_TYPE_CHANGED: native_display_event_type_t = 2;
+#[doc = " Which concrete DisplayEvent arrived."]
+pub type native_display_event_type_t = ::std::os::raw::c_uint;
+#[doc = " One DisplayEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct native_display_event_t {
+ pub type_: native_display_event_type_t,
+ pub display: native_display_t,
+}
+impl Default for native_display_event_t {
+ fn default() -> Self {
+ let mut s = ::std::mem::MaybeUninit::::uninit();
+ unsafe {
+ ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+ s.assume_init()
+ }
+ }
+}
+pub type native_display_event_callback_t = ::std::option::Option<
+ unsafe extern "C" fn(
+ event: *const native_display_event_t,
+ user_data: *mut ::std::os::raw::c_void,
+ ),
+>;
+pub type native_display_event_callback_t_async = ::std::option::Option<
+ unsafe extern "C" fn(
+ event: *const native_display_event_t,
+ delivery: native_event_delivery_t,
+ user_data: *mut ::std::os::raw::c_void,
+ ),
+>;
+unsafe extern "C" {
+ #[doc = " Creates a Display instance; release it with native_display_free()."]
+ pub fn native_display_create(display: *mut ::std::os::raw::c_void) -> native_display_t;
+}
+unsafe extern "C" {
+ pub fn native_display_get_id(display: native_display_t) -> native_display_id_t;
+}
+unsafe extern "C" {
+ #[doc = " Caller owns the returned string; free it with free_c_str()."]
+ pub fn native_display_get_name(display: native_display_t) -> *mut ::std::os::raw::c_char;
+}
+unsafe extern "C" {
+ pub fn native_display_get_position(display: native_display_t) -> native_point_t;
+}
+unsafe extern "C" {
+ pub fn native_display_get_size(display: native_display_t) -> native_size_t;
+}
+unsafe extern "C" {
+ pub fn native_display_get_work_area(display: native_display_t) -> native_rectangle_t;
+}
+unsafe extern "C" {
+ pub fn native_display_get_scale_factor(display: native_display_t) -> f64;
+}
+unsafe extern "C" {
+ pub fn native_display_is_primary(display: native_display_t) -> bool;
+}
+unsafe extern "C" {
+ pub fn native_display_get_orientation(
+ display: native_display_t,
+ ) -> native_display_orientation_t;
+}
+unsafe extern "C" {
+ pub fn native_display_get_refresh_rate(display: native_display_t) -> ::std::os::raw::c_int;
+}
+unsafe extern "C" {
+ pub fn native_display_get_bit_depth(display: native_display_t) -> ::std::os::raw::c_int;
+}
+unsafe extern "C" {
+ #[doc = " Platform-specific native object (NSScreen*, HMONITOR, ...)."]
+ pub fn native_display_get_native_object(
+ display: native_display_t,
+ ) -> *mut ::std::os::raw::c_void;
+}
+unsafe extern "C" {
+ #[doc = " Releases the caller's reference. Safe to call with an invalid or\n already-released handle."]
+ pub fn native_display_free(display: native_display_t);
+}
+unsafe extern "C" {
+ #[doc = " Frees the array and releases every handle it contains."]
+ pub fn native_display_list_free(list: *mut native_display_list_t);
+}
+unsafe extern "C" {
+ #[doc = " Frees only the array; the caller takes over the handles."]
+ pub fn native_display_list_release(list: *mut native_display_list_t);
+}
+pub const NATIVE_CAPTURE_SOURCE_TYPE_NONE: native_capture_source_type_t = 0;
+pub const NATIVE_CAPTURE_SOURCE_TYPE_DISPLAY: native_capture_source_type_t = 1;
+pub const NATIVE_CAPTURE_SOURCE_TYPE_WINDOW: native_capture_source_type_t = 2;
+pub const NATIVE_CAPTURE_SOURCE_TYPE_UNKNOWN: native_capture_source_type_t = 3;
+pub type native_capture_source_type_t = ::std::os::raw::c_uint;
+#[doc = " Opaque CaptureSource handle.\n\n A generational index into the library's handle table, NOT a pointer:\n never dereference it, and compare it against NATIVE_INVALID_CAPTURE_SOURCE rather than NULL.\n Releasing a handle invalidates it; later calls fail safely instead of\n touching freed memory."]
+pub type native_capture_source_t = u64;
+unsafe extern "C" {
+ #[doc = " Caller owns the returned handle; release it with native_capture_source_free()."]
+ pub fn native_capture_source_from_display(display: native_display_t)
+ -> native_capture_source_t;
+}
+unsafe extern "C" {
+ #[doc = " Caller owns the returned handle; release it with native_capture_source_free()."]
+ pub fn native_capture_source_from_window(window: native_window_t) -> native_capture_source_t;
+}
+unsafe extern "C" {
+ pub fn native_capture_source_get_type(
+ capture_source: native_capture_source_t,
+ ) -> native_capture_source_type_t;
+}
+unsafe extern "C" {
+ #[doc = " Caller owns the returned string; free it with free_c_str()."]
+ pub fn native_capture_source_get_name(
+ capture_source: native_capture_source_t,
+ ) -> *mut ::std::os::raw::c_char;
+}
+unsafe extern "C" {
+ #[doc = " Releases the caller's reference. Safe to call with an invalid or\n already-released handle."]
+ pub fn native_capture_source_free(capture_source: native_capture_source_t);
+}
#[doc = " Arguments are borrowed until event_delivery_complete(delivery, ...), which is required exactly once."]
pub type native_clipboard_read_callback_t = ::std::option::Option<
unsafe extern "C" fn(
@@ -2778,7 +2950,7 @@ impl Default for native_clipboard_data_t {
}
pub const NATIVE_CLIPBOARD_EVENT_TYPE_CHANGED: native_clipboard_event_type_t = 0;
#[doc = " Which concrete ClipboardEvent arrived."]
-pub type native_clipboard_event_type_t = ::std::os::raw::c_int;
+pub type native_clipboard_event_type_t = ::std::os::raw::c_uint;
#[doc = " One ClipboardEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
@@ -2972,120 +3144,7 @@ unsafe extern "C" {
pub const NATIVE_DIALOG_MODALITY_NONE: native_dialog_modality_t = 0;
pub const NATIVE_DIALOG_MODALITY_APPLICATION: native_dialog_modality_t = 1;
pub const NATIVE_DIALOG_MODALITY_WINDOW: native_dialog_modality_t = 2;
-pub type native_dialog_modality_t = ::std::os::raw::c_int;
-pub type native_display_id_t = ::std::os::raw::c_uint;
-pub const NATIVE_DISPLAY_ORIENTATION_PORTRAIT: native_display_orientation_t = 0;
-pub const NATIVE_DISPLAY_ORIENTATION_LANDSCAPE: native_display_orientation_t = 90;
-pub const NATIVE_DISPLAY_ORIENTATION_PORTRAIT_FLIPPED: native_display_orientation_t = 180;
-pub const NATIVE_DISPLAY_ORIENTATION_LANDSCAPE_FLIPPED: native_display_orientation_t = 270;
-pub type native_display_orientation_t = ::std::os::raw::c_int;
-#[doc = " Opaque Display handle.\n\n A generational index into the library's handle table, NOT a pointer:\n never dereference it, and compare it against NATIVE_INVALID_DISPLAY rather than NULL.\n Releasing a handle invalidates it; later calls fail safely instead of\n touching freed memory."]
-pub type native_display_t = u64;
-#[doc = " Owning list of Display handles."]
-#[repr(C)]
-#[derive(Debug, Copy, Clone)]
-pub struct native_display_list_t {
- pub displays: *mut native_display_t,
- pub count: ::std::os::raw::c_long,
-}
-impl Default for native_display_list_t {
- fn default() -> Self {
- let mut s = ::std::mem::MaybeUninit::::uninit();
- unsafe {
- ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
- s.assume_init()
- }
- }
-}
-pub const NATIVE_DISPLAY_EVENT_TYPE_ADDED: native_display_event_type_t = 0;
-pub const NATIVE_DISPLAY_EVENT_TYPE_REMOVED: native_display_event_type_t = 1;
-pub const NATIVE_DISPLAY_EVENT_TYPE_CHANGED: native_display_event_type_t = 2;
-#[doc = " Which concrete DisplayEvent arrived."]
-pub type native_display_event_type_t = ::std::os::raw::c_int;
-#[doc = " One DisplayEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
-#[repr(C)]
-#[derive(Debug, Copy, Clone)]
-pub struct native_display_event_t {
- pub type_: native_display_event_type_t,
- pub display: native_display_t,
-}
-impl Default for native_display_event_t {
- fn default() -> Self {
- let mut s = ::std::mem::MaybeUninit::::uninit();
- unsafe {
- ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
- s.assume_init()
- }
- }
-}
-pub type native_display_event_callback_t = ::std::option::Option<
- unsafe extern "C" fn(
- event: *const native_display_event_t,
- user_data: *mut ::std::os::raw::c_void,
- ),
->;
-pub type native_display_event_callback_t_async = ::std::option::Option<
- unsafe extern "C" fn(
- event: *const native_display_event_t,
- delivery: native_event_delivery_t,
- user_data: *mut ::std::os::raw::c_void,
- ),
->;
-unsafe extern "C" {
- #[doc = " Creates a Display instance; release it with native_display_free()."]
- pub fn native_display_create(display: *mut ::std::os::raw::c_void) -> native_display_t;
-}
-unsafe extern "C" {
- pub fn native_display_get_id(display: native_display_t) -> native_display_id_t;
-}
-unsafe extern "C" {
- #[doc = " Caller owns the returned string; free it with free_c_str()."]
- pub fn native_display_get_name(display: native_display_t) -> *mut ::std::os::raw::c_char;
-}
-unsafe extern "C" {
- pub fn native_display_get_position(display: native_display_t) -> native_point_t;
-}
-unsafe extern "C" {
- pub fn native_display_get_size(display: native_display_t) -> native_size_t;
-}
-unsafe extern "C" {
- pub fn native_display_get_work_area(display: native_display_t) -> native_rectangle_t;
-}
-unsafe extern "C" {
- pub fn native_display_get_scale_factor(display: native_display_t) -> f64;
-}
-unsafe extern "C" {
- pub fn native_display_is_primary(display: native_display_t) -> bool;
-}
-unsafe extern "C" {
- pub fn native_display_get_orientation(
- display: native_display_t,
- ) -> native_display_orientation_t;
-}
-unsafe extern "C" {
- pub fn native_display_get_refresh_rate(display: native_display_t) -> ::std::os::raw::c_int;
-}
-unsafe extern "C" {
- pub fn native_display_get_bit_depth(display: native_display_t) -> ::std::os::raw::c_int;
-}
-unsafe extern "C" {
- #[doc = " Platform-specific native object (NSScreen*, HMONITOR, ...)."]
- pub fn native_display_get_native_object(
- display: native_display_t,
- ) -> *mut ::std::os::raw::c_void;
-}
-unsafe extern "C" {
- #[doc = " Releases the caller's reference. Safe to call with an invalid or\n already-released handle."]
- pub fn native_display_free(display: native_display_t);
-}
-unsafe extern "C" {
- #[doc = " Frees the array and releases every handle it contains."]
- pub fn native_display_list_free(list: *mut native_display_list_t);
-}
-unsafe extern "C" {
- #[doc = " Frees only the array; the caller takes over the handles."]
- pub fn native_display_list_release(list: *mut native_display_list_t);
-}
+pub type native_dialog_modality_t = ::std::os::raw::c_uint;
unsafe extern "C" {
pub fn native_display_manager_get_all() -> native_display_list_t;
}
@@ -3120,12 +3179,12 @@ pub const NATIVE_DRAG_OPERATION_NONE: native_drag_operation_t = 0;
pub const NATIVE_DRAG_OPERATION_COPY: native_drag_operation_t = 1;
pub const NATIVE_DRAG_OPERATION_MOVE: native_drag_operation_t = 2;
pub const NATIVE_DRAG_OPERATION_LINK: native_drag_operation_t = 3;
-pub type native_drag_operation_t = ::std::os::raw::c_int;
+pub type native_drag_operation_t = ::std::os::raw::c_uint;
#[doc = " Opaque DragSource handle.\n\n A generational index into the library's handle table, NOT a pointer:\n never dereference it, and compare it against NATIVE_INVALID_DRAG_SOURCE rather than NULL.\n Releasing a handle invalidates it; later calls fail safely instead of\n touching freed memory."]
pub type native_drag_source_t = u64;
pub const NATIVE_DRAG_SOURCE_EVENT_TYPE_ENDED: native_drag_source_event_type_t = 0;
#[doc = " Which concrete DragSourceEvent arrived."]
-pub type native_drag_source_event_type_t = ::std::os::raw::c_int;
+pub type native_drag_source_event_type_t = ::std::os::raw::c_uint;
#[doc = " One DragSourceEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Copy, Clone)]
@@ -3284,7 +3343,7 @@ pub const NATIVE_DROP_TARGET_EVENT_TYPE_MOVED: native_drop_target_event_type_t =
pub const NATIVE_DROP_TARGET_EVENT_TYPE_EXITED: native_drop_target_event_type_t = 2;
pub const NATIVE_DROP_TARGET_EVENT_TYPE_DROPPED: native_drop_target_event_type_t = 3;
#[doc = " Which concrete DropTargetEvent arrived."]
-pub type native_drop_target_event_type_t = ::std::os::raw::c_int;
+pub type native_drop_target_event_type_t = ::std::os::raw::c_uint;
#[doc = " One DropTargetEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Copy, Clone)]
@@ -3404,12 +3463,12 @@ pub const NATIVE_FILE_DIALOG_MODE_OPEN_FILE: native_file_dialog_mode_t = 0;
pub const NATIVE_FILE_DIALOG_MODE_OPEN_FILES: native_file_dialog_mode_t = 1;
pub const NATIVE_FILE_DIALOG_MODE_SAVE_FILE: native_file_dialog_mode_t = 2;
pub const NATIVE_FILE_DIALOG_MODE_SELECT_FOLDER: native_file_dialog_mode_t = 3;
-pub type native_file_dialog_mode_t = ::std::os::raw::c_int;
+pub type native_file_dialog_mode_t = ::std::os::raw::c_uint;
pub const NATIVE_FILE_DIALOG_RESULT_NONE: native_file_dialog_result_t = 0;
pub const NATIVE_FILE_DIALOG_RESULT_ACCEPTED: native_file_dialog_result_t = 1;
pub const NATIVE_FILE_DIALOG_RESULT_CANCELLED: native_file_dialog_result_t = 2;
pub const NATIVE_FILE_DIALOG_RESULT_FAILED: native_file_dialog_result_t = 3;
-pub type native_file_dialog_result_t = ::std::os::raw::c_int;
+pub type native_file_dialog_result_t = ::std::os::raw::c_uint;
#[doc = " Opaque FileDialog handle.\n\n A generational index into the library's handle table, NOT a pointer:\n never dereference it, and compare it against NATIVE_INVALID_FILE_DIALOG rather than NULL.\n Releasing a handle invalidates it; later calls fail safely instead of\n touching freed memory."]
pub type native_file_dialog_t = u64;
unsafe extern "C" {
@@ -3593,7 +3652,7 @@ pub const NATIVE_MESSAGE_DIALOG_RESULT_NONE: native_message_dialog_result_t = 0;
pub const NATIVE_MESSAGE_DIALOG_RESULT_PRIMARY: native_message_dialog_result_t = 1;
pub const NATIVE_MESSAGE_DIALOG_RESULT_SECONDARY: native_message_dialog_result_t = 2;
pub const NATIVE_MESSAGE_DIALOG_RESULT_CLOSE: native_message_dialog_result_t = 3;
-pub type native_message_dialog_result_t = ::std::os::raw::c_int;
+pub type native_message_dialog_result_t = ::std::os::raw::c_uint;
#[doc = " Opaque MessageDialog handle.\n\n A generational index into the library's handle table, NOT a pointer:\n never dereference it, and compare it against NATIVE_INVALID_MESSAGE_DIALOG rather than NULL.\n Releasing a handle invalidates it; later calls fail safely instead of\n touching freed memory."]
pub type native_message_dialog_t = u64;
unsafe extern "C" {
@@ -3717,7 +3776,7 @@ unsafe extern "C" {
}
pub const NATIVE_NOTIFICATION_EVENT_TYPE_ACTIVATED: native_notification_event_type_t = 0;
#[doc = " Which concrete NotificationEvent arrived."]
-pub type native_notification_event_type_t = ::std::os::raw::c_int;
+pub type native_notification_event_type_t = ::std::os::raw::c_uint;
#[doc = " One NotificationEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Copy, Clone)]
@@ -3885,7 +3944,7 @@ unsafe extern "C" {
pub const NATIVE_PROTOCOL_HANDLER_EVENT_TYPE_PROTOCOL_URL_RECEIVED:
native_protocol_handler_event_type_t = 0;
#[doc = " Which concrete ProtocolHandlerEvent arrived."]
-pub type native_protocol_handler_event_type_t = ::std::os::raw::c_int;
+pub type native_protocol_handler_event_type_t = ::std::os::raw::c_uint;
#[doc = " One ProtocolHandlerEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Copy, Clone)]
@@ -3973,6 +4032,243 @@ unsafe extern "C" {
#[doc = " Unregisters a listener. Returns false if unknown."]
pub fn native_protocol_handler_remove_listener(listener_id: native_listener_id_t) -> bool;
}
+#[doc = " Arguments are borrowed until event_delivery_complete(delivery, ...), which is required exactly once."]
+pub type native_screen_capturer_select_source_callback_t = ::std::option::Option<
+ unsafe extern "C" fn(
+ arg0: bool,
+ arg1: native_capture_source_t,
+ delivery: native_event_delivery_t,
+ user_data: *mut ::std::os::raw::c_void,
+ ),
+>;
+#[doc = " Arguments are borrowed until event_delivery_complete(delivery, ...), which is required exactly once."]
+pub type native_screen_capturer_capture_callback_t = ::std::option::Option<
+ unsafe extern "C" fn(
+ arg0: bool,
+ arg1: native_image_t,
+ delivery: native_event_delivery_t,
+ user_data: *mut ::std::os::raw::c_void,
+ ),
+>;
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct native_capture_source_selection_options_t {
+ pub allow_displays: bool,
+ pub allow_windows: bool,
+ pub parent_window: native_window_t,
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct native_screen_capture_options_t {
+ pub include_cursor: bool,
+ pub crop_enabled: bool,
+ pub crop: native_rectangle_t,
+}
+unsafe extern "C" {
+ #[doc = " Frees everything the struct owns."]
+ pub fn native_capture_source_selection_options_free(
+ value: *mut native_capture_source_selection_options_t,
+ );
+}
+unsafe extern "C" {
+ #[doc = " Frees everything the struct owns."]
+ pub fn native_screen_capture_options_free(value: *mut native_screen_capture_options_t);
+}
+unsafe extern "C" {
+ pub fn native_screen_capturer_is_supported() -> bool;
+}
+unsafe extern "C" {
+ pub fn native_screen_capturer_is_source_selection_supported() -> bool;
+}
+unsafe extern "C" {
+ pub fn native_screen_capturer_is_direct_capture_supported(
+ type_: native_capture_source_type_t,
+ ) -> bool;
+}
+unsafe extern "C" {
+ pub fn native_screen_capturer_select_source(
+ options: native_capture_source_selection_options_t,
+ callback: native_screen_capturer_select_source_callback_t,
+ callback_user_data: *mut ::std::os::raw::c_void,
+ callback_release_user_data: native_release_user_data_t,
+ );
+}
+unsafe extern "C" {
+ pub fn native_screen_capturer_capture(
+ source: native_capture_source_t,
+ options: native_screen_capture_options_t,
+ callback: native_screen_capturer_capture_callback_t,
+ callback_user_data: *mut ::std::os::raw::c_void,
+ callback_release_user_data: native_release_user_data_t,
+ );
+}
+pub const NATIVE_SCREEN_RECORDING_STATE_IDLE: native_screen_recording_state_t = 0;
+pub const NATIVE_SCREEN_RECORDING_STATE_STARTING: native_screen_recording_state_t = 1;
+pub const NATIVE_SCREEN_RECORDING_STATE_RECORDING: native_screen_recording_state_t = 2;
+pub const NATIVE_SCREEN_RECORDING_STATE_STOPPING: native_screen_recording_state_t = 3;
+pub const NATIVE_SCREEN_RECORDING_STATE_COMPLETED: native_screen_recording_state_t = 4;
+pub const NATIVE_SCREEN_RECORDING_STATE_CANCELLED: native_screen_recording_state_t = 5;
+pub const NATIVE_SCREEN_RECORDING_STATE_FAILED: native_screen_recording_state_t = 6;
+pub type native_screen_recording_state_t = ::std::os::raw::c_uint;
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone)]
+pub struct native_screen_recording_options_t {
+ pub capture: native_screen_capture_options_t,
+ pub frame_rate: f64,
+ pub video_bitrate: ::std::os::raw::c_ulong,
+}
+#[doc = " Opaque ScreenRecorder handle.\n\n A generational index into the library's handle table, NOT a pointer:\n never dereference it, and compare it against NATIVE_INVALID_SCREEN_RECORDER rather than NULL.\n Releasing a handle invalidates it; later calls fail safely instead of\n touching freed memory."]
+pub type native_screen_recorder_t = u64;
+pub const NATIVE_SCREEN_RECORDING_EVENT_TYPE_STARTED: native_screen_recording_event_type_t = 0;
+pub const NATIVE_SCREEN_RECORDING_EVENT_TYPE_COMPLETED: native_screen_recording_event_type_t = 1;
+pub const NATIVE_SCREEN_RECORDING_EVENT_TYPE_CANCELLED: native_screen_recording_event_type_t = 2;
+pub const NATIVE_SCREEN_RECORDING_EVENT_TYPE_FAILED: native_screen_recording_event_type_t = 3;
+#[doc = " Which concrete ScreenRecordingEvent arrived."]
+pub type native_screen_recording_event_type_t = ::std::os::raw::c_uint;
+#[doc = " One ScreenRecordingEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub struct native_screen_recording_event_t {
+ pub type_: native_screen_recording_event_type_t,
+ pub data: native_screen_recording_event_t__bindgen_ty_1,
+}
+#[repr(C)]
+#[derive(Copy, Clone)]
+pub union native_screen_recording_event_t__bindgen_ty_1 {
+ pub completed: native_screen_recording_event_t__bindgen_ty_1__bindgen_ty_1,
+ pub failed: native_screen_recording_event_t__bindgen_ty_1__bindgen_ty_2,
+}
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct native_screen_recording_event_t__bindgen_ty_1__bindgen_ty_1 {
+ pub file_path: *mut ::std::os::raw::c_char,
+ pub duration: f64,
+}
+impl Default for native_screen_recording_event_t__bindgen_ty_1__bindgen_ty_1 {
+ fn default() -> Self {
+ let mut s = ::std::mem::MaybeUninit::::uninit();
+ unsafe {
+ ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+ s.assume_init()
+ }
+ }
+}
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct native_screen_recording_event_t__bindgen_ty_1__bindgen_ty_2 {
+ pub message: *mut ::std::os::raw::c_char,
+}
+impl Default for native_screen_recording_event_t__bindgen_ty_1__bindgen_ty_2 {
+ fn default() -> Self {
+ let mut s = ::std::mem::MaybeUninit::::uninit();
+ unsafe {
+ ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+ s.assume_init()
+ }
+ }
+}
+impl Default for native_screen_recording_event_t__bindgen_ty_1 {
+ fn default() -> Self {
+ let mut s = ::std::mem::MaybeUninit::::uninit();
+ unsafe {
+ ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+ s.assume_init()
+ }
+ }
+}
+impl Default for native_screen_recording_event_t {
+ fn default() -> Self {
+ let mut s = ::std::mem::MaybeUninit::::uninit();
+ unsafe {
+ ::std::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
+ s.assume_init()
+ }
+ }
+}
+pub type native_screen_recording_event_callback_t = ::std::option::Option<
+ unsafe extern "C" fn(
+ event: *const native_screen_recording_event_t,
+ user_data: *mut ::std::os::raw::c_void,
+ ),
+>;
+pub type native_screen_recording_event_callback_t_async = ::std::option::Option<
+ unsafe extern "C" fn(
+ event: *const native_screen_recording_event_t,
+ delivery: native_event_delivery_t,
+ user_data: *mut ::std::os::raw::c_void,
+ ),
+>;
+unsafe extern "C" {
+ #[doc = " Frees everything the struct owns."]
+ pub fn native_screen_recording_options_free(value: *mut native_screen_recording_options_t);
+}
+unsafe extern "C" {
+ #[doc = " Creates a ScreenRecorder instance; release it with native_screen_recorder_free()."]
+ pub fn native_screen_recorder_create() -> native_screen_recorder_t;
+}
+unsafe extern "C" {
+ pub fn native_screen_recorder_is_supported() -> bool;
+}
+unsafe extern "C" {
+ pub fn native_screen_recorder_start(
+ screen_recorder: native_screen_recorder_t,
+ source: native_capture_source_t,
+ file_path: *const ::std::os::raw::c_char,
+ options: native_screen_recording_options_t,
+ ) -> bool;
+}
+unsafe extern "C" {
+ pub fn native_screen_recorder_stop(screen_recorder: native_screen_recorder_t) -> bool;
+}
+unsafe extern "C" {
+ pub fn native_screen_recorder_cancel(screen_recorder: native_screen_recorder_t) -> bool;
+}
+unsafe extern "C" {
+ pub fn native_screen_recorder_get_state(
+ screen_recorder: native_screen_recorder_t,
+ ) -> native_screen_recording_state_t;
+}
+unsafe extern "C" {
+ pub fn native_screen_recorder_is_active(screen_recorder: native_screen_recorder_t) -> bool;
+}
+unsafe extern "C" {
+ pub fn native_screen_recorder_get_duration(screen_recorder: native_screen_recorder_t) -> f64;
+}
+unsafe extern "C" {
+ #[doc = " Caller owns the returned string; free it with free_c_str()."]
+ pub fn native_screen_recorder_get_file_path(
+ screen_recorder: native_screen_recorder_t,
+ ) -> *mut ::std::os::raw::c_char;
+}
+unsafe extern "C" {
+ #[doc = " Releases the caller's reference. Safe to call with an invalid or\n already-released handle."]
+ pub fn native_screen_recorder_free(screen_recorder: native_screen_recorder_t);
+}
+unsafe extern "C" {
+ #[doc = " Registers @p callback for every ScreenRecordingEvent this ScreenRecorder emits.\n @return the listener id, or NATIVE_INVALID_LISTENER_ID on failure."]
+ pub fn native_screen_recorder_add_listener(
+ screen_recorder: native_screen_recorder_t,
+ callback: native_screen_recording_event_callback_t,
+ user_data: *mut ::std::os::raw::c_void,
+ release_user_data: native_release_user_data_t,
+ ) -> native_listener_id_t;
+}
+unsafe extern "C" {
+ #[doc = " Registers an asynchronous callback. Its event, borrowed handles and user_data\n remain valid until event_delivery_complete is called, including after removal.\n Every delivered payload must be acknowledged. Check is_active before invoking a queued callback."]
+ pub fn native_screen_recorder_add_listener_async(
+ screen_recorder: native_screen_recorder_t,
+ callback: native_screen_recording_event_callback_t_async,
+ user_data: *mut ::std::os::raw::c_void,
+ release_user_data: native_release_user_data_t,
+ ) -> native_listener_id_t;
+}
+unsafe extern "C" {
+ #[doc = " Unregisters a listener. Returns false if unknown."]
+ pub fn native_screen_recorder_remove_listener(
+ screen_recorder: native_screen_recorder_t,
+ listener_id: native_listener_id_t,
+ ) -> bool;
+}
#[doc = " Opaque SecureStorage handle.\n\n A generational index into the library's handle table, NOT a pointer:\n never dereference it, and compare it against NATIVE_INVALID_SECURE_STORAGE rather than NULL.\n Releasing a handle invalidates it; later calls fail safely instead of\n touching freed memory."]
pub type native_secure_storage_t = u64;
unsafe extern "C" {
@@ -4046,7 +4342,7 @@ unsafe extern "C" {
pub type native_shortcut_id_t = ::std::os::raw::c_uint;
pub const NATIVE_SHORTCUT_SCOPE_GLOBAL: native_shortcut_scope_t = 0;
pub const NATIVE_SHORTCUT_SCOPE_APPLICATION: native_shortcut_scope_t = 1;
-pub type native_shortcut_scope_t = ::std::os::raw::c_int;
+pub type native_shortcut_scope_t = ::std::os::raw::c_uint;
pub type native_shortcut_options_callback_t =
::std::option::Option;
pub type native_shortcut_create_with_id_and_accelerator_and_callback_t =
@@ -4097,7 +4393,7 @@ pub const NATIVE_SHORTCUT_EVENT_TYPE_UNREGISTERED: native_shortcut_event_type_t
pub const NATIVE_SHORTCUT_EVENT_TYPE_REGISTRATION_FAILED: native_shortcut_event_type_t = 3;
pub const NATIVE_SHORTCUT_EVENT_TYPE_RELEASED: native_shortcut_event_type_t = 4;
#[doc = " Which concrete ShortcutEvent arrived."]
-pub type native_shortcut_event_type_t = ::std::os::raw::c_int;
+pub type native_shortcut_event_type_t = ::std::os::raw::c_uint;
#[doc = " One ShortcutEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Copy, Clone)]
@@ -4357,10 +4653,10 @@ pub const NATIVE_CONTEXT_MENU_TRIGGER_NONE: native_context_menu_trigger_t = 0;
pub const NATIVE_CONTEXT_MENU_TRIGGER_CLICKED: native_context_menu_trigger_t = 1;
pub const NATIVE_CONTEXT_MENU_TRIGGER_RIGHT_CLICKED: native_context_menu_trigger_t = 2;
pub const NATIVE_CONTEXT_MENU_TRIGGER_DOUBLE_CLICKED: native_context_menu_trigger_t = 3;
-pub type native_context_menu_trigger_t = ::std::os::raw::c_int;
+pub type native_context_menu_trigger_t = ::std::os::raw::c_uint;
pub const NATIVE_TRAY_ICON_POSITION_LEFT: native_tray_icon_position_t = 0;
pub const NATIVE_TRAY_ICON_POSITION_RIGHT: native_tray_icon_position_t = 1;
-pub type native_tray_icon_position_t = ::std::os::raw::c_int;
+pub type native_tray_icon_position_t = ::std::os::raw::c_uint;
#[doc = " Opaque TrayIcon handle.\n\n A generational index into the library's handle table, NOT a pointer:\n never dereference it, and compare it against NATIVE_INVALID_TRAY_ICON rather than NULL.\n Releasing a handle invalidates it; later calls fail safely instead of\n touching freed memory."]
pub type native_tray_icon_t = u64;
#[doc = " Owning list of TrayIcon handles."]
@@ -4383,7 +4679,7 @@ pub const NATIVE_TRAY_ICON_EVENT_TYPE_CLICKED: native_tray_icon_event_type_t = 0
pub const NATIVE_TRAY_ICON_EVENT_TYPE_RIGHT_CLICKED: native_tray_icon_event_type_t = 1;
pub const NATIVE_TRAY_ICON_EVENT_TYPE_DOUBLE_CLICKED: native_tray_icon_event_type_t = 2;
#[doc = " Which concrete TrayIconEvent arrived."]
-pub type native_tray_icon_event_type_t = ::std::os::raw::c_int;
+pub type native_tray_icon_event_type_t = ::std::os::raw::c_uint;
#[doc = " One TrayIconEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Copy, Clone)]
@@ -4625,7 +4921,7 @@ pub const NATIVE_URL_OPEN_ERROR_CODE_INVALID_URL_UNSUPPORTED_SCHEME: native_url_
3;
pub const NATIVE_URL_OPEN_ERROR_CODE_UNSUPPORTED_PLATFORM: native_url_open_error_code_t = 4;
pub const NATIVE_URL_OPEN_ERROR_CODE_INVOCATION_FAILED: native_url_open_error_code_t = 5;
-pub type native_url_open_error_code_t = ::std::os::raw::c_int;
+pub type native_url_open_error_code_t = ::std::os::raw::c_uint;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct native_url_open_result_t {
@@ -4661,7 +4957,7 @@ pub const NATIVE_WINDOW_DRAG_EVENT_TYPE_MOVED: native_window_drag_event_type_t =
pub const NATIVE_WINDOW_DRAG_EVENT_TYPE_ENDED: native_window_drag_event_type_t = 1;
pub const NATIVE_WINDOW_DRAG_EVENT_TYPE_CANCELLED: native_window_drag_event_type_t = 2;
#[doc = " Which concrete WindowDragEvent arrived."]
-pub type native_window_drag_event_type_t = ::std::os::raw::c_int;
+pub type native_window_drag_event_type_t = ::std::os::raw::c_uint;
#[doc = " One WindowDragEvent, tagged by its concrete type.\n\n Synchronous callbacks borrow this payload until they return. Async callbacks\n borrow it until event_delivery_complete. Copy anything needed after that."]
#[repr(C)]
#[derive(Debug, Copy, Clone)]
diff --git a/bindings/rust/nativeapi/src/capture_source.rs b/bindings/rust/nativeapi/src/capture_source.rs
new file mode 100644
index 00000000..e2cd4a8e
--- /dev/null
+++ b/bindings/rust/nativeapi/src/capture_source.rs
@@ -0,0 +1,122 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+#![allow(dead_code)]
+#![allow(unused_imports)]
+
+use cnativeapi;
+use std::ffi::{CStr, CString};
+
+use crate::display::Display;
+use crate::window::Window;
+
+#[repr(i32)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
+pub enum CaptureSourceType {
+ None = 0,
+ Display = 1,
+ Window = 2,
+ Unknown = 3,
+}
+
+impl CaptureSourceType {
+ pub(crate) fn from_raw(raw: cnativeapi::native_capture_source_type_t) -> Self {
+ match raw {
+ cnativeapi::NATIVE_CAPTURE_SOURCE_TYPE_NONE => Self::None,
+ cnativeapi::NATIVE_CAPTURE_SOURCE_TYPE_DISPLAY => Self::Display,
+ cnativeapi::NATIVE_CAPTURE_SOURCE_TYPE_WINDOW => Self::Window,
+ cnativeapi::NATIVE_CAPTURE_SOURCE_TYPE_UNKNOWN => Self::Unknown,
+ _ => Self::None,
+ }
+ }
+
+ pub(crate) fn to_raw(self) -> cnativeapi::native_capture_source_type_t {
+ self as cnativeapi::native_capture_source_type_t
+ }
+}
+
+/// Owned handle to a native `CaptureSource`.
+#[derive(Debug)]
+#[repr(transparent)]
+pub struct CaptureSource {
+ handle: cnativeapi::native_capture_source_t,
+}
+
+impl CaptureSource {
+ /// Adopts a handle returned by the C API.
+ ///
+ /// # Safety
+ /// `handle` must be a live handle that is not owned elsewhere.
+ pub unsafe fn from_raw(handle: cnativeapi::native_capture_source_t) -> Option {
+ if handle == 0 {
+ None
+ } else {
+ Some(Self { handle })
+ }
+ }
+
+ /// Borrows the underlying C handle.
+ pub fn as_raw(&self) -> cnativeapi::native_capture_source_t {
+ self.handle
+ }
+
+ pub fn from_display(display: Option<&Display>) -> Option {
+ unsafe {
+ CaptureSource::from_raw(cnativeapi::native_capture_source_from_display(display.map_or(0, |value| value.as_raw())))
+ }
+ }
+
+ pub fn from_window(window: Option<&Window>) -> Option {
+ unsafe {
+ CaptureSource::from_raw(cnativeapi::native_capture_source_from_window(window.map_or(0, |value| value.as_raw())))
+ }
+ }
+
+ pub fn r#type(&self) -> CaptureSourceType {
+ unsafe {
+ CaptureSourceType::from_raw(cnativeapi::native_capture_source_get_type(self.handle))
+ }
+ }
+
+ pub fn name(&self) -> Option {
+ unsafe {
+ let ptr = cnativeapi::native_capture_source_get_name(self.handle);
+ if ptr.is_null() {
+ return None;
+ }
+ let value = CStr::from_ptr(ptr).to_string_lossy().into_owned();
+ cnativeapi::free_c_str(ptr);
+ Some(value)
+ }
+ }
+
+}
+
+impl Drop for CaptureSource {
+ fn drop(&mut self) {
+ if self.handle != 0 {
+ unsafe { cnativeapi::native_capture_source_free(self.handle) };
+ }
+ }
+}
+
+/// A `CaptureSource` owned elsewhere; using it does not release it.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct CaptureSourceRef(cnativeapi::native_capture_source_t);
+
+impl CaptureSourceRef {
+ pub(crate) fn from_raw(handle: cnativeapi::native_capture_source_t) -> Self {
+ Self(handle)
+ }
+
+ pub fn as_raw(&self) -> cnativeapi::native_capture_source_t {
+ self.0
+ }
+
+ /// Runs `f` against the borrowed handle. The `CaptureSource` it receives
+ /// must not outlive the call.
+ pub fn with(&self, f: impl FnOnce(&CaptureSource) -> R) -> R {
+ let borrowed = std::mem::ManuallyDrop::new(CaptureSource { handle: self.0 });
+ f(&borrowed)
+ }
+}
+
diff --git a/bindings/rust/nativeapi/src/modules.rs b/bindings/rust/nativeapi/src/modules.rs
index f85e4146..db6df131 100644
--- a/bindings/rust/nativeapi/src/modules.rs
+++ b/bindings/rust/nativeapi/src/modules.rs
@@ -6,6 +6,7 @@
pub mod accessibility_manager;
pub mod app_info;
pub mod application;
+pub mod capture_source;
pub mod clipboard;
pub mod color;
pub mod device_info;
@@ -28,6 +29,8 @@ pub mod placement;
pub mod positioning_strategy;
pub mod preferences;
pub mod protocol_handler;
+pub mod screen_capturer;
+pub mod screen_recorder;
pub mod secure_storage;
pub mod shortcut;
pub mod shortcut_manager;
@@ -47,6 +50,7 @@ pub mod window_taskbar;
pub use accessibility_manager::{AccessibilityManager};
pub use app_info::{AppInfo};
pub use application::{Brightness, ApplicationEvent, Application};
+pub use capture_source::{CaptureSourceType, CaptureSource, CaptureSourceRef};
pub use clipboard::{ClipboardData, ClipboardEvent, Clipboard};
pub use color::{Color};
pub use device_info::{DeviceInfo};
@@ -69,6 +73,8 @@ pub use placement::{Placement};
pub use positioning_strategy::{PositioningStrategyType, PositioningStrategy, PositioningStrategyRef};
pub use preferences::{Preferences, PreferencesRef};
pub use protocol_handler::{ProtocolHandlerEvent, ProtocolHandler};
+pub use screen_capturer::{CaptureSourceSelectionOptions, ScreenCaptureOptions, ScreenCapturer};
+pub use screen_recorder::{ScreenRecordingState, ScreenRecordingOptions, ScreenRecordingEvent, ScreenRecorder, ScreenRecorderRef};
pub use secure_storage::{SecureStorage, SecureStorageRef};
pub use shortcut::{ShortcutId, ShortcutScope, ShortcutOptions, ShortcutEvent, Shortcut, ShortcutRef};
pub use shortcut_manager::{ShortcutManager};
diff --git a/bindings/rust/nativeapi/src/screen_capturer.rs b/bindings/rust/nativeapi/src/screen_capturer.rs
new file mode 100644
index 00000000..38e53c2b
--- /dev/null
+++ b/bindings/rust/nativeapi/src/screen_capturer.rs
@@ -0,0 +1,153 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+#![allow(dead_code)]
+#![allow(unused_imports)]
+
+use cnativeapi;
+use std::ffi::{CStr, CString};
+
+use crate::capture_source::{CaptureSource, CaptureSourceType};
+use crate::geometry::{RawOfRectangle, Rectangle};
+use crate::image::Image;
+use crate::window::Window;
+
+#[derive(Debug)]
+pub struct CaptureSourceSelectionOptions {
+ pub allow_displays: bool,
+ pub allow_windows: bool,
+ pub parent_window: Option,
+}
+
+impl CaptureSourceSelectionOptions {
+ pub(crate) unsafe fn from_raw(raw: &cnativeapi::native_capture_source_selection_options_t) -> Self {
+ Self {
+ allow_displays: raw.allow_displays,
+ allow_windows: raw.allow_windows,
+ parent_window: Window::from_raw(cnativeapi::native_handle_retain(raw.parent_window)),
+ }
+ }
+
+ pub(crate) fn to_raw(&self) -> RawOfCaptureSourceSelectionOptions {
+ let mut raw = cnativeapi::native_capture_source_selection_options_t::default();
+ raw.allow_displays = self.allow_displays;
+ raw.allow_windows = self.allow_windows;
+ raw.parent_window = self.parent_window.as_ref().map_or(0, |v| v.as_raw());
+ RawOfCaptureSourceSelectionOptions { raw, _owned: () }
+ }
+}
+
+/// `CaptureSourceSelectionOptions` in its C form, keeping any borrowed buffers alive.
+pub(crate) struct RawOfCaptureSourceSelectionOptions {
+ pub(crate) raw: cnativeapi::native_capture_source_selection_options_t,
+ _owned: (),
+}
+
+#[derive(Debug, Clone, PartialEq)]
+pub struct ScreenCaptureOptions {
+ pub include_cursor: bool,
+ pub crop_enabled: bool,
+ pub crop: Rectangle,
+}
+
+impl ScreenCaptureOptions {
+ pub(crate) unsafe fn from_raw(raw: &cnativeapi::native_screen_capture_options_t) -> Self {
+ Self {
+ include_cursor: raw.include_cursor,
+ crop_enabled: raw.crop_enabled,
+ crop: Rectangle::from_raw(&raw.crop),
+ }
+ }
+
+ pub(crate) fn to_raw(&self) -> RawOfScreenCaptureOptions {
+ let mut raw = cnativeapi::native_screen_capture_options_t::default();
+ raw.include_cursor = self.include_cursor;
+ raw.crop_enabled = self.crop_enabled;
+ let crop_nested = self.crop.to_raw();
+ raw.crop = crop_nested.raw;
+ RawOfScreenCaptureOptions { raw, _owned: (crop_nested, ()) }
+ }
+}
+
+/// `ScreenCaptureOptions` in its C form, keeping any borrowed buffers alive.
+pub(crate) struct RawOfScreenCaptureOptions {
+ pub(crate) raw: cnativeapi::native_screen_capture_options_t,
+ _owned: (RawOfRectangle, ()),
+}
+
+pub struct ScreenCapturer;
+
+impl ScreenCapturer {
+ pub fn is_supported() -> bool {
+ unsafe {
+ cnativeapi::native_screen_capturer_is_supported()
+ }
+ }
+
+ pub fn is_source_selection_supported() -> bool {
+ unsafe {
+ cnativeapi::native_screen_capturer_is_source_selection_supported()
+ }
+ }
+
+ pub fn is_direct_capture_supported(r#type: CaptureSourceType) -> bool {
+ unsafe {
+ cnativeapi::native_screen_capturer_is_direct_capture_supported(r#type.to_raw())
+ }
+ }
+
+ pub fn select_source(options: &CaptureSourceSelectionOptions, callback: impl Fn(bool, Option) + 'static) {
+ let options_raw = options.to_raw();
+ unsafe extern "C" fn trampoline(arg0: bool, arg1: u64, delivery: cnativeapi::native_event_delivery_t, user_data: *mut std::ffi::c_void) {
+ struct Delivery(cnativeapi::native_event_delivery_t);
+ impl Drop for Delivery { fn drop(&mut self) { unsafe { cnativeapi::native_event_delivery_complete(self.0, true); } } }
+ let _delivery = Delivery(delivery);
+ if !cnativeapi::native_event_delivery_is_active(delivery) { return; }
+ if user_data.is_null() {
+ return;
+ }
+ let callback = &*(user_data as *const std::sync::Arc)>);
+ let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| callback(arg0, CaptureSource::from_raw(cnativeapi::native_handle_retain(arg1)))));
+ }
+ fn into_user_data(callback: std::sync::Arc)>) -> *mut std::ffi::c_void {
+ Box::into_raw(Box::new(callback)) as *mut std::ffi::c_void
+ }
+ unsafe extern "C" fn release(user_data: *mut std::ffi::c_void) {
+ if !user_data.is_null() {
+ drop(Box::from_raw(user_data as *mut std::sync::Arc)>));
+ }
+ }
+ let callback_user_data = into_user_data(std::sync::Arc::new(callback));
+ unsafe {
+ cnativeapi::native_screen_capturer_select_source(options_raw.raw, Some(trampoline), callback_user_data, Some(release));
+ }
+ }
+
+ pub fn capture(source: Option<&CaptureSource>, options: &ScreenCaptureOptions, callback: impl Fn(bool, Option) + 'static) {
+ let options_raw = options.to_raw();
+ unsafe extern "C" fn trampoline(arg0: bool, arg1: u64, delivery: cnativeapi::native_event_delivery_t, user_data: *mut std::ffi::c_void) {
+ struct Delivery(cnativeapi::native_event_delivery_t);
+ impl Drop for Delivery { fn drop(&mut self) { unsafe { cnativeapi::native_event_delivery_complete(self.0, true); } } }
+ let _delivery = Delivery(delivery);
+ if !cnativeapi::native_event_delivery_is_active(delivery) { return; }
+ if user_data.is_null() {
+ return;
+ }
+ let callback = &*(user_data as *const std::sync::Arc)>);
+ let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| callback(arg0, Image::from_raw(cnativeapi::native_handle_retain(arg1)))));
+ }
+ fn into_user_data(callback: std::sync::Arc)>) -> *mut std::ffi::c_void {
+ Box::into_raw(Box::new(callback)) as *mut std::ffi::c_void
+ }
+ unsafe extern "C" fn release(user_data: *mut std::ffi::c_void) {
+ if !user_data.is_null() {
+ drop(Box::from_raw(user_data as *mut std::sync::Arc)>));
+ }
+ }
+ let callback_user_data = into_user_data(std::sync::Arc::new(callback));
+ unsafe {
+ cnativeapi::native_screen_capturer_capture(source.map_or(0, |value| value.as_raw()), options_raw.raw, Some(trampoline), callback_user_data, Some(release));
+ }
+ }
+
+}
+
diff --git a/bindings/rust/nativeapi/src/screen_recorder.rs b/bindings/rust/nativeapi/src/screen_recorder.rs
new file mode 100644
index 00000000..060eb5d4
--- /dev/null
+++ b/bindings/rust/nativeapi/src/screen_recorder.rs
@@ -0,0 +1,244 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+#![allow(dead_code)]
+#![allow(unused_imports)]
+
+use cnativeapi;
+use std::ffi::{CStr, CString};
+
+use crate::capture_source::CaptureSource;
+use crate::screen_capturer::{RawOfScreenCaptureOptions, ScreenCaptureOptions};
+
+/// Identifies one registered event listener.
+pub type ListenerId = cnativeapi::native_listener_id_t;
+
+#[repr(i32)]
+#[derive(Debug, Copy, Clone, PartialEq, Eq)]
+pub enum ScreenRecordingState {
+ Idle = 0,
+ Starting = 1,
+ Recording = 2,
+ Stopping = 3,
+ Completed = 4,
+ Cancelled = 5,
+ Failed = 6,
+}
+
+impl ScreenRecordingState {
+ pub(crate) fn from_raw(raw: cnativeapi::native_screen_recording_state_t) -> Self {
+ match raw {
+ cnativeapi::NATIVE_SCREEN_RECORDING_STATE_IDLE => Self::Idle,
+ cnativeapi::NATIVE_SCREEN_RECORDING_STATE_STARTING => Self::Starting,
+ cnativeapi::NATIVE_SCREEN_RECORDING_STATE_RECORDING => Self::Recording,
+ cnativeapi::NATIVE_SCREEN_RECORDING_STATE_STOPPING => Self::Stopping,
+ cnativeapi::NATIVE_SCREEN_RECORDING_STATE_COMPLETED => Self::Completed,
+ cnativeapi::NATIVE_SCREEN_RECORDING_STATE_CANCELLED => Self::Cancelled,
+ cnativeapi::NATIVE_SCREEN_RECORDING_STATE_FAILED => Self::Failed,
+ _ => Self::Idle,
+ }
+ }
+
+ pub(crate) fn to_raw(self) -> cnativeapi::native_screen_recording_state_t {
+ self as cnativeapi::native_screen_recording_state_t
+ }
+}
+
+#[derive(Debug, Clone, PartialEq)]
+pub struct ScreenRecordingOptions {
+ pub capture: ScreenCaptureOptions,
+ pub frame_rate: f64,
+ pub video_bitrate: std::os::raw::c_ulong,
+}
+
+impl ScreenRecordingOptions {
+ pub(crate) unsafe fn from_raw(raw: &cnativeapi::native_screen_recording_options_t) -> Self {
+ Self {
+ capture: ScreenCaptureOptions::from_raw(&raw.capture),
+ frame_rate: raw.frame_rate,
+ video_bitrate: raw.video_bitrate,
+ }
+ }
+
+ pub(crate) fn to_raw(&self) -> RawOfScreenRecordingOptions {
+ let mut raw = cnativeapi::native_screen_recording_options_t::default();
+ let capture_nested = self.capture.to_raw();
+ raw.capture = capture_nested.raw;
+ raw.frame_rate = self.frame_rate;
+ raw.video_bitrate = self.video_bitrate;
+ RawOfScreenRecordingOptions { raw, _owned: (capture_nested, ()) }
+ }
+}
+
+/// `ScreenRecordingOptions` in its C form, keeping any borrowed buffers alive.
+pub(crate) struct RawOfScreenRecordingOptions {
+ pub(crate) raw: cnativeapi::native_screen_recording_options_t,
+ _owned: (RawOfScreenCaptureOptions, ()),
+}
+
+/// One `ScreenRecordingEvent`, in its concrete form.
+#[derive(Debug, Clone, PartialEq)]
+pub enum ScreenRecordingEvent {
+ Started,
+ Completed { file_path: Option, duration: f64 },
+ Cancelled,
+ Failed { message: Option },
+}
+
+impl ScreenRecordingEvent {
+ pub(crate) unsafe fn from_raw(raw: &cnativeapi::native_screen_recording_event_t) -> Option {
+ Some(match raw.type_ {
+ cnativeapi::NATIVE_SCREEN_RECORDING_EVENT_TYPE_STARTED => Self::Started,
+ cnativeapi::NATIVE_SCREEN_RECORDING_EVENT_TYPE_COMPLETED => Self::Completed { file_path: if raw.data.completed.file_path.is_null() { None } else { Some(CStr::from_ptr(raw.data.completed.file_path).to_string_lossy().into_owned()) }, duration: raw.data.completed.duration },
+ cnativeapi::NATIVE_SCREEN_RECORDING_EVENT_TYPE_CANCELLED => Self::Cancelled,
+ cnativeapi::NATIVE_SCREEN_RECORDING_EVENT_TYPE_FAILED => Self::Failed { message: if raw.data.failed.message.is_null() { None } else { Some(CStr::from_ptr(raw.data.failed.message).to_string_lossy().into_owned()) } },
+ _ => return None,
+ })
+ }
+}
+
+/// Owned handle to a native `ScreenRecorder`.
+#[derive(Debug)]
+#[repr(transparent)]
+pub struct ScreenRecorder {
+ handle: cnativeapi::native_screen_recorder_t,
+}
+
+impl ScreenRecorder {
+ /// Adopts a handle returned by the C API.
+ ///
+ /// # Safety
+ /// `handle` must be a live handle that is not owned elsewhere.
+ pub unsafe fn from_raw(handle: cnativeapi::native_screen_recorder_t) -> Option {
+ if handle == 0 {
+ None
+ } else {
+ Some(Self { handle })
+ }
+ }
+
+ /// Borrows the underlying C handle.
+ pub fn as_raw(&self) -> cnativeapi::native_screen_recorder_t {
+ self.handle
+ }
+
+ /// Creates a new `ScreenRecorder`; returns `None` if the native side failed.
+ pub fn new() -> Option {
+ unsafe {
+ Self::from_raw(cnativeapi::native_screen_recorder_create())
+ }
+ }
+
+ pub fn is_supported() -> bool {
+ unsafe {
+ cnativeapi::native_screen_recorder_is_supported()
+ }
+ }
+
+ pub fn start(&self, source: Option<&CaptureSource>, file_path: &str, options: &ScreenRecordingOptions) -> bool {
+ let file_path_native = CString::new(file_path).expect("string argument contains interior nul byte");
+ let options_raw = options.to_raw();
+ unsafe {
+ cnativeapi::native_screen_recorder_start(self.handle, source.map_or(0, |value| value.as_raw()), file_path_native.as_ptr(), options_raw.raw)
+ }
+ }
+
+ pub fn stop(&self) -> bool {
+ unsafe {
+ cnativeapi::native_screen_recorder_stop(self.handle)
+ }
+ }
+
+ pub fn cancel(&self) -> bool {
+ unsafe {
+ cnativeapi::native_screen_recorder_cancel(self.handle)
+ }
+ }
+
+ pub fn state(&self) -> ScreenRecordingState {
+ unsafe {
+ ScreenRecordingState::from_raw(cnativeapi::native_screen_recorder_get_state(self.handle))
+ }
+ }
+
+ pub fn is_active(&self) -> bool {
+ unsafe {
+ cnativeapi::native_screen_recorder_is_active(self.handle)
+ }
+ }
+
+ pub fn duration(&self) -> f64 {
+ unsafe {
+ cnativeapi::native_screen_recorder_get_duration(self.handle)
+ }
+ }
+
+ pub fn file_path(&self) -> Option {
+ unsafe {
+ let ptr = cnativeapi::native_screen_recorder_get_file_path(self.handle);
+ if ptr.is_null() {
+ return None;
+ }
+ let value = CStr::from_ptr(ptr).to_string_lossy().into_owned();
+ cnativeapi::free_c_str(ptr);
+ Some(value)
+ }
+ }
+
+ /// Registers `callback` for every `ScreenRecordingEvent` this `ScreenRecorder` emits.
+ ///
+ /// The closure is dropped on the main thread once the listener is removed
+ /// or its emitter destroyed.
+ pub fn add_listener(&self, callback: impl Fn(&ScreenRecordingEvent) + 'static) -> ListenerId {
+ unsafe extern "C" fn trampoline(event: *const cnativeapi::native_screen_recording_event_t, user_data: *mut std::ffi::c_void) {
+ if event.is_null() || user_data.is_null() {
+ return;
+ }
+ let callback = &*(user_data as *const Box);
+ if let Some(event) = ScreenRecordingEvent::from_raw(&*event) {
+ callback(&event);
+ }
+ }
+ let boxed: Box> = Box::new(Box::new(callback));
+ let user_data = Box::into_raw(boxed) as *mut std::ffi::c_void;
+ unsafe extern "C" fn release(user_data: *mut std::ffi::c_void) {
+ drop(Box::from_raw(user_data as *mut Box));
+ }
+ unsafe { cnativeapi::native_screen_recorder_add_listener(self.handle, Some(trampoline), user_data, Some(release)) }
+ }
+
+ /// Unregisters a listener. Returns false if unknown.
+ pub fn remove_listener(&self, listener_id: ListenerId) -> bool {
+ unsafe { cnativeapi::native_screen_recorder_remove_listener(self.handle, listener_id) }
+ }
+
+}
+
+impl Drop for ScreenRecorder {
+ fn drop(&mut self) {
+ if self.handle != 0 {
+ unsafe { cnativeapi::native_screen_recorder_free(self.handle) };
+ }
+ }
+}
+
+/// A `ScreenRecorder` owned elsewhere; using it does not release it.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct ScreenRecorderRef(cnativeapi::native_screen_recorder_t);
+
+impl ScreenRecorderRef {
+ pub(crate) fn from_raw(handle: cnativeapi::native_screen_recorder_t) -> Self {
+ Self(handle)
+ }
+
+ pub fn as_raw(&self) -> cnativeapi::native_screen_recorder_t {
+ self.0
+ }
+
+ /// Runs `f` against the borrowed handle. The `ScreenRecorder` it receives
+ /// must not outlive the call.
+ pub fn with(&self, f: impl FnOnce(&ScreenRecorder) -> R) -> R {
+ let borrowed = std::mem::ManuallyDrop::new(ScreenRecorder { handle: self.0 });
+ f(&borrowed)
+ }
+}
+
diff --git a/bindings/rust/nativeapi/tests/screen_capture.rs b/bindings/rust/nativeapi/tests/screen_capture.rs
new file mode 100644
index 00000000..7f4914e6
--- /dev/null
+++ b/bindings/rust/nativeapi/tests/screen_capture.rs
@@ -0,0 +1,37 @@
+use nativeapi::{
+ CaptureSourceType, Rectangle, ScreenCaptureOptions, ScreenCapturer, ScreenRecorder,
+ ScreenRecordingOptions, ScreenRecordingState,
+};
+
+// No desktop access: links the real capture backend and exercises nested FFI
+// values, source validation and lifecycle rejection without requesting capture.
+#[test]
+fn invalid_request_keeps_recorder_idle() {
+ assert!(!ScreenCapturer::is_direct_capture_supported(
+ CaptureSourceType::None
+ ));
+ assert!(!ScreenCapturer::is_direct_capture_supported(
+ CaptureSourceType::Unknown
+ ));
+ let options = ScreenRecordingOptions {
+ capture: ScreenCaptureOptions {
+ include_cursor: false,
+ crop_enabled: true,
+ crop: Rectangle {
+ x: 1.0,
+ y: 2.0,
+ width: 32.0,
+ height: 48.0,
+ },
+ },
+ frame_rate: 30.0,
+ video_bitrate: 1_000_000,
+ };
+ let recorder = ScreenRecorder::new().expect("recorder handle");
+ assert!(!recorder.start(None, "relative.mp4", &options));
+ assert_eq!(recorder.state(), ScreenRecordingState::Idle);
+ assert_eq!(recorder.duration(), 0.0);
+ assert!(!recorder.is_active());
+ assert!(!recorder.stop());
+ assert!(!recorder.cancel());
+}
diff --git a/bindings/swift/Package.swift b/bindings/swift/Package.swift
index b560b7f0..cdaeb232 100644
--- a/bindings/swift/Package.swift
+++ b/bindings/swift/Package.swift
@@ -45,6 +45,10 @@ nativeLinkerSettings = [
.linkedFramework("Carbon"),
.linkedFramework("IOKit"),
.linkedFramework("ServiceManagement"),
+ .linkedFramework("AVFoundation"),
+ .linkedFramework("CoreMedia"),
+ .linkedFramework("CoreVideo"),
+ .linkedFramework("VideoToolbox"),
]
systemTargets = []
#elseif os(Linux)
@@ -103,6 +107,14 @@ nativeLinkerSettings = [
.linkedLibrary("version"),
.linkedLibrary("psapi"),
.linkedLibrary("shlwapi"),
+ .linkedLibrary("d3d11"),
+ .linkedLibrary("dxgi"),
+ .linkedLibrary("windowsapp"),
+ .linkedLibrary("runtimeobject"),
+ .linkedLibrary("mfplat"),
+ .linkedLibrary("mfreadwrite"),
+ .linkedLibrary("mfuuid"),
+ .linkedLibrary("windowscodecs"),
]
systemTargets = []
// WinUI 3 is opt-in in the core's CMake build; the Swift package ships the
diff --git a/bindings/swift/Sources/NativeAPI/CaptureSource.swift b/bindings/swift/Sources/NativeAPI/CaptureSource.swift
new file mode 100644
index 00000000..7fe340ce
--- /dev/null
+++ b/bindings/swift/Sources/NativeAPI/CaptureSource.swift
@@ -0,0 +1,79 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Code generated by ./codegen. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+import CNativeAPI
+import Foundation
+
+public enum CaptureSourceType: CInt {
+ case none = 0
+ case display = 1
+ case window = 2
+ case unknown = 3
+
+ init(raw: native_capture_source_type_t) {
+ switch raw {
+ case NATIVE_CAPTURE_SOURCE_TYPE_NONE: self = .none
+ case NATIVE_CAPTURE_SOURCE_TYPE_DISPLAY: self = .display
+ case NATIVE_CAPTURE_SOURCE_TYPE_WINDOW: self = .window
+ case NATIVE_CAPTURE_SOURCE_TYPE_UNKNOWN: self = .unknown
+ default: self = .none
+ }
+ }
+
+ var raw: native_capture_source_type_t {
+ native_capture_source_type_t(rawValue: numericCast(self.rawValue))
+ }
+}
+
+/// Owned handle to a native `CaptureSource`.
+public class CaptureSource {
+ public let nativeHandle: native_capture_source_t
+ private let ownsHandle: Bool
+ private var disposed = false
+
+ public init(nativeHandle: native_capture_source_t, ownsHandle: Bool = true) {
+ self.nativeHandle = nativeHandle
+ self.ownsHandle = ownsHandle
+ }
+
+ deinit {
+ guard ownsHandle, !disposed else { return }
+ native_handle_finalize(UnsafeMutableRawPointer(bitPattern: UInt(nativeHandle)))
+ }
+
+ /// Releases this reference now; call on the UI thread.
+ public func dispose() {
+ guard ownsHandle, !disposed else { return }
+ disposed = true
+ releaseNativeHandle()
+ }
+
+ /// Releases this reference with its own C ABI function.
+ public func releaseNativeHandle() {
+ native_capture_source_free(nativeHandle)
+ }
+
+ public static func fromDisplay(_ display: Display?) -> CaptureSource? {
+ let handle = native_capture_source_from_display(display?.nativeHandle ?? 0)
+ guard handle != NATIVE_INVALID_CAPTURE_SOURCE else { return nil }
+ return CaptureSource(nativeHandle: handle)
+ }
+
+ public static func fromWindow(_ window: Window?) -> CaptureSource? {
+ let handle = native_capture_source_from_window(window?.nativeHandle ?? 0)
+ guard handle != NATIVE_INVALID_CAPTURE_SOURCE else { return nil }
+ return CaptureSource(nativeHandle: handle)
+ }
+
+ public var type: CaptureSourceType {
+ return CaptureSourceType(raw: native_capture_source_get_type(nativeHandle))
+ }
+
+ public var name: String? {
+ guard let value = native_capture_source_get_name(nativeHandle) else { return nil }
+ defer { free_c_str(value) }
+ return String(cString: value)
+ }
+
+}
diff --git a/bindings/swift/Sources/NativeAPI/ScreenCapturer.swift b/bindings/swift/Sources/NativeAPI/ScreenCapturer.swift
new file mode 100644
index 00000000..f8a16df4
--- /dev/null
+++ b/bindings/swift/Sources/NativeAPI/ScreenCapturer.swift
@@ -0,0 +1,95 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Code generated by ./codegen. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+import CNativeAPI
+import Foundation
+
+public struct CaptureSourceSelectionOptions {
+ public var allowDisplays: Bool
+ public var allowWindows: Bool
+ public var parentWindow: Window?
+
+ public init(allowDisplays: Bool, allowWindows: Bool, parentWindow: Window? = nil) {
+ self.allowDisplays = allowDisplays
+ self.allowWindows = allowWindows
+ self.parentWindow = parentWindow
+ }
+}
+
+extension CaptureSourceSelectionOptions {
+ init(raw: native_capture_source_selection_options_t) {
+ self.init(allowDisplays: raw.allow_displays, allowWindows: raw.allow_windows, parentWindow: nativeapiOwned(raw.parent_window) { Window(nativeHandle: $0) })
+ }
+
+ func toRaw() -> native_capture_source_selection_options_t {
+ var raw = native_capture_source_selection_options_t()
+ raw.allow_displays = self.allowDisplays
+ raw.allow_windows = self.allowWindows
+ raw.parent_window = self.parentWindow?.nativeHandle ?? 0
+ return raw
+ }
+}
+
+public struct ScreenCaptureOptions {
+ public var includeCursor: Bool
+ public var cropEnabled: Bool
+ public var crop: Rectangle
+
+ public init(includeCursor: Bool, cropEnabled: Bool, crop: Rectangle) {
+ self.includeCursor = includeCursor
+ self.cropEnabled = cropEnabled
+ self.crop = crop
+ }
+}
+
+extension ScreenCaptureOptions {
+ init(raw: native_screen_capture_options_t) {
+ self.init(includeCursor: raw.include_cursor, cropEnabled: raw.crop_enabled, crop: Rectangle(raw: raw.crop))
+ }
+
+ func toRaw() -> native_screen_capture_options_t {
+ var raw = native_screen_capture_options_t()
+ raw.include_cursor = self.includeCursor
+ raw.crop_enabled = self.cropEnabled
+ raw.crop = self.crop.toRaw()
+ return raw
+ }
+}
+
+public enum ScreenCapturer {
+ public static func isSupported() -> Bool {
+ return native_screen_capturer_is_supported()
+ }
+
+ public static func isSourceSelectionSupported() -> Bool {
+ return native_screen_capturer_is_source_selection_supported()
+ }
+
+ public static func isDirectCaptureSupported(_ type: CaptureSourceType) -> Bool {
+ return native_screen_capturer_is_direct_capture_supported(type.raw)
+ }
+
+ public static func selectSource(_ options: CaptureSourceSelectionOptions, callback: @escaping (Bool, CaptureSource?) -> Void) -> Void {
+ let optionsRaw = options.toRaw()
+ let callbackContext = Unmanaged.passRetained(CallbackBox2(callback)).toOpaque()
+ let callbackTrampoline: @convention(c) (Bool, native_capture_source_t, native_event_delivery_t, UnsafeMutableRawPointer?) -> Void = { arg0, arg1, delivery, userData in
+ defer { _ = native_event_delivery_complete(delivery, true) }
+ guard let userData else { return }
+ Unmanaged>.fromOpaque(userData).takeUnretainedValue().body(arg0, nativeapiOwned(arg1) { CaptureSource(nativeHandle: $0) })
+ }
+ native_screen_capturer_select_source(optionsRaw, callbackTrampoline, callbackContext, nativeapiReleaseUserData)
+ }
+
+ public static func capture(_ source: CaptureSource?, options: ScreenCaptureOptions, callback: @escaping (Bool, Image?) -> Void) -> Void {
+ let optionsRaw = options.toRaw()
+ let callbackContext = Unmanaged.passRetained(CallbackBox2(callback)).toOpaque()
+ let callbackTrampoline: @convention(c) (Bool, native_image_t, native_event_delivery_t, UnsafeMutableRawPointer?) -> Void = { arg0, arg1, delivery, userData in
+ defer { _ = native_event_delivery_complete(delivery, true) }
+ guard let userData else { return }
+ Unmanaged>.fromOpaque(userData).takeUnretainedValue().body(arg0, nativeapiOwned(arg1) { Image(nativeHandle: $0) })
+ }
+ native_screen_capturer_capture(source?.nativeHandle ?? 0, optionsRaw, callbackTrampoline, callbackContext, nativeapiReleaseUserData)
+ }
+
+}
diff --git a/bindings/swift/Sources/NativeAPI/ScreenRecorder.swift b/bindings/swift/Sources/NativeAPI/ScreenRecorder.swift
new file mode 100644
index 00000000..ffe88d4e
--- /dev/null
+++ b/bindings/swift/Sources/NativeAPI/ScreenRecorder.swift
@@ -0,0 +1,169 @@
+// AUTO-GENERATED. DO NOT EDIT.
+// Code generated by ./codegen. DO NOT EDIT.
+// Any manual changes WILL BE LOST when this file is regenerated.
+
+import CNativeAPI
+import Foundation
+
+public enum ScreenRecordingState: CInt {
+ case idle = 0
+ case starting = 1
+ case recording = 2
+ case stopping = 3
+ case completed = 4
+ case cancelled = 5
+ case failed = 6
+
+ init(raw: native_screen_recording_state_t) {
+ switch raw {
+ case NATIVE_SCREEN_RECORDING_STATE_IDLE: self = .idle
+ case NATIVE_SCREEN_RECORDING_STATE_STARTING: self = .starting
+ case NATIVE_SCREEN_RECORDING_STATE_RECORDING: self = .recording
+ case NATIVE_SCREEN_RECORDING_STATE_STOPPING: self = .stopping
+ case NATIVE_SCREEN_RECORDING_STATE_COMPLETED: self = .completed
+ case NATIVE_SCREEN_RECORDING_STATE_CANCELLED: self = .cancelled
+ case NATIVE_SCREEN_RECORDING_STATE_FAILED: self = .failed
+ default: self = .idle
+ }
+ }
+
+ var raw: native_screen_recording_state_t {
+ native_screen_recording_state_t(rawValue: numericCast(self.rawValue))
+ }
+}
+
+public struct ScreenRecordingOptions {
+ public var capture: ScreenCaptureOptions
+ public var frameRate: Double
+ public var videoBitrate: CUnsignedLong
+
+ public init(capture: ScreenCaptureOptions, frameRate: Double, videoBitrate: CUnsignedLong) {
+ self.capture = capture
+ self.frameRate = frameRate
+ self.videoBitrate = videoBitrate
+ }
+}
+
+extension ScreenRecordingOptions {
+ init(raw: native_screen_recording_options_t) {
+ self.init(capture: ScreenCaptureOptions(raw: raw.capture), frameRate: raw.frame_rate, videoBitrate: raw.video_bitrate)
+ }
+
+ func toRaw() -> native_screen_recording_options_t {
+ var raw = native_screen_recording_options_t()
+ raw.capture = self.capture.toRaw()
+ raw.frame_rate = self.frameRate
+ raw.video_bitrate = self.videoBitrate
+ return raw
+ }
+}
+
+/// One `ScreenRecordingEvent`, in its concrete form.
+public enum ScreenRecordingEvent {
+ case started
+ case completed(filePath: String?, duration: Double)
+ case cancelled
+ case failed(message: String?)
+
+ init?(raw: native_screen_recording_event_t) {
+ switch raw.type {
+ case NATIVE_SCREEN_RECORDING_EVENT_TYPE_STARTED: self = .started
+ case NATIVE_SCREEN_RECORDING_EVENT_TYPE_COMPLETED: self = .completed(filePath: raw.data.completed.file_path.map { String(cString: $0) }, duration: raw.data.completed.duration)
+ case NATIVE_SCREEN_RECORDING_EVENT_TYPE_CANCELLED: self = .cancelled
+ case NATIVE_SCREEN_RECORDING_EVENT_TYPE_FAILED: self = .failed(message: raw.data.failed.message.map { String(cString: $0) })
+ default: return nil
+ }
+ }
+}
+
+/// Owned handle to a native `ScreenRecorder`.
+public class ScreenRecorder {
+ public let nativeHandle: native_screen_recorder_t
+ private let ownsHandle: Bool
+ private var disposed = false
+
+ public init(nativeHandle: native_screen_recorder_t, ownsHandle: Bool = true) {
+ self.nativeHandle = nativeHandle
+ self.ownsHandle = ownsHandle
+ }
+
+ deinit {
+ guard ownsHandle, !disposed else { return }
+ native_handle_finalize(UnsafeMutableRawPointer(bitPattern: UInt(nativeHandle)))
+ }
+
+ /// Releases this reference now; call on the UI thread.
+ public func dispose() {
+ guard ownsHandle, !disposed else { return }
+ disposed = true
+ releaseNativeHandle()
+ }
+
+ /// Releases this reference with its own C ABI function.
+ public func releaseNativeHandle() {
+ native_screen_recorder_free(nativeHandle)
+ }
+
+ /// Creates a new `ScreenRecorder`; returns nil if the native side failed.
+ public class func create() -> ScreenRecorder? {
+ let handle = native_screen_recorder_create()
+ guard handle != NATIVE_INVALID_SCREEN_RECORDER else { return nil }
+ return ScreenRecorder(nativeHandle: handle)
+ }
+
+ public static func isSupported() -> Bool {
+ return native_screen_recorder_is_supported()
+ }
+
+ public func start(_ source: CaptureSource?, filePath: String, options: ScreenRecordingOptions) -> Bool {
+ let filePathCString = strdup(filePath)
+ defer { free(filePathCString) }
+ let optionsRaw = options.toRaw()
+ return native_screen_recorder_start(nativeHandle, source?.nativeHandle ?? 0, filePathCString, optionsRaw)
+ }
+
+ public func stop() -> Bool {
+ return native_screen_recorder_stop(nativeHandle)
+ }
+
+ public func cancel() -> Bool {
+ return native_screen_recorder_cancel(nativeHandle)
+ }
+
+ public var state: ScreenRecordingState {
+ return ScreenRecordingState(raw: native_screen_recorder_get_state(nativeHandle))
+ }
+
+ public var isActive: Bool {
+ return native_screen_recorder_is_active(nativeHandle)
+ }
+
+ public var duration: Double {
+ return native_screen_recorder_get_duration(nativeHandle)
+ }
+
+ public var filePath: String? {
+ guard let value = native_screen_recorder_get_file_path(nativeHandle) else { return nil }
+ defer { free_c_str(value) }
+ return String(cString: value)
+ }
+
+ /// Registers `callback` for every `ScreenRecordingEvent` this `ScreenRecorder` emits.
+ ///
+ /// The closure runs synchronously on the UI thread; the context is
+ /// released through the C ABI when the listener is removed.
+ @discardableResult public func addListener(_ callback: @escaping (ScreenRecordingEvent) -> Void) -> ListenerId {
+ let context = Unmanaged.passRetained(CallbackBox1(callback)).toOpaque()
+ let trampoline: @convention(c) (UnsafePointer?, UnsafeMutableRawPointer?) -> Void = { event, userData in
+ guard let event, let userData, let value = ScreenRecordingEvent(raw: event.pointee) else { return }
+ Unmanaged>.fromOpaque(userData).takeUnretainedValue().body(value)
+ }
+ return native_screen_recorder_add_listener(nativeHandle, trampoline, context, nativeapiReleaseUserData)
+ }
+
+ /// Unregisters a listener. Returns false if unknown.
+ public func removeListener(_ listenerId: ListenerId) -> Bool {
+ native_screen_recorder_remove_listener(nativeHandle, listenerId)
+ }
+
+}
diff --git a/core b/core
index 3925fa38..af4fd6c3 160000
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 3925fa380eb8507eb46c7b0f04df1ccf436c0a67
+Subproject commit af4fd6c3011ee2eaab91eb5fe4913f137bf29d52
diff --git a/examples/flutter_screen_capture_example/.gitignore b/examples/flutter_screen_capture_example/.gitignore
new file mode 100644
index 00000000..79f7ecab
--- /dev/null
+++ b/examples/flutter_screen_capture_example/.gitignore
@@ -0,0 +1,48 @@
+# Miscellaneous
+*.class
+*.log
+*.pyc
+*.swp
+.DS_Store
+.atom/
+.build/
+.buildlog/
+.history
+.svn/
+.swiftpm/
+migrate_working_dir/
+
+# IntelliJ related
+*.iml
+*.ipr
+*.iws
+.idea/
+
+# The .vscode folder contains launch configuration and tasks you configure in
+# VS Code which you may wish to be included in version control, so this line
+# is commented out by default.
+#.vscode/
+
+# Flutter/Dart/Pub related
+**/doc/api/
+**/ios/Flutter/.last_build_id
+.dart_tool/
+.flutter-plugins-dependencies
+.pub-cache/
+.pub/
+/build/
+/coverage/
+
+# Symbolication related
+app.*.symbols
+
+# Obfuscation related
+app.*.map.json
+
+# Android Studio will place build artifacts here
+/android/app/debug
+/android/app/profile
+/android/app/release
+
+# Widget Preview related
+.widget_preview/
diff --git a/examples/flutter_screen_capture_example/.metadata b/examples/flutter_screen_capture_example/.metadata
new file mode 100644
index 00000000..12f6820b
--- /dev/null
+++ b/examples/flutter_screen_capture_example/.metadata
@@ -0,0 +1,33 @@
+# This file tracks properties of this Flutter project.
+# Used by Flutter tool to assess capabilities and perform upgrades etc.
+#
+# This file should be version controlled and should not be manually edited.
+
+version:
+ revision: "5fc346839b5d0eef006ed8404392afb4dfae428d"
+ channel: "stable"
+
+project_type: app
+
+# Tracks metadata for the flutter migrate command
+migration:
+ platforms:
+ - platform: root
+ create_revision: 5fc346839b5d0eef006ed8404392afb4dfae428d
+ base_revision: 5fc346839b5d0eef006ed8404392afb4dfae428d
+ - platform: macos
+ create_revision: 5fc346839b5d0eef006ed8404392afb4dfae428d
+ base_revision: 5fc346839b5d0eef006ed8404392afb4dfae428d
+ - platform: windows
+ create_revision: 5fc346839b5d0eef006ed8404392afb4dfae428d
+ base_revision: 5fc346839b5d0eef006ed8404392afb4dfae428d
+
+ # User provided section
+
+ # List of Local paths (relative to this file) that should be
+ # ignored by the migrate tool.
+ #
+ # Files that are not part of the templates will be ignored by default.
+ unmanaged_files:
+ - 'lib/main.dart'
+ - 'ios/Runner.xcodeproj/project.pbxproj'
diff --git a/examples/flutter_screen_capture_example/README.md b/examples/flutter_screen_capture_example/README.md
new file mode 100644
index 00000000..2c6b5602
--- /dev/null
+++ b/examples/flutter_screen_capture_example/README.md
@@ -0,0 +1,52 @@
+# Screen capture example
+
+Flutter desktop example for `ScreenCapturer`, `CaptureSource`, and `ScreenRecorder`.
+Requires macOS 14+ or Windows 10 version 2004+ with an available H.264 encoder.
+Other platforms currently expose unsupported stubs.
+
+## Run
+
+From the workspace root:
+
+```sh
+flutter pub get
+cd examples/flutter_screen_capture_example
+flutter run -d macos
+# On Windows:
+flutter run -d windows
+```
+
+## Try it
+
+1. Select **This window**, a display, or **System picker…**. On Windows the
+ system picker lets the user choose either a window or a display.
+2. Optionally include the cursor or crop a rectangle. Crop coordinates are
+ physical pixels relative to the selected source, not desktop coordinates.
+3. **Take screenshot** shows a preview; **Save PNG** writes a separate file.
+4. **Start recording**, then **Stop & save** to finalize a silent H.264 MP4.
+ **Discard** cancels and removes the temporary recording.
+5. Choose an output directory to keep captures outside the default temporary
+ directory. Each output receives a unique filename; existing files are not
+ overwritten.
+
+Allow the operating system's screen-capture request when prompted. Direct
+capture on macOS may require Screen & System Audio Recording permission;
+use the system picker to select a source explicitly. Closing the app during an
+operation is blocked until it finishes or the recording is discarded.
+
+The controller keeps native source/image/recorder handles alive until completion
+and explicitly disposes them. Capture options are supplied explicitly because
+binding defaults do not yet consistently match the C++ defaults. The screenshot
+preview decodes the data URI returned by `Image.toBase64()`.
+
+## Validation and remaining work
+
+The macOS example has been built and run: actual screenshots (including a
+2560 × 1440 frame) and short MP4 recordings succeeded. The Windows core capture
+backend has desktop smoke coverage; the Flutter example has not yet been run
+on Windows. Longer recordings, permission denial, source disappearance and
+runtime shutdown still need end-to-end coverage.
+
+The current **Open folder**, **Open** and **Play** actions use `UrlOpener`, whose
+current implementation accepts HTTP/HTTPS only. Local files are saved correctly,
+but these actions report an error; open the displayed path manually for now.
diff --git a/examples/flutter_screen_capture_example/analysis_options.yaml b/examples/flutter_screen_capture_example/analysis_options.yaml
new file mode 100644
index 00000000..362ff73a
--- /dev/null
+++ b/examples/flutter_screen_capture_example/analysis_options.yaml
@@ -0,0 +1,34 @@
+# This file configures the analyzer, which statically analyzes Dart code to
+# check for errors, warnings, and lints.
+#
+# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
+# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
+# invoked from the command line by running `flutter analyze`.
+
+# The following line activates a set of recommended lints for Flutter apps,
+# packages, and plugins designed to encourage good coding practices.
+include: package:flutter_lints/flutter.yaml
+
+analyzer:
+ exclude:
+ - build/**
+ - windows/**
+ - macos/**
+
+linter:
+ # The lint rules applied to this project can be customized in the
+ # section below to disable rules from the `package:flutter_lints/flutter.yaml`
+ # included above or to enable additional rules. A list of all available lints
+ # and their documentation is published at https://dart.dev/lints.
+ #
+ # Instead of disabling a lint rule for the entire project in the
+ # section below, it can also be suppressed for a single line of code
+ # or a specific dart file by using the `// ignore: name_of_lint` and
+ # `// ignore_for_file: name_of_lint` syntax on the line or in the file
+ # producing the lint.
+ rules:
+ # avoid_print: false # Uncomment to disable the `avoid_print` rule
+ # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
+
+# Additional information about this file can be found at
+# https://dart.dev/guides/language/analysis-options
diff --git a/examples/flutter_screen_capture_example/lib/capture_controller.dart b/examples/flutter_screen_capture_example/lib/capture_controller.dart
new file mode 100644
index 00000000..f5fe922a
--- /dev/null
+++ b/examples/flutter_screen_capture_example/lib/capture_controller.dart
@@ -0,0 +1,406 @@
+import 'dart:async';
+import 'dart:convert';
+import 'dart:io';
+
+import 'package:file_selector/file_selector.dart';
+import 'package:flutter/foundation.dart';
+import 'package:nativeapi/nativeapi.dart' as na;
+
+class CaptureArtifact {
+ const CaptureArtifact(this.path, {this.duration, this.width, this.height});
+ final String path;
+ final double? duration;
+ final int? width;
+ final int? height;
+ bool get isVideo => duration != null;
+ String get name => path.split(Platform.pathSeparator).last;
+}
+
+/// Owns native handles explicitly. UI changes never alter an in-flight request.
+class CaptureController extends ChangeNotifier {
+ final artifacts = [];
+ final log = [];
+ List displays = [];
+ na.Window? _window;
+ na.CaptureSource? _source;
+ na.Image? _image;
+ na.ScreenRecorder? _recorder;
+ int? _recordingListener, _closeListener, _quitListener;
+ Timer? _timer;
+ final _elapsed = Stopwatch();
+ bool _disposed = false;
+ bool ready = false;
+ bool busy = false;
+ bool captureSupported = false;
+ bool recordingSupported = false;
+ bool pickerSupported = false;
+ String sourceLabel = 'No source selected';
+ String outputDirectory = '';
+ String status = 'Choose a display, this window, or the system picker.';
+ String? error;
+ Uint8List? preview;
+ int imageWidth = 0, imageHeight = 0;
+ na.ScreenRecordingState recordingState = na.ScreenRecordingState.idle;
+
+ bool get hasSource => _source != null;
+ bool get hasImage => _image != null;
+ bool get active => switch (recordingState) {
+ na.ScreenRecordingState.starting ||
+ na.ScreenRecordingState.recording ||
+ na.ScreenRecordingState.stopping => true,
+ _ => false,
+ };
+ bool get locked => busy || active || !ready;
+ double get elapsed => _elapsed.elapsedMilliseconds / 1000;
+
+ void _changed() {
+ if (!_disposed) notifyListeners();
+ }
+
+ void _message(String message, {bool failure = false}) {
+ status = message;
+ error = failure ? message : null;
+ log.insert(0, message);
+ if (log.length > 30) log.removeLast();
+ debugPrint('[capture] $message');
+ _changed();
+ }
+
+ Future initialize() async {
+ try {
+ final directory = await Directory.systemTemp.createTemp(
+ 'nativeapi-capture-',
+ );
+ if (_disposed) return;
+ outputDirectory = directory.path;
+ _window = na.WindowManager.instance.getCurrent();
+ _window?.contentSize = const na.Size(width: 1120, height: 800);
+ captureSupported = na.ScreenCapturer.isSupported();
+ recordingSupported = na.ScreenRecorder.isSupported();
+ pickerSupported = na.ScreenCapturer.isSourceSelectionSupported();
+ displays = na.DisplayManager.instance.getAll();
+ _closeListener = _window?.addListener((event) {
+ if (event is na.WindowCloseRequestedEvent && (busy || active)) {
+ event.request.cancel();
+ _message(
+ 'Finish the current action, or stop / discard the recording before closing.',
+ );
+ }
+ });
+ _quitListener = na.Application.instance.addListener((event) {
+ if (event is na.ApplicationQuitRequestedEvent && (busy || active)) {
+ event.request.cancel();
+ _message('Stop and save, or discard the recording before quitting.');
+ }
+ });
+ ready = true;
+ _changed();
+ } catch (e) {
+ _message('Initialization failed: $e', failure: true);
+ }
+ }
+
+ void _replaceSource(na.CaptureSource? next) {
+ if (next == null) {
+ _message(
+ 'This source is unavailable. Select it again or try the system picker.',
+ failure: true,
+ );
+ return;
+ }
+ _source?.dispose();
+ _source = next;
+ final name = next.name;
+ sourceLabel = name == null || name.isEmpty
+ ? 'Selected ${next.type.name} source'
+ : name;
+ _message('Source selected: $sourceLabel');
+ }
+
+ void selectDisplay(na.Display display) {
+ if (locked) return;
+ _replaceSource(na.CaptureSource.fromDisplay(display));
+ }
+
+ void selectThisWindow() {
+ if (locked) return;
+ _replaceSource(na.CaptureSource.fromWindow(_window));
+ }
+
+ void releaseSource() {
+ if (locked) return;
+ _source?.dispose();
+ _source = null;
+ sourceLabel = 'No source selected';
+ _message('Source released. Any retained sharing session can now close.');
+ }
+
+ Future selectSource() async {
+ if (locked || !pickerSupported) return;
+ busy = true;
+ _message('Choose one screen or window in the system picker.');
+ try {
+ final result = Completer<(bool, na.CaptureSource?)>();
+ na.ScreenCapturer.selectSource(
+ na.CaptureSourceSelectionOptions(
+ allowDisplays: true,
+ allowWindows: true,
+ parentWindow: _window,
+ ),
+ (success, source) => result.complete((success, source)),
+ );
+ final (success, source) = await result.future;
+ if (_disposed) {
+ source?.dispose();
+ return;
+ }
+ if (!success) {
+ source?.dispose();
+ _message(
+ 'Source selection failed. Check system permission and try again.',
+ failure: true,
+ );
+ } else if (source == null) {
+ _message('Selection cancelled. The previous source is unchanged.');
+ } else {
+ _replaceSource(source);
+ }
+ } catch (e) {
+ _message('Source selection failed: $e', failure: true);
+ } finally {
+ busy = false;
+ _changed();
+ }
+ }
+
+ Future capture(na.ScreenCaptureOptions options) async {
+ if (locked || _source == null) return;
+ busy = true;
+ _message('Capturing a new frame…');
+ try {
+ final result = Completer<(bool, na.Image?)>();
+ na.ScreenCapturer.capture(
+ _source,
+ options,
+ (success, image) => result.complete((success, image)),
+ );
+ final (success, image) = await result.future;
+ if (_disposed) {
+ image?.dispose();
+ return;
+ }
+ if (!success || image == null) {
+ image?.dispose();
+ throw StateError(
+ 'No frame received. Check screen-recording permission, source availability and crop bounds.',
+ );
+ }
+ try {
+ final encoded = image.toBase64();
+ if (encoded == null) {
+ throw StateError('Cannot convert the captured image for preview.');
+ }
+ // Image.ToBase64 returns a data URI, including its MIME type.
+ final bytes = encoded.startsWith('data:')
+ ? UriData.parse(encoded).contentAsBytes()
+ : base64Decode(encoded);
+ imageWidth = image.size.width.toInt();
+ imageHeight = image.size.height.toInt();
+ _image?.dispose();
+ _image = image;
+ preview = bytes;
+ } catch (_) {
+ image.dispose();
+ rethrow;
+ }
+ _message('Screenshot ready · $imageWidth × $imageHeight px');
+ } catch (e) {
+ _message('Screenshot failed: $e', failure: true);
+ } finally {
+ busy = false;
+ _changed();
+ }
+ }
+
+ Future