From 26e6e8cec87ff57acd3a02e6f55ffa5c125f60d4 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 18 Jan 2024 15:03:03 -0800 Subject: [PATCH] apprt/embedded: add iOS platform with uivew --- include/ghostty.h | 6 ++++++ src/apprt/embedded.zig | 18 ++++++++++++++++++ src/renderer/Metal.zig | 1 + 3 files changed, 25 insertions(+) diff --git a/include/ghostty.h b/include/ghostty.h index 9035d9c0a..a6283170d 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -33,6 +33,7 @@ typedef void *ghostty_inspector_t; typedef enum { GHOSTTY_PLATFORM_INVALID, GHOSTTY_PLATFORM_MACOS, + GHOSTTY_PLATFORM_IOS, } ghostty_platform_e; typedef enum { @@ -358,8 +359,13 @@ typedef struct { void *nsview; } ghostty_platform_macos_s; +typedef struct { + void *uiview; +} ghostty_platform_ios_s; + typedef union { ghostty_platform_macos_s macos; + ghostty_platform_ios_s ios; } ghostty_platform_u; typedef struct { diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index a622fccc4..6b631de17 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -234,6 +234,7 @@ pub const App = struct { /// Platform-specific configuration for libghostty. pub const Platform = union(PlatformTag) { macos: MacOS, + ios: IOS, // If our build target for libghostty is not darwin then we do // not include macos support at all. @@ -242,12 +243,21 @@ pub const Platform = union(PlatformTag) { nsview: objc.Object, } else void; + pub const IOS = if (builtin.target.isDarwin()) struct { + /// The view to render the surface on. + uiview: objc.Object, + } else void; + // The C ABI compatible version of this union. The tag is expected // to be stored elsewhere. pub const C = extern union { macos: extern struct { nsview: ?*anyopaque, }, + + ios: extern struct { + uiview: ?*anyopaque, + }, }; /// Initialize a Platform a tag and configuration from the C ABI. @@ -260,6 +270,13 @@ pub const Platform = union(PlatformTag) { break :macos error.NSViewMustBeSet); break :macos .{ .macos = .{ .nsview = nsview } }; } else error.UnsupportedPlatform, + + .ios => if (IOS != void) ios: { + const config = c_platform.ios; + const uiview = objc.Object.fromId(config.uiview orelse + break :ios error.UIViewMustBeSet); + break :ios .{ .ios = .{ .uiview = uiview } }; + } else error.UnsupportedPlatform, }; } }; @@ -269,6 +286,7 @@ pub const PlatformTag = enum(c_int) { // from the C API. macos = 1, + ios = 2, }; pub const Surface = struct { diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 7a689f6be..5232d0e04 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -468,6 +468,7 @@ pub fn finalizeSurfaceInit(self: *const Metal, surface: *apprt.Surface) !void { apprt.embedded => .{ .view = switch (surface.platform) { .macos => |v| v.nsview, + .ios => |v| v.uiview, }, .scaleFactor = @floatCast(surface.content_scale.x), },