aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/apprt/gtk/winproto.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/winproto.zig
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/apprt/gtk/winproto.zig')
-rw-r--r--vendor/libghostty-vt/src/apprt/gtk/winproto.zig155
1 files changed, 155 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/apprt/gtk/winproto.zig b/vendor/libghostty-vt/src/apprt/gtk/winproto.zig
new file mode 100644
index 00000000..d409d6c2
--- /dev/null
+++ b/vendor/libghostty-vt/src/apprt/gtk/winproto.zig
@@ -0,0 +1,155 @@
+const std = @import("std");
+const build_options = @import("build_options");
+const Allocator = std.mem.Allocator;
+
+const gdk = @import("gdk");
+
+const Config = @import("../../config.zig").Config;
+const input = @import("../../input.zig");
+const key = @import("key.zig");
+const ApprtWindow = @import("class/window.zig").Window;
+
+pub const noop = @import("winproto/noop.zig");
+pub const x11 = @import("winproto/x11.zig");
+pub const wayland = @import("winproto/wayland.zig");
+
+pub const Protocol = enum {
+ none,
+ wayland,
+ x11,
+};
+
+/// App-state for the underlying windowing protocol. There should be one
+/// instance of this struct per application.
+pub const App = union(Protocol) {
+ none: noop.App,
+ wayland: if (build_options.wayland) wayland.App else noop.App,
+ x11: if (build_options.x11) x11.App else noop.App,
+
+ pub fn init(
+ alloc: Allocator,
+ gdk_display: *gdk.Display,
+ app_id: [:0]const u8,
+ config: *const Config,
+ ) !App {
+ inline for (@typeInfo(App).@"union".fields) |field| {
+ if (try field.type.init(
+ alloc,
+ gdk_display,
+ app_id,
+ config,
+ )) |v| {
+ return @unionInit(App, field.name, v);
+ }
+ }
+
+ return .{ .none = .{} };
+ }
+
+ pub fn deinit(self: *App) void {
+ switch (self.*) {
+ inline else => |*v| v.deinit(),
+ }
+ }
+
+ pub fn eventMods(
+ self: *App,
+ device: ?*gdk.Device,
+ gtk_mods: gdk.ModifierType,
+ ) input.Mods {
+ return switch (self.*) {
+ inline else => |*v| v.eventMods(device, gtk_mods),
+ } orelse key.translateMods(gtk_mods);
+ }
+
+ pub fn supportsQuickTerminal(self: App) bool {
+ return switch (self) {
+ inline else => |v| v.supportsQuickTerminal(),
+ };
+ }
+
+ /// Set up necessary support for the quick terminal that must occur
+ /// *before* the window-level winproto object is created.
+ ///
+ /// Only has an effect on the Wayland backend, where the gtk4-layer-shell
+ /// library is initialized.
+ pub fn initQuickTerminal(self: *App, apprt_window: *ApprtWindow) !void {
+ switch (self.*) {
+ inline else => |*v| try v.initQuickTerminal(apprt_window),
+ }
+ }
+};
+
+/// Per-Window state for the underlying windowing protocol.
+///
+/// In Wayland, the terminology used is "Surface" and for it, this is
+/// really "Surface"-specific state. But Ghostty uses the term "Surface"
+/// heavily to mean something completely different, so we use "Window" here
+/// to better match what it generally maps to in the Ghostty codebase.
+pub const Window = union(Protocol) {
+ none: noop.Window,
+ wayland: if (build_options.wayland) wayland.Window else noop.Window,
+ x11: if (build_options.x11) x11.Window else noop.Window,
+
+ pub fn init(
+ alloc: Allocator,
+ app: *App,
+ apprt_window: *ApprtWindow,
+ ) !Window {
+ return switch (app.*) {
+ inline else => |*v, tag| {
+ inline for (@typeInfo(Window).@"union".fields) |field| {
+ if (comptime std.mem.eql(
+ u8,
+ field.name,
+ @tagName(tag),
+ )) return @unionInit(
+ Window,
+ field.name,
+ try field.type.init(
+ alloc,
+ v,
+ apprt_window,
+ ),
+ );
+ }
+ },
+ };
+ }
+
+ pub fn deinit(self: *Window) void {
+ switch (self.*) {
+ inline else => |*v| v.deinit(),
+ }
+ }
+
+ pub fn resizeEvent(self: *Window) !void {
+ switch (self.*) {
+ inline else => |*v| try v.resizeEvent(),
+ }
+ }
+
+ pub fn syncAppearance(self: *Window) !void {
+ switch (self.*) {
+ inline else => |*v| try v.syncAppearance(),
+ }
+ }
+
+ pub fn clientSideDecorationEnabled(self: Window) bool {
+ return switch (self) {
+ inline else => |v| v.clientSideDecorationEnabled(),
+ };
+ }
+
+ pub fn addSubprocessEnv(self: *Window, env: *std.process.EnvMap) !void {
+ switch (self.*) {
+ inline else => |*v| try v.addSubprocessEnv(env),
+ }
+ }
+
+ pub fn setUrgent(self: *Window, urgent: bool) !void {
+ switch (self.*) {
+ inline else => |*v| try v.setUrgent(urgent),
+ }
+ }
+};