aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/apprt/gtk/build
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/build
parent55c138263e190a1e79d4b997bfb9397306c0ec1f (diff)
feat: finish ghostty pane backend integration
Diffstat (limited to 'vendor/libghostty-vt/src/apprt/gtk/build')
-rw-r--r--vendor/libghostty-vt/src/apprt/gtk/build/blueprint.zig174
-rw-r--r--vendor/libghostty-vt/src/apprt/gtk/build/gresource.zig277
-rw-r--r--vendor/libghostty-vt/src/apprt/gtk/build/info.zig18
3 files changed, 469 insertions, 0 deletions
diff --git a/vendor/libghostty-vt/src/apprt/gtk/build/blueprint.zig b/vendor/libghostty-vt/src/apprt/gtk/build/blueprint.zig
new file mode 100644
index 00000000..4920ce6f
--- /dev/null
+++ b/vendor/libghostty-vt/src/apprt/gtk/build/blueprint.zig
@@ -0,0 +1,174 @@
+//! Compiles a blueprint file using `blueprint-compiler`. This performs
+//! additional checks to ensure that various minimum versions are met.
+//!
+//! Usage: blueprint.zig <major> <minor> <output> <input>
+//!
+//! Example: blueprint.zig 1 5 output.ui input.blp
+
+const std = @import("std");
+
+pub const c = @cImport({
+ @cInclude("adwaita.h");
+});
+
+pub const blueprint_compiler_help =
+ \\
+ \\When building from a Git checkout, Ghostty requires
+ \\version {f} or newer of `blueprint-compiler` as a
+ \\build-time dependency. Please install it, ensure that it
+ \\is available on your PATH, and then retry building Ghostty.
+ \\See `HACKING.md` for more details.
+ \\
+ \\This message should *not* appear for normal users, who
+ \\should build Ghostty from official release tarballs instead.
+ \\Please consult https://ghostty.org/docs/install/build for
+ \\more information on the recommended build instructions.
+;
+
+const adwaita_version = std.SemanticVersion{
+ .major = c.ADW_MAJOR_VERSION,
+ .minor = c.ADW_MINOR_VERSION,
+ .patch = c.ADW_MICRO_VERSION,
+};
+const required_blueprint_version = std.SemanticVersion{
+ .major = 0,
+ .minor = 16,
+ .patch = 0,
+};
+
+pub fn main() !void {
+ var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
+ defer _ = debug_allocator.deinit();
+ const alloc = debug_allocator.allocator();
+
+ // Get our args
+ var it = try std.process.argsWithAllocator(alloc);
+ defer it.deinit();
+ _ = it.next(); // Skip argv0
+ const arg_major = it.next() orelse return error.NoMajorVersion;
+ const arg_minor = it.next() orelse return error.NoMinorVersion;
+ const output = it.next() orelse return error.NoOutput;
+ const input = it.next() orelse return error.NoInput;
+
+ const required_adwaita_version = std.SemanticVersion{
+ .major = try std.fmt.parseUnsigned(u8, arg_major, 10),
+ .minor = try std.fmt.parseUnsigned(u8, arg_minor, 10),
+ .patch = 0,
+ };
+ if (adwaita_version.order(required_adwaita_version) == .lt) {
+ std.debug.print(
+ \\`libadwaita` is too old.
+ \\
+ \\Ghostty requires a version {f} or newer of `libadwaita` to
+ \\compile this blueprint. Please install it, ensure that it is
+ \\available on your PATH, and then retry building Ghostty.
+ , .{required_adwaita_version});
+ std.posix.exit(1);
+ }
+
+ // Version checks
+ {
+ var stdout: std.ArrayListUnmanaged(u8) = .empty;
+ defer stdout.deinit(alloc);
+ var stderr: std.ArrayListUnmanaged(u8) = .empty;
+ defer stderr.deinit(alloc);
+
+ var blueprint_compiler = std.process.Child.init(
+ &.{
+ "blueprint-compiler",
+ "--version",
+ },
+ alloc,
+ );
+ blueprint_compiler.stdout_behavior = .Pipe;
+ blueprint_compiler.stderr_behavior = .Pipe;
+ try blueprint_compiler.spawn();
+ try blueprint_compiler.collectOutput(
+ alloc,
+ &stdout,
+ &stderr,
+ std.math.maxInt(u16),
+ );
+ const term = blueprint_compiler.wait() catch |err| switch (err) {
+ error.FileNotFound => {
+ std.debug.print(
+ \\`blueprint-compiler` not found.
+ ++ blueprint_compiler_help,
+ .{required_blueprint_version},
+ );
+ std.posix.exit(1);
+ },
+ else => return err,
+ };
+ switch (term) {
+ .Exited => |rc| if (rc != 0) std.process.exit(1),
+ else => std.process.exit(1),
+ }
+
+ const version = try std.SemanticVersion.parse(std.mem.trim(
+ u8,
+ stdout.items,
+ &std.ascii.whitespace,
+ ));
+ if (version.order(required_blueprint_version) == .lt) {
+ std.debug.print(
+ \\`blueprint-compiler` is the wrong version.
+ ++ blueprint_compiler_help,
+ .{required_blueprint_version},
+ );
+ std.posix.exit(1);
+ }
+ }
+
+ // Compilation
+ {
+ var stdout: std.ArrayListUnmanaged(u8) = .empty;
+ defer stdout.deinit(alloc);
+ var stderr: std.ArrayListUnmanaged(u8) = .empty;
+ defer stderr.deinit(alloc);
+
+ var blueprint_compiler = std.process.Child.init(
+ &.{
+ "blueprint-compiler",
+ "compile",
+ "--output",
+ output,
+ input,
+ },
+ alloc,
+ );
+ blueprint_compiler.stdout_behavior = .Pipe;
+ blueprint_compiler.stderr_behavior = .Pipe;
+ try blueprint_compiler.spawn();
+ try blueprint_compiler.collectOutput(
+ alloc,
+ &stdout,
+ &stderr,
+ std.math.maxInt(u16),
+ );
+ const term = blueprint_compiler.wait() catch |err| switch (err) {
+ error.FileNotFound => {
+ std.debug.print(
+ \\`blueprint-compiler` not found.
+ ++ blueprint_compiler_help,
+ .{required_blueprint_version},
+ );
+ std.posix.exit(1);
+ },
+ else => return err,
+ };
+
+ switch (term) {
+ .Exited => |rc| {
+ if (rc != 0) {
+ std.debug.print("{s}", .{stderr.items});
+ std.process.exit(1);
+ }
+ },
+ else => {
+ std.debug.print("{s}", .{stderr.items});
+ std.process.exit(1);
+ },
+ }
+ }
+}
diff --git a/vendor/libghostty-vt/src/apprt/gtk/build/gresource.zig b/vendor/libghostty-vt/src/apprt/gtk/build/gresource.zig
new file mode 100644
index 00000000..c50ea8cd
--- /dev/null
+++ b/vendor/libghostty-vt/src/apprt/gtk/build/gresource.zig
@@ -0,0 +1,277 @@
+//! This file contains a binary helper that builds our gresource XML
+//! file that we can then use with `glib-compile-resources`.
+//!
+//! This binary is expected to be run from the Ghostty source root.
+//! Litmus test: `src/apprt/gtk` should exist relative to the pwd.
+
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+
+const build_info = @import("info.zig");
+
+/// The path to the Blueprint files. The folder structure is expected to be
+/// `{version}/{name}.blp` where `version` is the major and minor
+/// minimum adwaita version.
+pub const ui_path = "src/apprt/gtk/ui";
+
+/// The path to the CSS files.
+pub const css_path = "src/apprt/gtk/css";
+
+/// The possible icon sizes we'll embed into the gresource file.
+/// If any size doesn't exist then it will be an error. We could
+/// infer this completely from available files but we wouldn't be
+/// able to error when they don't exist that way.
+pub const icon_sizes: []const comptime_int = &.{ 16, 32, 128, 256, 512, 1024 };
+
+/// The blueprint files that we will embed into the gresource file.
+/// We can't look these up at runtime [easily] because we require the
+/// compiled UI files as input. We can refactor this lator to maybe do
+/// all of this automatically and ensure we have the right dependencies
+/// setup in the build system.
+///
+/// These will be asserted to exist at runtime.
+pub const blueprints: []const Blueprint = &.{
+ .{ .major = 1, .minor = 0, .name = "clipboard-confirmation-dialog" },
+ .{ .major = 1, .minor = 4, .name = "clipboard-confirmation-dialog" },
+ .{ .major = 1, .minor = 2, .name = "close-confirmation-dialog" },
+ .{ .major = 1, .minor = 2, .name = "config-errors-dialog" },
+ .{ .major = 1, .minor = 2, .name = "debug-warning" },
+ .{ .major = 1, .minor = 3, .name = "debug-warning" },
+ .{ .major = 1, .minor = 5, .name = "imgui-widget" },
+ .{ .major = 1, .minor = 5, .name = "inspector-widget" },
+ .{ .major = 1, .minor = 5, .name = "inspector-window" },
+ .{ .major = 1, .minor = 2, .name = "resize-overlay" },
+ .{ .major = 1, .minor = 2, .name = "search-overlay" },
+ .{ .major = 1, .minor = 2, .name = "key-state-overlay" },
+ .{ .major = 1, .minor = 5, .name = "split-tree" },
+ .{ .major = 1, .minor = 5, .name = "split-tree-split" },
+ .{ .major = 1, .minor = 2, .name = "surface" },
+ .{ .major = 1, .minor = 5, .name = "surface-scrolled-window" },
+ .{ .major = 1, .minor = 3, .name = "surface-child-exited" },
+ .{ .major = 1, .minor = 5, .name = "tab" },
+ .{ .major = 1, .minor = 5, .name = "title-dialog" },
+ .{ .major = 1, .minor = 5, .name = "window" },
+ .{ .major = 1, .minor = 5, .name = "command-palette" },
+};
+
+/// CSS files in css_path
+pub const css = [_][]const u8{
+ "style.css",
+ "style-dark.css",
+ "style-hc.css",
+ "style-hc-dark.css",
+};
+
+pub const Blueprint = struct {
+ major: u16,
+ minor: u16,
+ name: []const u8,
+};
+
+/// The list of filepaths that we depend on. Used for the build
+/// system to have proper caching.
+pub const file_inputs = deps: {
+ const total = (icon_sizes.len * 2) + blueprints.len + css.len;
+ var deps: [total][]const u8 = undefined;
+ var index: usize = 0;
+ for (icon_sizes) |size| {
+ deps[index] = std.fmt.comptimePrint("images/gnome/{d}.png", .{size});
+ deps[index + 1] = std.fmt.comptimePrint("images/gnome/{d}.png", .{size * 2});
+ index += 2;
+ }
+ for (blueprints) |bp| {
+ deps[index] = std.fmt.comptimePrint("{s}/{d}.{d}/{s}.blp", .{
+ ui_path,
+ bp.major,
+ bp.minor,
+ bp.name,
+ });
+ index += 1;
+ }
+ for (css) |name| {
+ deps[index] = std.fmt.comptimePrint("{s}/{s}", .{ css_path, name });
+ index += 1;
+ }
+ break :deps deps;
+};
+
+/// Returns the matching blueprint resource path for the given blueprint
+/// definition. This will fail at compile time if the blueprint is not
+/// found.
+///
+/// Must be called at comptime.
+pub fn blueprint(comptime bp: Blueprint) [:0]const u8 {
+ // The comptime block around this whole thing forces an error if
+ // the caller attempts to call this function at runtime.
+ comptime {
+ for (blueprints) |candidate| {
+ if (candidate.major == bp.major and
+ candidate.minor == bp.minor and
+ std.mem.eql(u8, candidate.name, bp.name))
+ {
+ return std.fmt.comptimePrint("{s}/ui/{d}.{d}/{s}.ui", .{
+ build_info.resource_path,
+ candidate.major,
+ candidate.minor,
+ candidate.name,
+ });
+ }
+ }
+
+ @compileError("invalid blueprint");
+ }
+}
+
+pub fn main() !void {
+ var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
+ defer _ = debug_allocator.deinit();
+ const alloc = debug_allocator.allocator();
+
+ // Collect the UI files that are passed in as arguments.
+ var ui_files: std.ArrayListUnmanaged([]const u8) = .empty;
+ defer {
+ for (ui_files.items) |item| alloc.free(item);
+ ui_files.deinit(alloc);
+ }
+ var it = try std.process.argsWithAllocator(alloc);
+ defer it.deinit();
+ while (it.next()) |arg| {
+ if (!std.mem.endsWith(u8, arg, ".ui")) continue;
+ try ui_files.append(
+ alloc,
+ try alloc.dupe(u8, arg),
+ );
+ }
+
+ var buf: [4096]u8 = undefined;
+ var stdout = std.fs.File.stdout().writer(&buf);
+ const writer = &stdout.interface;
+ try writer.writeAll(
+ \\<?xml version="1.0" encoding="UTF-8"?>
+ \\<gresources>
+ \\
+ );
+
+ try genRoot(writer);
+ try genIcons(writer);
+ try genUi(alloc, writer, &ui_files);
+
+ try writer.writeAll(
+ \\</gresources>
+ \\
+ );
+
+ try stdout.end();
+}
+
+/// Generate the icon resources. This works by looking up all the icons
+/// specified by `icon_sizes` in `images/icons/`. They are asserted to exist
+/// by trying to access the file.
+fn genIcons(writer: *std.Io.Writer) !void {
+ try writer.print(
+ \\ <gresource prefix="{s}/icons">
+ \\
+ , .{build_info.resource_path});
+
+ const cwd = std.fs.cwd();
+ inline for (icon_sizes) |size| {
+ // 1x
+ {
+ const alias = std.fmt.comptimePrint("{d}x{d}", .{ size, size });
+ const source = std.fmt.comptimePrint("images/gnome/{d}.png", .{size});
+ try cwd.access(source, .{});
+ try writer.print(
+ \\ <file alias="{s}/apps/{s}.png">{s}</file>
+ \\
+ ,
+ .{ alias, build_info.base_application_id, source },
+ );
+ }
+
+ // 2x
+ {
+ const alias = std.fmt.comptimePrint("{d}x{d}@2", .{ size, size });
+ const source = std.fmt.comptimePrint("images/gnome/{d}.png", .{size * 2});
+ try cwd.access(source, .{});
+ try writer.print(
+ \\ <file alias="{s}/apps/{s}.png">{s}</file>
+ \\
+ ,
+ .{ alias, build_info.base_application_id, source },
+ );
+ }
+ }
+
+ try writer.writeAll(
+ \\ </gresource>
+ \\
+ );
+}
+
+/// Generate the resources at the root prefix.
+fn genRoot(writer: *std.Io.Writer) !void {
+ try writer.print(
+ \\ <gresource prefix="{s}">
+ \\
+ , .{build_info.resource_path});
+
+ const cwd = std.fs.cwd();
+ inline for (css) |name| {
+ const source = std.fmt.comptimePrint(
+ "{s}/{s}",
+ .{ css_path, name },
+ );
+ try cwd.access(source, .{});
+ try writer.print(
+ \\ <file compressed="true" alias="{s}">{s}</file>
+ \\
+ ,
+ .{ name, source },
+ );
+ }
+
+ try writer.writeAll(
+ \\ </gresource>
+ \\
+ );
+}
+
+/// Generate all the UI resources. This works by looking up all the
+/// blueprint files in `${ui_path}/{major}.{minor}/{name}.blp` and
+/// assuming these will be
+fn genUi(
+ alloc: Allocator,
+ writer: *std.Io.Writer,
+ files: *const std.ArrayListUnmanaged([]const u8),
+) !void {
+ try writer.print(
+ \\ <gresource prefix="{s}/ui">
+ \\
+ , .{build_info.resource_path});
+
+ for (files.items) |ui_file| {
+ for (blueprints) |bp| {
+ const expected = try std.fmt.allocPrint(
+ alloc,
+ "/{d}.{d}/{s}.ui",
+ .{ bp.major, bp.minor, bp.name },
+ );
+ defer alloc.free(expected);
+ if (!std.mem.endsWith(u8, ui_file, expected)) continue;
+ try writer.print(
+ " <file compressed=\"true\" preprocess=\"xml-stripblanks\" alias=\"{d}.{d}/{s}.ui\">{s}</file>\n",
+ .{ bp.major, bp.minor, bp.name, ui_file },
+ );
+ break;
+ } else {
+ // The for loop never broke which means it didn't find
+ // a matching blueprint for this input.
+ return error.BlueprintNotFound;
+ }
+ }
+
+ try writer.writeAll(
+ \\ </gresource>
+ \\
+ );
+}
diff --git a/vendor/libghostty-vt/src/apprt/gtk/build/info.zig b/vendor/libghostty-vt/src/apprt/gtk/build/info.zig
new file mode 100644
index 00000000..fc6478d8
--- /dev/null
+++ b/vendor/libghostty-vt/src/apprt/gtk/build/info.zig
@@ -0,0 +1,18 @@
+const builtin = @import("builtin");
+
+/// Base application ID
+pub const base_application_id = "com.mitchellh.ghostty";
+
+/// GTK application ID
+pub const application_id = switch (builtin.mode) {
+ .Debug, .ReleaseSafe => base_application_id ++ "-debug",
+ .ReleaseFast, .ReleaseSmall => base_application_id,
+};
+
+pub const resource_path = "/com/mitchellh/ghostty";
+
+/// GTK object path
+pub const object_path = switch (builtin.mode) {
+ .Debug, .ReleaseSafe => resource_path ++ "_debug",
+ .ReleaseFast, .ReleaseSmall => resource_path,
+};