feat(lib): port libghostty, Ghostty's embedded C API
Ports apprt/embedded.zig, main_c.zig and config/CApi.zig + c_get.zig as crates/ghostty-lib (cdylib/staticlib/rlib `libghostty`), exporting every function of the unchanged include/ghostty.h - the ABI Ghostty's Swift macOS/iOS app links against. The embedded runtime implements the runtime traits over the host's C callbacks, so the real core drives it. - ghostty-core selects the renderer per target: Metal on Apple (surface NSView/UIView via RtSurface::platform_view), OpenGL elsewhere. - ghostty_config_get follows Zig's c_get rules via a CValue type (143 supported keys, checked against the Zig field types). - The inspector C API is complete; its Metal backend replaces ImGui's Metal renderer and has not run. Verification: generated C ABI probe (sizeof/alignof/offsetof of every struct/union, 755 enum values, every function linked, nm exports, headers byte-identical to upstream); a C host on Linux covering init, CLI actions, config, app, keys, focus and color scheme; an opt-in test-platform feature creating real surfaces on Linux with headless EGL and a pty (13 tests). Apple targets are clippy-clean but not run; the Swift app has not been built against it. Test Plan: - cargo test -p ghostty-lib (and --features test-platform) - cargo clippy --target aarch64-apple-darwin -p ghostty-lib (cross env in docs/rewrite/notes/macos-M1.md)
This commit is contained in:
1 parent
4787565397
commit
49d4ecefae
47 files changed
+10296
-34
No files matched your search
@@ -1520,6 +1520,12 @@ impl<G: GraphicsApi> Renderer<G> {
|
||||
.is_some_and(DisplayLink::is_running)
|
||||
}
|
||||
|
||||
/// The font grid currently used for rendering (for apprts that need
|
||||
/// to read the primary face, e.g. macOS quicklook).
|
||||
pub fn font_grid(&self) -> Arc<SharedGrid> {
|
||||
Arc::clone(&lock(&self.draw).font_grid)
|
||||
}
|
||||
|
||||
/// Called by the renderer thread when it begins (`threadEnter`).
|
||||
pub fn thread_enter(&self) {
|
||||
lock(&self.draw).api.thread_enter();
|
||||
|
||||
@@ -239,6 +239,23 @@ impl Metal {
|
||||
})
|
||||
}
|
||||
|
||||
/// [`Metal::init`] for a raw `NSView` / `UIView` pointer as handed over
|
||||
/// through the C API (`ghostty_platform_macos_s.nsview`). The view must
|
||||
/// stay alive for the lifetime of the renderer (the host owns it).
|
||||
pub fn init_with_view(
|
||||
blending: AlphaBlending,
|
||||
view: *mut c_void,
|
||||
scale_factor: f64,
|
||||
) -> Result<Metal, Error> {
|
||||
if view.is_null() {
|
||||
return Err(Error::ObjCFailed);
|
||||
}
|
||||
// SAFETY: the caller (the embedded runtime) guarantees `view` is a
|
||||
// valid, live NSView / UIView, which is an Objective-C object.
|
||||
let view: &AnyObject = unsafe { &*view.cast::<AnyObject>() };
|
||||
Metal::init(blending, &ViewInfo { view, scale_factor })
|
||||
}
|
||||
|
||||
/// The layer the renderer presents on.
|
||||
pub fn layer(&self) -> &IOSurfaceLayer {
|
||||
&self.layer
|
||||
|
||||
Reference in new issue
Block a user