aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/apprt/gtk/ipc/new_tab.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-09-10 21:51:57 +0300
committerGitHub <noreply@github.com>2026-09-10 21:51:57 +0300
commit425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch)
treee52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/src/apprt/gtk/ipc/new_tab.zig
parent90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff)
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/src/apprt/gtk/ipc/new_tab.zig')
-rw-r--r--vendor/libghostty-vt/src/apprt/gtk/ipc/new_tab.zig71
1 files changed, 71 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/apprt/gtk/ipc/new_tab.zig b/vendor/libghostty-vt/src/apprt/gtk/ipc/new_tab.zig
new file mode 100644
index 00000000..c5e53895
--- /dev/null
+++ b/vendor/libghostty-vt/src/apprt/gtk/ipc/new_tab.zig
@@ -0,0 +1,71 @@
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+
+const glib = @import("glib");
+
+const apprt = @import("../../../apprt.zig");
+const DBus = @import("DBus.zig");
+
+// Use a D-Bus method call to open a new tab on GTK.
+// See: https://wiki.gnome.org/Projects/GLib/GApplication/DBusAPI
+//
+// `ghostty +new-tab` is equivalent to the following command (on a release build):
+//
+// ```
+// gdbus call --session --dest com.mitchellh.ghostty --object-path /com/mitchellh/ghostty --method org.gtk.Actions.Activate new-tab '[<@(tas) (0, [])>]' []
+// ```
+//
+// `ghostty +new-tab -e echo hello` would be equivalent to the following command (on a release build):
+//
+// ```
+// gdbus call --session --dest com.mitchellh.ghostty --object-path /com/mitchellh/ghostty --method org.gtk.Actions.Activate new-tab '[<@(tas) (0, ["-e" "echo" "hello"])>]' []
+// ```
+pub fn newTab(alloc: Allocator, target: apprt.ipc.Target, value: apprt.ipc.Action.NewTab) (Allocator.Error || std.Io.Writer.Error || apprt.ipc.Errors)!bool {
+ var dbus = try DBus.init(alloc, target, "new-tab");
+ defer dbus.deinit(alloc);
+
+ const tas_variant_type = glib.VariantType.new("(tas)");
+ defer tas_variant_type.free();
+
+ var parameter: glib.VariantBuilder = undefined;
+ parameter.init(tas_variant_type);
+ errdefer parameter.clear();
+
+ {
+ // Add the target surface ID to the parameter.
+ const t = glib.Variant.newUint64(value.surface_id);
+ parameter.addValue(t);
+ }
+
+ {
+ // If any arguments were specified on the command line, this value is an
+ // array of strings that contain the arguments. They will be sent to the
+ // main Ghostty instance and interpreted as CLI arguments.
+ const as_variant_type = glib.VariantType.new("as");
+ defer as_variant_type.free();
+
+ const s_variant_type = glib.VariantType.new("s");
+ defer s_variant_type.free();
+
+ var command: glib.VariantBuilder = undefined;
+ command.init(as_variant_type);
+ errdefer command.clear();
+
+ if (value.arguments) |arguments| {
+ for (arguments) |argument| {
+ const bytes = glib.Bytes.new(argument.ptr, argument.len + 1);
+ defer bytes.unref();
+ const string = glib.Variant.newFromBytes(s_variant_type, bytes, @intFromBool(true));
+ command.addValue(string);
+ }
+ }
+
+ parameter.addValue(command.end());
+ }
+
+ dbus.addParameter(parameter.end());
+
+ try dbus.send();
+
+ return true;
+}