diff --git a/src/apprt.zig b/src/apprt.zig index 147086f5f..c422aaeb4 100644 --- a/src/apprt.zig +++ b/src/apprt.zig @@ -51,7 +51,6 @@ pub const runtime = switch (build_config.artifact) { pub const App = runtime.App; pub const Surface = runtime.Surface; -pub const IPC = runtime.IPC; /// Runtime is the runtime to use for Ghostty. All runtimes do not provide /// equivalent feature sets. diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index e8c9db8f4..0b6512599 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -319,6 +319,23 @@ pub const App = struct { else => {}, } } + + /// Send the given IPC to a running Ghostty. Returns `true` if the action was + /// able to be performed, `false` otherwise. + /// + /// Note that this is a static function. Since this is called from a CLI app (or + /// some other process that is not Ghostty) there is no full-featured apprt App + /// to use. + pub fn performIpc( + _: Allocator, + _: apprt.ipc.Target, + comptime action: apprt.ipc.Action.Key, + _: apprt.ipc.Action.Value(action), + ) (Allocator.Error || std.posix.WriteError || apprt.ipc.Errors)!bool { + switch (action) { + .new_window => return false, + } + } }; /// Platform-specific configuration for libghostty. @@ -1153,22 +1170,6 @@ pub const Inspector = struct { } }; -/// Functions for inter-process communication. -pub const IPC = struct { - /// Send the given IPC to a running Ghostty. Returns `true` if the action was - /// able to be performed, `false` otherwise. - pub fn sendIPC( - _: Allocator, - _: apprt.ipc.Target, - comptime action: apprt.ipc.Action.Key, - _: apprt.ipc.Action.Value(action), - ) (Allocator.Error || std.posix.WriteError || apprt.ipc.Errors)!bool { - switch (action) { - .new_window => return false, - } - } -}; - // C API pub const CAPI = struct { const global = &@import("../global.zig").state; diff --git a/src/apprt/gtk.zig b/src/apprt/gtk.zig index 970923d37..3193065c4 100644 --- a/src/apprt/gtk.zig +++ b/src/apprt/gtk.zig @@ -3,7 +3,6 @@ pub const App = @import("gtk/App.zig"); pub const Surface = @import("gtk/Surface.zig"); pub const resourcesDir = @import("gtk/flatpak.zig").resourcesDir; -pub const IPC = @import("gtk/IPC.zig"); test { @import("std").testing.refAllDecls(@This()); diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index ab12d1f33..314998285 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -34,6 +34,7 @@ const terminal = @import("../../terminal/main.zig"); const Config = configpkg.Config; const CoreApp = @import("../../App.zig"); const CoreSurface = @import("../../Surface.zig"); +const ipc = @import("ipc.zig"); const cgroup = @import("cgroup.zig"); const Surface = @import("Surface.zig"); @@ -547,6 +548,23 @@ pub fn performAction( return true; } +/// Send the given IPC to a running Ghostty. Returns `true` if the action was +/// able to be performed, `false` otherwise. +/// +/// Note that this is a static function. Since this is called from a CLI app (or +/// some other process that is not Ghostty) there is no full-featured apprt App +/// to use. +pub fn performIpc( + alloc: Allocator, + target: apprt.ipc.Target, + comptime action: apprt.ipc.Action.Key, + value: apprt.ipc.Action.Value(action), +) (Allocator.Error || std.posix.WriteError || apprt.ipc.Errors)!bool { + switch (action) { + .new_window => return try ipc.openNewWindow(alloc, target, value), + } +} + fn newTab(_: *App, target: apprt.Target) !void { switch (target) { .app => {}, diff --git a/src/apprt/gtk/IPC.zig b/src/apprt/gtk/IPC.zig deleted file mode 100644 index 780ddaf8d..000000000 --- a/src/apprt/gtk/IPC.zig +++ /dev/null @@ -1,26 +0,0 @@ -//! Functions for inter-process communication. -const IPC = @This(); - -const std = @import("std"); -const Allocator = std.mem.Allocator; - -const apprt = @import("../../apprt.zig"); - -pub const openNewWindow = @import("ipc/new_window.zig").openNewWindow; - -/// Send the given IPC to a running Ghostty. Returns `true` if the action was -/// able to be performed, `false` otherwise. -pub fn sendIPC( - alloc: Allocator, - target: apprt.ipc.Target, - comptime action: apprt.ipc.Action.Key, - value: apprt.ipc.Action.Value(action), -) (Allocator.Error || std.posix.WriteError || apprt.ipc.Errors)!bool { - switch (action) { - .new_window => return try openNewWindow(alloc, target, value), - } -} - -test { - _ = openNewWindow; -} diff --git a/src/apprt/gtk/ipc.zig b/src/apprt/gtk/ipc.zig new file mode 100644 index 000000000..7c2dc3887 --- /dev/null +++ b/src/apprt/gtk/ipc.zig @@ -0,0 +1 @@ +pub const openNewWindow = @import("ipc/new_window.zig").openNewWindow; diff --git a/src/apprt/none.zig b/src/apprt/none.zig index 2359197ad..0483d824c 100644 --- a/src/apprt/none.zig +++ b/src/apprt/none.zig @@ -5,12 +5,9 @@ const internal_os = @import("../os/main.zig"); const apprt = @import("../apprt.zig"); pub const resourcesDir = internal_os.resourcesDir; -pub const App = struct {}; -pub const Surface = struct {}; -/// Functions for inter-process communication. -pub const IPC = struct { +pub const App = struct { /// Always return false as there is no apprt to communicate with. - pub fn sendIPC( + pub fn performIpc( _: Allocator, _: apprt.ipc.Target, comptime action: apprt.ipc.Action.Key, @@ -19,3 +16,4 @@ pub const IPC = struct { return false; } }; +pub const Surface = struct {}; diff --git a/src/cli/new_window.zig b/src/cli/new_window.zig index 995c8b2f0..343175b4e 100644 --- a/src/cli/new_window.zig +++ b/src/cli/new_window.zig @@ -147,7 +147,7 @@ fn runArgs(alloc_gpa: Allocator, argsIter: anytype) !u8 { defer arena.deinit(); const alloc = arena.allocator(); - if (apprt.IPC.sendIPC( + if (apprt.App.performIpc( alloc, if (opts.class) |class| .{ .class = class } else .detect, .new_window,