aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/apprt/gtk/ipc/new_window.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-04-04 19:22:04 +0300
committerCan Celik <ogulcancelik@gmail.com>2026-04-05 01:23:06 +0300
commit41dd733ca7123c9ac4bfc6c781697a660e95b052 (patch)
tree3fc91815ca139ef2e0b281bba0abda4ef15175f4 /vendor/libghostty-vt/src/apprt/gtk/ipc/new_window.zig
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/apprt/gtk/ipc/new_window.zig')
-rw-r--r--vendor/libghostty-vt/src/apprt/gtk/ipc/new_window.zig62
1 files changed, 62 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/apprt/gtk/ipc/new_window.zig b/vendor/libghostty-vt/src/apprt/gtk/ipc/new_window.zig
new file mode 100644
index 00000000..02fed322
--- /dev/null
+++ b/vendor/libghostty-vt/src/apprt/gtk/ipc/new_window.zig
@@ -0,0 +1,62 @@
+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 window on GTK.
+// See: https://wiki.gnome.org/Projects/GLib/GApplication/DBusAPI
+//
+// `ghostty +new-window` 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-window [] []
+// ```
+//
+// `ghostty +new-window -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-window-command '[<@as ["-e" "echo" "hello"]>]' []
+// ```
+pub fn newWindow(alloc: Allocator, target: apprt.ipc.Target, value: apprt.ipc.Action.NewWindow) (Allocator.Error || std.Io.Writer.Error || apprt.ipc.Errors)!bool {
+ var dbus = try DBus.init(
+ alloc,
+ target,
+ if (value.arguments == null)
+ "new-window"
+ else
+ "new-window-command",
+ );
+ defer dbus.deinit(alloc);
+
+ if (value.arguments) |arguments| {
+ // If any arguments were specified on the command line, the first
+ // parameter 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();
+
+ 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);
+ }
+
+ dbus.addParameter(command.end());
+ }
+
+ try dbus.send();
+
+ return true;
+}