cli/gtk: move IPC/sendIPC to App/performIpc

This commit is contained in:
Jeffrey C. Ollie
2025-07-14 14:45:46 -05:00
parent f5eb413c31
commit dd3853abeb
8 changed files with 40 additions and 50 deletions

View File

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

View File

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

View File

@ -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());

View File

@ -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 => {},

View File

@ -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;
}

1
src/apprt/gtk/ipc.zig Normal file
View File

@ -0,0 +1 @@
pub const openNewWindow = @import("ipc/new_window.zig").openNewWindow;

View File

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

View File

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