aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/pkg/macos/video/display_link.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-04-04 19:22:04 +0300
committerCan Celik <ogulcancelik@gmail.com>2026-04-05 01:23:06 +0300
commit41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch)
tree3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/pkg/macos/video/display_link.zig
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/pkg/macos/video/display_link.zig')
-rw-r--r--vendor/libghostty-vt/pkg/macos/video/display_link.zig86
1 files changed, 86 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/pkg/macos/video/display_link.zig b/vendor/libghostty-vt/pkg/macos/video/display_link.zig
new file mode 100644
index 00000000..7d6b437f
--- /dev/null
+++ b/vendor/libghostty-vt/pkg/macos/video/display_link.zig
@@ -0,0 +1,86 @@
+const std = @import("std");
+const assert = std.debug.assert;
+const Allocator = std.mem.Allocator;
+const c = @import("c.zig").c;
+
+pub const DisplayLink = opaque {
+ pub const Error = error{
+ InvalidOperation,
+ };
+
+ pub fn createWithActiveCGDisplays() Allocator.Error!*DisplayLink {
+ var result: ?*DisplayLink = null;
+ if (c.CVDisplayLinkCreateWithActiveCGDisplays(
+ @ptrCast(&result),
+ ) != c.kCVReturnSuccess)
+ return error.OutOfMemory;
+
+ return result orelse error.OutOfMemory;
+ }
+
+ pub fn release(self: *DisplayLink) void {
+ c.CVDisplayLinkRelease(@ptrCast(self));
+ }
+
+ pub fn start(self: *DisplayLink) Error!void {
+ if (c.CVDisplayLinkStart(@ptrCast(self)) != c.kCVReturnSuccess)
+ return error.InvalidOperation;
+ }
+
+ pub fn stop(self: *DisplayLink) Error!void {
+ if (c.CVDisplayLinkStop(@ptrCast(self)) != c.kCVReturnSuccess)
+ return error.InvalidOperation;
+ }
+
+ pub fn isRunning(self: *DisplayLink) bool {
+ return c.CVDisplayLinkIsRunning(@ptrCast(self)) != 0;
+ }
+
+ pub fn setCurrentCGDisplay(
+ self: *DisplayLink,
+ display_id: c.CGDirectDisplayID,
+ ) Error!void {
+ if (c.CVDisplayLinkSetCurrentCGDisplay(
+ @ptrCast(self),
+ display_id,
+ ) != c.kCVReturnSuccess)
+ return error.InvalidOperation;
+ }
+
+ // Note: this purposely throws away a ton of arguments I didn't need.
+ // It would be trivial to refactor this into Zig types and properly
+ // pass this through.
+ pub fn setOutputCallback(
+ self: *DisplayLink,
+ comptime Userdata: type,
+ comptime callbackFn: *const fn (*DisplayLink, ?*Userdata) void,
+ userinfo: ?*Userdata,
+ ) Error!void {
+ if (c.CVDisplayLinkSetOutputCallback(
+ @ptrCast(self),
+ @ptrCast(&(struct {
+ fn callback(
+ displayLink: *DisplayLink,
+ inNow: *const c.CVTimeStamp,
+ inOutputTime: *const c.CVTimeStamp,
+ flagsIn: c.CVOptionFlags,
+ flagsOut: *c.CVOptionFlags,
+ inner_userinfo: ?*anyopaque,
+ ) callconv(.c) c.CVReturn {
+ _ = inNow;
+ _ = inOutputTime;
+ _ = flagsIn;
+ _ = flagsOut;
+
+ callbackFn(
+ displayLink,
+ @ptrCast(@alignCast(inner_userinfo)),
+ );
+ return c.kCVReturnSuccess;
+ }
+ }).callback),
+ userinfo,
+ ) != c.kCVReturnSuccess)
+ return error.InvalidOperation;
+ }
+};