mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
apprt/embedded: add iOS platform with uivew
This commit is contained in:
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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),
|
||||
},
|
||||
|
Reference in New Issue
Block a user