Skip to content

Commit

Permalink
add ScreenCaptureKit
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
  • Loading branch information
slimsag committed Sep 29, 2024
1 parent 773066d commit cff324b
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 33 deletions.
13 changes: 13 additions & 0 deletions generator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,16 @@ fn generateAppKit(generator: anytype) !void {
// try generator.addProtocol("NSPreviewRepresentableActivityItem");
}

fn generateScreenCaptureKit(generator: anytype) !void {
generator.namespace = "SC";
generator.allow_methods = &.{};

try generator.addInterface("SCShareableContent");
try generator.addInterface("SCRunningApplication");
try generator.addInterface("SCDisplay");
try generator.addInterface("SCWindow");
}

fn usage() void {
std.log.warn(
\\mach-objc-generator [options]
Expand All @@ -2184,6 +2194,7 @@ const Framework = enum {
avf_audio,
core_midi,
app_kit,
screen_capture_kit,
};

pub fn main() anyerror!void {
Expand All @@ -2209,6 +2220,7 @@ pub fn main() anyerror!void {
if (std.mem.eql(u8, args[i], "AVFAudio")) break :blk .avf_audio;
if (std.mem.eql(u8, args[i], "CoreMIDI")) break :blk .core_midi;
if (std.mem.eql(u8, args[i], "AppKit")) break :blk .app_kit;
if (std.mem.eql(u8, args[i], "ScreenCaptureKit")) break :blk .screen_capture_kit;
usage();
std.process.exit(1);
};
Expand Down Expand Up @@ -2260,6 +2272,7 @@ pub fn main() anyerror!void {
.avf_audio => try generateAVFAudio(&generator),
.core_midi => try generateCoreMIDI(&generator),
.app_kit => try generateAppKit(&generator),
.screen_capture_kit => try generateScreenCaptureKit(&generator),
}
try generator.generate();
}
Expand Down
55 changes: 55 additions & 0 deletions screen_capture_kit_manual.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// const ca = @import("quartz_core.zig");
// const cf = @import("core_foundation.zig");
const ns = @import("foundation.zig");
const cg = @import("core_graphics.zig");
const objc = @import("objc.zig");

// pub const applicationMain = NSApplicationMain;
// extern fn NSApplicationMain(argc: c_int, argv: [*]*c_char) c_int;

// // ------------------------------------------------------------------------------------------------
// // Shared

// pub const ErrorDomain = ns.ErrorDomain;
// pub const ErrorUserInfoKey = ns.ErrorUserInfoKey;
// pub const Integer = ns.Integer;
// pub const NotificationName = ns.NotificationName;
// pub const TimeInterval = ns.TimeInterval;
// pub const UInteger = ns.UInteger;
// pub const unichar = ns.unichar;
// pub const Range = ns.Range;
// pub const StringEncoding = ns.StringEncoding;
// pub const StringTransform = ns.StringTransform;
// pub const StringEncodingDetectionOptionsKey = ns.StringEncodingDetectionOptionsKey;
// pub const Array = ns.Array;
// pub const String = ns.String;

// // ------------------------------------------------------------------------------------------------
// // Types

// pub const ModalResponse = *String;
// pub const PasteboardType = *String;
// pub const AboutPanelOptionKey = *String;
// pub const ModalSession = *opaque {};
// pub const PrintInfoAttributeKey = *String;
// pub const Rect = cg.Rect;
// pub const Point = cg.Point;
// pub const Size = cg.Size;
// pub const RunLoopMode = *String;
// pub const PrinterPaperName = *String;
// pub const PrintJobDispositionValue = *String;
// pub const InterfaceStyle = UInteger;
// pub const TouchBarItemIdentifier = *String;
// pub const TouchBarCustomizationIdentifier = *String;
// pub const TouchBarItemPriority = f32;
// pub const DeviceDescriptionKey = *String;
// pub const PrinterTypeName = *String;
// pub const PrintInfoSettingKey = *String;
// pub const AccessibilityActionName = *String;
// pub const AccessibilityAttributeName = *String;
// pub const ExceptionName = *String;
// pub const ImageName = *String;
// pub const NibName = *String;
// pub const WindowFrameAutosaveName = *String;
// pub const AccessibilityParameterizedAttributeName = *String;
// pub const UserInterfaceItemIdentifier = *String;
169 changes: 169 additions & 0 deletions src/screen_capture_kit.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
// const ca = @import("quartz_core.zig");
// const cf = @import("core_foundation.zig");
const ns = @import("foundation.zig");
const cg = @import("core_graphics.zig");
const objc = @import("objc.zig");

// pub const applicationMain = NSApplicationMain;
// extern fn NSApplicationMain(argc: c_int, argv: [*]*c_char) c_int;

// // ------------------------------------------------------------------------------------------------
// // Shared

// pub const ErrorDomain = ns.ErrorDomain;
// pub const ErrorUserInfoKey = ns.ErrorUserInfoKey;
// pub const Integer = ns.Integer;
// pub const NotificationName = ns.NotificationName;
// pub const TimeInterval = ns.TimeInterval;
// pub const UInteger = ns.UInteger;
// pub const unichar = ns.unichar;
// pub const Range = ns.Range;
// pub const StringEncoding = ns.StringEncoding;
// pub const StringTransform = ns.StringTransform;
// pub const StringEncodingDetectionOptionsKey = ns.StringEncodingDetectionOptionsKey;
// pub const Array = ns.Array;
// pub const String = ns.String;

// // ------------------------------------------------------------------------------------------------
// // Types

// pub const ModalResponse = *String;
// pub const PasteboardType = *String;
// pub const AboutPanelOptionKey = *String;
// pub const ModalSession = *opaque {};
// pub const PrintInfoAttributeKey = *String;
// pub const Rect = cg.Rect;
// pub const Point = cg.Point;
// pub const Size = cg.Size;
// pub const RunLoopMode = *String;
// pub const PrinterPaperName = *String;
// pub const PrintJobDispositionValue = *String;
// pub const InterfaceStyle = UInteger;
// pub const TouchBarItemIdentifier = *String;
// pub const TouchBarCustomizationIdentifier = *String;
// pub const TouchBarItemPriority = f32;
// pub const DeviceDescriptionKey = *String;
// pub const PrinterTypeName = *String;
// pub const PrintInfoSettingKey = *String;
// pub const AccessibilityActionName = *String;
// pub const AccessibilityAttributeName = *String;
// pub const ExceptionName = *String;
// pub const ImageName = *String;
// pub const NibName = *String;
// pub const WindowFrameAutosaveName = *String;
// pub const AccessibilityParameterizedAttributeName = *String;
// pub const UserInterfaceItemIdentifier = *String;

pub const SCShareableContent = opaque {
pub const InternalInfo = objc.ExternClass("SCShareableContent", @This(), ns.ObjectInterface, &.{});
pub const as = InternalInfo.as;
pub const retain = InternalInfo.retain;
pub const release = InternalInfo.release;
pub const autorelease = InternalInfo.autorelease;
pub const new = InternalInfo.new;
pub const alloc = InternalInfo.alloc;
pub const allocInit = InternalInfo.allocInit;

pub fn getShareableContentWithCompletionHandler(completionHandler_: *ns.Block(fn (?*SCShareableContent, ?*ns.Error) void)) void {
return objc.msgSend(@This().InternalInfo.class(), "getShareableContentWithCompletionHandler:", void, .{completionHandler_});
}
pub fn getShareableContentExcludingDesktopWindows_onScreenWindowsOnly_completionHandler(excludeDesktopWindows_: bool, onScreenWindowsOnly_: bool, completionHandler_: *ns.Block(fn (?*SCShareableContent, ?*ns.Error) void)) void {
return objc.msgSend(@This().InternalInfo.class(), "getShareableContentExcludingDesktopWindows:onScreenWindowsOnly:completionHandler:", void, .{ excludeDesktopWindows_, onScreenWindowsOnly_, completionHandler_ });
}
pub fn getShareableContentExcludingDesktopWindows_onScreenWindowsOnlyBelowWindow_completionHandler(excludeDesktopWindows_: bool, window_: *SCWindow, completionHandler_: *ns.Block(fn (?*SCShareableContent, ?*ns.Error) void)) void {
return objc.msgSend(@This().InternalInfo.class(), "getShareableContentExcludingDesktopWindows:onScreenWindowsOnlyBelowWindow:completionHandler:", void, .{ excludeDesktopWindows_, window_, completionHandler_ });
}
pub fn getShareableContentExcludingDesktopWindows_onScreenWindowsOnlyAboveWindow_completionHandler(excludeDesktopWindows_: bool, window_: *SCWindow, completionHandler_: *ns.Block(fn (?*SCShareableContent, ?*ns.Error) void)) void {
return objc.msgSend(@This().InternalInfo.class(), "getShareableContentExcludingDesktopWindows:onScreenWindowsOnlyAboveWindow:completionHandler:", void, .{ excludeDesktopWindows_, window_, completionHandler_ });
}
pub fn infoForFilter(filter_: *SCContentFilter) *SCShareableContentInfo {
return objc.msgSend(@This().InternalInfo.class(), "infoForFilter:", *SCShareableContentInfo, .{filter_});
}
pub fn windows(self_: *@This()) *ns.Array(*SCWindow) {
return objc.msgSend(self_, "windows", *ns.Array(*SCWindow), .{});
}
pub fn displays(self_: *@This()) *ns.Array(*SCDisplay) {
return objc.msgSend(self_, "displays", *ns.Array(*SCDisplay), .{});
}
pub fn applications(self_: *@This()) *ns.Array(*SCRunningApplication) {
return objc.msgSend(self_, "applications", *ns.Array(*SCRunningApplication), .{});
}
};

pub const SCRunningApplication = opaque {
pub const InternalInfo = objc.ExternClass("SCRunningApplication", @This(), ns.ObjectInterface, &.{});
pub const as = InternalInfo.as;
pub const retain = InternalInfo.retain;
pub const release = InternalInfo.release;
pub const autorelease = InternalInfo.autorelease;
pub const new = InternalInfo.new;
pub const alloc = InternalInfo.alloc;
pub const allocInit = InternalInfo.allocInit;

pub fn bundleIdentifier(self_: *@This()) *ns.String {
return objc.msgSend(self_, "bundleIdentifier", *ns.String, .{});
}
pub fn applicationName(self_: *@This()) *ns.String {
return objc.msgSend(self_, "applicationName", *ns.String, .{});
}
pub fn processID(self_: *@This()) pid_t {
return objc.msgSend(self_, "processID", pid_t, .{});
}
};

pub const SCDisplay = opaque {
pub const InternalInfo = objc.ExternClass("SCDisplay", @This(), ns.ObjectInterface, &.{});
pub const as = InternalInfo.as;
pub const retain = InternalInfo.retain;
pub const release = InternalInfo.release;
pub const autorelease = InternalInfo.autorelease;
pub const new = InternalInfo.new;
pub const alloc = InternalInfo.alloc;
pub const allocInit = InternalInfo.allocInit;

pub fn displayID(self_: *@This()) cg.DirectDisplayID {
return objc.msgSend(self_, "displayID", cg.DirectDisplayID, .{});
}
pub fn width(self_: *@This()) ns.Integer {
return objc.msgSend(self_, "width", ns.Integer, .{});
}
pub fn height(self_: *@This()) ns.Integer {
return objc.msgSend(self_, "height", ns.Integer, .{});
}
pub fn frame(self_: *@This()) cg.Rect {
return objc.msgSend(self_, "frame", cg.Rect, .{});
}
};

pub const SCWindow = opaque {
pub const InternalInfo = objc.ExternClass("SCWindow", @This(), ns.ObjectInterface, &.{});
pub const as = InternalInfo.as;
pub const retain = InternalInfo.retain;
pub const release = InternalInfo.release;
pub const autorelease = InternalInfo.autorelease;
pub const new = InternalInfo.new;
pub const alloc = InternalInfo.alloc;
pub const allocInit = InternalInfo.allocInit;

pub fn windowID(self_: *@This()) cg.WindowID {
return objc.msgSend(self_, "windowID", cg.WindowID, .{});
}
pub fn frame(self_: *@This()) cg.Rect {
return objc.msgSend(self_, "frame", cg.Rect, .{});
}
pub fn title(self_: *@This()) ?*ns.String {
return objc.msgSend(self_, "title", ?*ns.String, .{});
}
pub fn windowLayer(self_: *@This()) ns.Integer {
return objc.msgSend(self_, "windowLayer", ns.Integer, .{});
}
pub fn owningApplication(self_: *@This()) ?*SCRunningApplication {
return objc.msgSend(self_, "owningApplication", ?*SCRunningApplication, .{});
}
pub fn isOnScreen(self_: *@This()) bool {
return objc.msgSend(self_, "isOnScreen", bool, .{});
}
pub fn isActive(self_: *@This()) bool {
return objc.msgSend(self_, "isActive", bool, .{});
}
};
76 changes: 43 additions & 33 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,52 @@ git_clone_rev https://github.com/hexops/xcode-frameworks 3d1d9613c39bfc2ebfa2551

zig build -Doptimize=ReleaseFast

rm -f src/metal.zig
echo "Generating Metal"
# rm -f src/metal.zig
# echo "Generating Metal"
# echo "
# #include <Metal/Metal.h>
# " > headers.m
# clang headers.m -F ./xcode-frameworks/Frameworks -Xclang -ast-dump=json -fsyntax-only -Wno-deprecated-declarations > headers.json
# cat metal_manual.zig > src/metal.zig
# ./zig-out/bin/generator --framework Metal >> src/metal.zig
# rm headers.json headers.m

# rm -f src/avf_audio.zig
# echo "Generating AVFAudio"
# cp avf_audio_headers.m headers.m
# clang headers.m -F ./xcode-frameworks/Frameworks -Xclang -ast-dump=json -fsyntax-only -Wno-deprecated-declarations > headers.json
# cat avf_audio_manual.zig > src/avf_audio.zig
# ./zig-out/bin/generator --framework AVFAudio >> src/avf_audio.zig
# rm headers.json headers.m

# rm -f src/core_midi.zig
# echo "Generating CoreMIDI"
# echo "
# #include <CoreMIDI/MidiServices.h>
# " > headers.m
# clang headers.m -F ./xcode-frameworks/Frameworks -Xclang -ast-dump=json -fsyntax-only -Wno-deprecated-declarations > headers.json
# cat core_midi_manual.zig > src/core_midi.zig
# ./zig-out/bin/generator --framework CoreMIDI >> src/core_midi.zig
# rm headers.json headers.m

# rm -f src/app_kit.zig
# echo "Generating AppKit"
# echo "
# #include <AppKit/AppKit.h>
# " > headers.m
# clang headers.m -F ./xcode-frameworks/Frameworks -Xclang -ast-dump=json -fsyntax-only -Wno-deprecated-declarations -Wno-availability > headers.json
# cat app_kit_manual.zig > src/app_kit.zig
# ./zig-out/bin/generator --framework AppKit >> src/app_kit.zig
# rm headers.json headers.m

rm -f src/screen_capture_kit.zig
echo "Generating ScreenCaptureKit"
echo "
#include <Metal/Metal.h>
" > headers.m
clang headers.m -F ./xcode-frameworks/Frameworks -Xclang -ast-dump=json -fsyntax-only -Wno-deprecated-declarations > headers.json
cat metal_manual.zig > src/metal.zig
./zig-out/bin/generator --framework Metal >> src/metal.zig
rm headers.json headers.m

rm -f src/avf_audio.zig
echo "Generating AVFAudio"
cp avf_audio_headers.m headers.m
clang headers.m -F ./xcode-frameworks/Frameworks -Xclang -ast-dump=json -fsyntax-only -Wno-deprecated-declarations > headers.json
cat avf_audio_manual.zig > src/avf_audio.zig
./zig-out/bin/generator --framework AVFAudio >> src/avf_audio.zig
rm headers.json headers.m

rm -f src/core_midi.zig
echo "Generating CoreMIDI"
echo "
#include <CoreMIDI/MidiServices.h>
" > headers.m
clang headers.m -F ./xcode-frameworks/Frameworks -Xclang -ast-dump=json -fsyntax-only -Wno-deprecated-declarations > headers.json
cat core_midi_manual.zig > src/core_midi.zig
./zig-out/bin/generator --framework CoreMIDI >> src/core_midi.zig
rm headers.json headers.m

rm -f src/app_kit.zig
echo "Generating AppKit"
echo "
#include <AppKit/AppKit.h>
#include <ScreenCaptureKit/ScreenCaptureKit.h>
" > headers.m
clang headers.m -F ./xcode-frameworks/Frameworks -Xclang -ast-dump=json -fsyntax-only -Wno-deprecated-declarations -Wno-availability > headers.json
cat app_kit_manual.zig > src/app_kit.zig
./zig-out/bin/generator --framework AppKit >> src/app_kit.zig
cat screen_capture_kit_manual.zig > src/screen_capture_kit.zig
./zig-out/bin/generator --framework ScreenCaptureKit >> src/screen_capture_kit.zig
rm headers.json headers.m

zig fmt .
Expand Down

0 comments on commit cff324b

Please sign in to comment.