try to abstract bundle ID to a zig file

This commit is contained in:
Mitchell Hashimoto
2024-11-25 16:10:55 -08:00
parent adc59be977
commit b9345e8d6a
8 changed files with 26 additions and 7 deletions

View File

@ -14,6 +14,7 @@ const std = @import("std");
const assert = std.debug.assert; const assert = std.debug.assert;
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const builtin = @import("builtin"); const builtin = @import("builtin");
const build_config = @import("../../build_config.zig");
const apprt = @import("../../apprt.zig"); const apprt = @import("../../apprt.zig");
const configpkg = @import("../../config.zig"); const configpkg = @import("../../config.zig");
const input = @import("../../input.zig"); const input = @import("../../input.zig");
@ -181,7 +182,7 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
} }
} }
const default_id = "com.mitchellh.ghostty"; const default_id = comptime build_config.bundle_id;
break :app_id if (builtin.mode == .Debug) default_id ++ "-debug" else default_id; break :app_id if (builtin.mode == .Debug) default_id ++ "-debug" else default_id;
}; };

View File

@ -3,6 +3,7 @@ const ConfigErrors = @This();
const std = @import("std"); const std = @import("std");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const build_config = @import("../../build_config.zig");
const configpkg = @import("../../config.zig"); const configpkg = @import("../../config.zig");
const Config = configpkg.Config; const Config = configpkg.Config;
@ -53,7 +54,7 @@ fn init(self: *ConfigErrors, app: *App) !void {
c.gtk_window_set_title(gtk_window, "Configuration Errors"); c.gtk_window_set_title(gtk_window, "Configuration Errors");
c.gtk_window_set_default_size(gtk_window, 600, 275); c.gtk_window_set_default_size(gtk_window, 600, 275);
c.gtk_window_set_resizable(gtk_window, 0); c.gtk_window_set_resizable(gtk_window, 0);
c.gtk_window_set_icon_name(gtk_window, "com.mitchellh.ghostty"); c.gtk_window_set_icon_name(gtk_window, build_config.bundle_id);
_ = c.g_signal_connect_data(window, "destroy", c.G_CALLBACK(&gtkDestroy), self, null, c.G_CONNECT_DEFAULT); _ = c.g_signal_connect_data(window, "destroy", c.G_CALLBACK(&gtkDestroy), self, null, c.G_CONNECT_DEFAULT);
// Set some state // Set some state

View File

@ -5,6 +5,7 @@ const Surface = @This();
const std = @import("std"); const std = @import("std");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const build_config = @import("../../build_config.zig");
const configpkg = @import("../../config.zig"); const configpkg = @import("../../config.zig");
const apprt = @import("../../apprt.zig"); const apprt = @import("../../apprt.zig");
const font = @import("../../font/main.zig"); const font = @import("../../font/main.zig");
@ -1149,7 +1150,7 @@ pub fn showDesktopNotification(
defer c.g_object_unref(notification); defer c.g_object_unref(notification);
c.g_notification_set_body(notification, body.ptr); c.g_notification_set_body(notification, body.ptr);
const icon = c.g_themed_icon_new("com.mitchellh.ghostty"); const icon = c.g_themed_icon_new(build_config.bundle_id);
defer c.g_object_unref(icon); defer c.g_object_unref(icon);
c.g_notification_set_icon(notification, icon); c.g_notification_set_icon(notification, icon);

View File

@ -103,7 +103,7 @@ pub fn init(self: *Window, app: *App) !void {
// to disable this so that terminal programs can capture F10 (such as htop) // to disable this so that terminal programs can capture F10 (such as htop)
c.gtk_window_set_handle_menubar_accel(gtk_window, 0); c.gtk_window_set_handle_menubar_accel(gtk_window, 0);
c.gtk_window_set_icon_name(gtk_window, "com.mitchellh.ghostty"); c.gtk_window_set_icon_name(gtk_window, build_config.bundle_id);
// Apply class to color headerbar if window-theme is set to `ghostty` and // Apply class to color headerbar if window-theme is set to `ghostty` and
// GTK version is before 4.16. The conditional is because above 4.16 // GTK version is before 4.16. The conditional is because above 4.16

View File

@ -2,6 +2,7 @@ const std = @import("std");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
const assert = std.debug.assert; const assert = std.debug.assert;
const build_config = @import("../../build_config.zig");
const App = @import("App.zig"); const App = @import("App.zig");
const Surface = @import("Surface.zig"); const Surface = @import("Surface.zig");
const TerminalWindow = @import("Window.zig"); const TerminalWindow = @import("Window.zig");
@ -141,7 +142,7 @@ const Window = struct {
self.window = gtk_window; self.window = gtk_window;
c.gtk_window_set_title(gtk_window, "Ghostty: Terminal Inspector"); c.gtk_window_set_title(gtk_window, "Ghostty: Terminal Inspector");
c.gtk_window_set_default_size(gtk_window, 1000, 600); c.gtk_window_set_default_size(gtk_window, 1000, 600);
c.gtk_window_set_icon_name(gtk_window, "com.mitchellh.ghostty"); c.gtk_window_set_icon_name(gtk_window, build_config.bundle_id);
// Initialize our imgui widget // Initialize our imgui widget
try self.imgui_widget.init(); try self.imgui_widget.init();

View File

@ -103,6 +103,20 @@ pub const app_runtime: apprt.Runtime = config.app_runtime;
pub const font_backend: font.Backend = config.font_backend; pub const font_backend: font.Backend = config.font_backend;
pub const renderer: rendererpkg.Impl = config.renderer; pub const renderer: rendererpkg.Impl = config.renderer;
/// The bundle ID for the app. This is used in many places and is currently
/// hardcoded here. We could make this configurable in the future if there
/// is a reason to do so.
///
/// On macOS, this must match the App bundle ID. We can get that dynamically
/// via an API but I don't want to pay the cost of that at runtime.
///
/// On GTK, this should match the various folders with resources.
///
/// There are many places that don't use this variable so simply swapping
/// this variable is NOT ENOUGH to change the bundle ID. I just wanted to
/// avoid it in Zig coe as much as possible.
pub const bundle_id = "com.mitchellh.ghostty";
/// True if we should have "slow" runtime safety checks. The initial motivation /// True if we should have "slow" runtime safety checks. The initial motivation
/// for this was terminal page/pagelist integrity checks. These were VERY /// for this was terminal page/pagelist integrity checks. These were VERY
/// slow but very thorough. But they made it so slow that the terminal couldn't /// slow but very thorough. But they made it so slow that the terminal couldn't

View File

@ -141,7 +141,7 @@ fn logFn(
// Initialize a logger. This is slow to do on every operation // Initialize a logger. This is slow to do on every operation
// but we shouldn't be logging too much. // but we shouldn't be logging too much.
const logger = macos.os.Log.create("com.mitchellh.ghostty", @tagName(scope)); const logger = macos.os.Log.create(build_config.bundle_id, @tagName(scope));
defer logger.release(); defer logger.release();
logger.log(std.heap.c_allocator, mac_level, format, args); logger.log(std.heap.c_allocator, mac_level, format, args);
} }

View File

@ -1,5 +1,6 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin"); const builtin = @import("builtin");
const build_config = @import("../build_config.zig");
const assert = std.debug.assert; const assert = std.debug.assert;
const objc = @import("objc"); const objc = @import("objc");
const Allocator = std.mem.Allocator; const Allocator = std.mem.Allocator;
@ -56,7 +57,7 @@ pub fn appSupportDir(
return try std.fs.path.join(alloc, &.{ return try std.fs.path.join(alloc, &.{
app_support_dir, app_support_dir,
"com.mitchellh.ghostty", build_config.bundle_id,
sub_path, sub_path,
}); });
} }