apprt/embedded: add iOS platform with uivew

This commit is contained in:
Mitchell Hashimoto
2024-01-18 15:03:03 -08:00
parent 5fe3900efa
commit 26e6e8cec8
3 changed files with 25 additions and 0 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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),
},