diff options
| -rw-r--r-- | abi/pardes.h | 6 | ||||
| -rw-r--r-- | dev/macos/Sources/AppDelegate.swift | 2 | ||||
| -rw-r--r-- | docs/ghostty-macos-notes.md | 4 | ||||
| -rw-r--r-- | docs/macos.md | 4 | ||||
| -rw-r--r-- | runtime/macos.zig | 10 | ||||
| -rw-r--r-- | test/macos_e2e.swift | 4 |
6 files changed, 15 insertions, 15 deletions
diff --git a/abi/pardes.h b/abi/pardes.h index 65ca5c60..ca65b8f3 100644 --- a/abi/pardes.h +++ b/abi/pardes.h @@ -191,7 +191,7 @@ typedef enum { PARDES_HAPTIC_LOOK = 2, } pardes_haptic_e; -// ---------------------------------------------------------------- runtime +// ---------------------------------------------------------------- callbacks // What the host lends the core. Three callbacks, because everything else the // core wants done it already does itself: it owns the ptys, and it opens URLs @@ -214,7 +214,7 @@ typedef struct { // pardes_paste, which may be synchronous inside this call. Main thread, // inside pardes_tick. void (*read_clipboard)(void *userdata); -} pardes_runtime_s; +} pardes_callbacks_s; // ---------------------------------------------------------------- lifecycle @@ -223,7 +223,7 @@ typedef struct { // core defers each shell's greeting until it has seen one), and the first // forkpty takes its winsize straight off the core — boot at 80x24 and the // shell draws its first prompt to a width the window never had. -int pardes_init(const pardes_runtime_s *runtime, uint16_t cols, uint16_t rows); +int pardes_init(const pardes_callbacks_s *runtime, uint16_t cols, uint16_t rows); void pardes_deinit(void); // Drain pty output into the core and perform the effects it queued. Call after diff --git a/dev/macos/Sources/AppDelegate.swift b/dev/macos/Sources/AppDelegate.swift index 767d3766..4168999f 100644 --- a/dev/macos/Sources/AppDelegate.swift +++ b/dev/macos/Sources/AppDelegate.swift @@ -132,7 +132,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, PardesViewDelegate { // to change the day macos_min_version reaches 14. NSApp.activate(ignoringOtherApps: true) - var runtime = pardes_runtime_s( + var runtime = pardes_callbacks_s( userdata: Unmanaged.passUnretained(self).toOpaque(), wakeup: { ud in // A pty reader thread. Every other function in pardes.h is diff --git a/docs/ghostty-macos-notes.md b/docs/ghostty-macos-notes.md index 830d4b1f..3dc03265 100644 --- a/docs/ghostty-macos-notes.md +++ b/docs/ghostty-macos-notes.md @@ -56,10 +56,10 @@ comptime { The payoff is that adding a feature adds an enum case, not a struct field: hosts that do not implement it return `false` and the ABI never changed. Worth copying the day a fixed callback list starts growing. pardes has three callbacks today -— `wakeup`, `set_clipboard`, `read_clipboard` (`Runtime` in `runtime/macos.zig:153`) +— `wakeup`, `set_clipboard`, `read_clipboard` (`Callbacks` in `runtime/macos.zig:153`) — and does not need it yet. -Two userdata scopes, worth noting: the runtime struct's `userdata` is +Two userdata scopes, worth noting: the callbacks struct's `userdata` is app-scoped, and each surface carries its own. Swift round-trips both with `Unmanaged.passUnretained(self).toOpaque()` — libghostty never retains, so lifetime stays entirely on the Swift side. diff --git a/docs/macos.md b/docs/macos.md index 44b77d67..98cd5312 100644 --- a/docs/macos.md +++ b/docs/macos.md @@ -85,7 +85,7 @@ copies had in common is the argument for the shared file existing: none set the pty master, so a program in one pane could read and write another pane's terminal and closing a master did not reliably hang its shell up. -That is why the runtime struct is three callbacks rather than a second vtable — +That is why the callbacks struct is three callbacks rather than a second vtable — and why two of the three are the clipboard: the pasteboard is AppKit's, in both directions, and is the one piece of IO the Zig side cannot reach for itself. @@ -128,7 +128,7 @@ is made of and what opens a path from argv or the Dock (`Look <path>`). it. `pardes_resize` also carries one cell in *physical* pixels, which only the native PDF placement path reads — pass the backing-store size, not points. -**Runtime callbacks.** `pardes_runtime_s` is a `userdata` and three functions, +**Callbacks.** `pardes_callbacks_s` is a `userdata` and three functions, copied by value during init so the struct need not outlive the call. `wakeup` means "your state moved, please pump me". `set_clipboard` hands over text to put on the pasteboard, borrowed for the duration of the call; it fires inside a tick diff --git a/runtime/macos.zig b/runtime/macos.zig index 408915da..a5869753 100644 --- a/runtime/macos.zig +++ b/runtime/macos.zig @@ -103,7 +103,7 @@ pub const Image = extern struct { paper_bg: u32, }; -pub const Runtime = extern struct { +pub const Callbacks = extern struct { userdata: ?*anyopaque = null, wakeup: ?*const fn (?*anyopaque) callconv(.c) void = null, set_clipboard: ?*const fn (?*anyopaque, [*]const u8, usize) callconv(.c) void = null, @@ -250,7 +250,7 @@ const State = struct { io: std.Io, core: *pardes.Pardes, started: bool = false, - runtime: Runtime, + runtime: Callbacks, tag_cells: [pardes.MAX_TAG_LAYERS][]Cell = @splat(&.{}), layer_cells: [pardes.MAX_PANES][]Cell = @splat(&.{}), cells: []Cell = &.{}, @@ -290,7 +290,7 @@ const State = struct { var state: ?State = null; -export fn pardes_init(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) c_int { +export fn pardes_init(runtime: ?*const Callbacks, cols_arg: u16, rows_arg: u16) c_int { if (state != null) return 1; // already up; deinit first initCore(runtime, cols_arg, rows_arg) catch |err| { log.err("init failed: {t}", .{err}); @@ -302,7 +302,7 @@ export fn pardes_init(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) c_ /// The shell's gpa in a Debug build, as std.start's is for the others. var debug_gpa: std.heap.DebugAllocator(.{}) = .init; -fn initCore(runtime: ?*const Runtime, cols_arg: u16, rows_arg: u16) !void { +fn initCore(runtime: ?*const Callbacks, cols_arg: u16, rows_arg: u16) !void { // The allocator every other shell gets from std.start: a DebugAllocator // in Debug, libc's malloc otherwise. libc's measured at least as fast as // std.heap.smp_allocator everywhere and faster on MuPDF's page-sized @@ -2461,7 +2461,7 @@ test "pardes.h matches the Zig boundary" { try expectEqual(@sizeOf(c.pardes_image_s), @sizeOf(Image)); inline for (@typeInfo(Image).@"struct".field_names) |name| try expectEqual(@offsetOf(c.pardes_image_s, name), @offsetOf(Image, name)); - try expectEqual(@sizeOf(c.pardes_runtime_s), @sizeOf(Runtime)); + try expectEqual(@sizeOf(c.pardes_callbacks_s), @sizeOf(Callbacks)); try expectEqual(@as(u32, c.PARDES_COLOR_DEFAULT), color_default); try expectEqual(@as(u32, c.PARDES_COLOR_INDEXED), color_indexed); diff --git a/test/macos_e2e.swift b/test/macos_e2e.swift index 74a03200..38d27808 100644 --- a/test/macos_e2e.swift +++ b/test/macos_e2e.swift @@ -51,7 +51,7 @@ private struct ScriptError: Error { } /// What the three C callbacks reach through `userdata`. A class, because a C -/// function pointer cannot capture: a pointer the runtime struct carries is the +/// function pointer cannot capture: a pointer the callbacks struct carries is the /// only way back into Swift state. private final class Host { /// Set by `wakeup`, which runs on a pty reader thread. Nothing else in the @@ -168,7 +168,7 @@ private final class Driver: PardesViewDelegate { message: "the view measured \(got.cols)x\(got.rows) cells, not the \(cols)x\(rows) the script asked for") } - var runtime = pardes_runtime_s( + var runtime = pardes_callbacks_s( userdata: Unmanaged.passUnretained(host).toOpaque(), wakeup: { ud in // A pty reader thread. One flag and out — see Host.woke. |
