apprt/gtk-ng: remove Ghostty-prefix from Zig-side classes

This commit is contained in:
Mitchell Hashimoto
2025-07-17 06:10:41 -07:00
parent 531d4a480e
commit b1aab1e7bf
6 changed files with 43 additions and 40 deletions

View File

@ -6,9 +6,9 @@ pub const Surface = @import("gtk-ng/Surface.zig");
pub const resourcesDir = internal_os.resourcesDir; pub const resourcesDir = internal_os.resourcesDir;
// The exported API, custom for the apprt. // The exported API, custom for the apprt.
pub const GhosttyApplication = @import("gtk-ng/class/application.zig").GhosttyApplication; pub const Application = @import("gtk-ng/class/application.zig").Application;
pub const GhosttyWindow = @import("gtk-ng/class/window.zig").GhosttyWindow; pub const Window = @import("gtk-ng/class/window.zig").Window;
pub const GhosttyConfig = @import("gtk-ng/class/config.zig").GhosttyConfig; pub const Config = @import("gtk-ng/class/config.zig").Config;
test { test {
@import("std").testing.refAllDecls(@This()); @import("std").testing.refAllDecls(@This());

View File

@ -12,15 +12,15 @@ const internal_os = @import("../../os/main.zig");
const Config = configpkg.Config; const Config = configpkg.Config;
const CoreApp = @import("../../App.zig"); const CoreApp = @import("../../App.zig");
const GhosttyApplication = @import("class/application.zig").GhosttyApplication; const Application = @import("class/application.zig").Application;
const Surface = @import("Surface.zig"); const Surface = @import("Surface.zig");
const gtk_version = @import("gtk_version.zig"); const gtk_version = @import("gtk_version.zig");
const adw_version = @import("adw_version.zig"); const adw_version = @import("adw_version.zig");
const log = std.log.scoped(.gtk); const log = std.log.scoped(.gtk);
/// The GObject GhosttyApplication instance /// The GObject Application instance
app: *GhosttyApplication, app: *Application,
pub fn init( pub fn init(
self: *App, self: *App,
@ -31,7 +31,7 @@ pub fn init(
) !void { ) !void {
_ = opts; _ = opts;
const app: *GhosttyApplication = try .new(core_app); const app: *Application = try .new(core_app);
errdefer app.unref(); errdefer app.unref();
self.* = .{ .app = app }; self.* = .{ .app = app };
return; return;

View File

@ -15,12 +15,12 @@ const CoreApp = @import("../../../App.zig");
const configpkg = @import("../../../config.zig"); const configpkg = @import("../../../config.zig");
const internal_os = @import("../../../os/main.zig"); const internal_os = @import("../../../os/main.zig");
const xev = @import("../../../global.zig").xev; const xev = @import("../../../global.zig").xev;
const Config = configpkg.Config; const CoreConfig = configpkg.Config;
const adw_version = @import("../adw_version.zig"); const adw_version = @import("../adw_version.zig");
const gtk_version = @import("../gtk_version.zig"); const gtk_version = @import("../gtk_version.zig");
const GhosttyConfig = @import("config.zig").GhosttyConfig; const Config = @import("config.zig").Config;
const GhosttyWindow = @import("window.zig").GhosttyWindow; const Window = @import("window.zig").Window;
const ConfigErrorsDialog = @import("config_errors_dialog.zig").ConfigErrorsDialog; const ConfigErrorsDialog = @import("config_errors_dialog.zig").ConfigErrorsDialog;
const log = std.log.scoped(.gtk_ghostty_application); const log = std.log.scoped(.gtk_ghostty_application);
@ -29,7 +29,7 @@ const log = std.log.scoped(.gtk_ghostty_application);
/// ///
/// This requires a `ghostty.App` and `ghostty.Config` and takes /// This requires a `ghostty.App` and `ghostty.Config` and takes
/// care of the rest. Call `run` to run the application to completion. /// care of the rest. Call `run` to run the application to completion.
pub const GhosttyApplication = extern struct { pub const Application = extern struct {
/// This type creates a new GObject class. Since the Application is /// This type creates a new GObject class. Since the Application is
/// the primary entrypoint I'm going to use this as a place to document /// the primary entrypoint I'm going to use this as a place to document
/// how this all works and where you can find resources for it, but /// how this all works and where you can find resources for it, but
@ -49,6 +49,7 @@ pub const GhosttyApplication = extern struct {
parent_instance: Parent, parent_instance: Parent,
pub const Parent = adw.Application; pub const Parent = adw.Application;
pub const getGObjectType = gobject.ext.defineClass(Self, .{ pub const getGObjectType = gobject.ext.defineClass(Self, .{
.name = "GhosttyApplication",
.classInit = &Class.init, .classInit = &Class.init,
.parent_class = &Class.parent, .parent_class = &Class.parent,
.private = .{ .Type = Private, .offset = &Private.offset }, .private = .{ .Type = Private, .offset = &Private.offset },
@ -59,7 +60,7 @@ pub const GhosttyApplication = extern struct {
core_app: *CoreApp, core_app: *CoreApp,
/// The configuration for the application. /// The configuration for the application.
config: *GhosttyConfig, config: *Config,
/// The base path of the transient cgroup used to put all surfaces /// The base path of the transient cgroup used to put all surfaces
/// into their own cgroup. This is only set if cgroups are enabled /// into their own cgroup. This is only set if cgroups are enabled
@ -74,7 +75,7 @@ pub const GhosttyApplication = extern struct {
var offset: c_int = 0; var offset: c_int = 0;
}; };
/// Creates a new GhosttyApplication instance. /// Creates a new Application instance.
/// ///
/// This does a lot more work than a typical class instantiation, /// This does a lot more work than a typical class instantiation,
/// because we expect that this is the main program entrypoint. /// because we expect that this is the main program entrypoint.
@ -99,12 +100,12 @@ pub const GhosttyApplication = extern struct {
}; };
// Load our configuration. // Load our configuration.
var config = Config.load(alloc) catch |err| err: { var config = CoreConfig.load(alloc) catch |err| err: {
// If we fail to load the configuration, then we should log // If we fail to load the configuration, then we should log
// the error in the diagnostics so it can be shown to the user. // the error in the diagnostics so it can be shown to the user.
// We can still load a default which only fails for OOM, allowing // We can still load a default which only fails for OOM, allowing
// us to startup. // us to startup.
var default: Config = try .default(alloc); var default: CoreConfig = try .default(alloc);
errdefer default.deinit(); errdefer default.deinit();
const config_arena = default._arena.?.allocator(); const config_arena = default._arena.?.allocator();
try default._diagnostics.append(config_arena, .{ try default._diagnostics.append(config_arena, .{
@ -171,7 +172,7 @@ pub const GhosttyApplication = extern struct {
}); });
// Wrap our configuration in a GObject. // Wrap our configuration in a GObject.
const config_obj: *GhosttyConfig = try .new(alloc, &config); const config_obj: *Config = try .new(alloc, &config);
errdefer config_obj.unref(); errdefer config_obj.unref();
// Initialize the app. // Initialize the app.
@ -310,7 +311,7 @@ pub const GhosttyApplication = extern struct {
gobject.Object.unref(self.as(gobject.Object)); gobject.Object.unref(self.as(gobject.Object));
} }
fn private(self: *GhosttyApplication) *Private { fn private(self: *Self) *Private {
return gobject.ext.impl_helpers.getPrivate( return gobject.ext.impl_helpers.getPrivate(
self, self,
Private, Private,
@ -318,7 +319,7 @@ pub const GhosttyApplication = extern struct {
); );
} }
fn startup(self: *GhosttyApplication) callconv(.C) void { fn startup(self: *Self) callconv(.C) void {
log.debug("startup", .{}); log.debug("startup", .{});
gio.Application.virtual_methods.startup.call( gio.Application.virtual_methods.startup.call(
@ -351,7 +352,7 @@ pub const GhosttyApplication = extern struct {
/// Configure libxev to use a specific backend. /// Configure libxev to use a specific backend.
/// ///
/// This must be called before any other xev APIs are used. /// This must be called before any other xev APIs are used.
fn startupXev(self: *GhosttyApplication) void { fn startupXev(self: *Self) void {
const priv = self.private(); const priv = self.private();
const config = priv.config.get(); const config = priv.config.get();
@ -381,7 +382,7 @@ pub const GhosttyApplication = extern struct {
/// Setup the style manager on startup. The primary task here is to /// Setup the style manager on startup. The primary task here is to
/// setup our initial light/dark mode based on the configuration and /// setup our initial light/dark mode based on the configuration and
/// setup listeners for changes to the style manager. /// setup listeners for changes to the style manager.
fn startupStyleManager(self: *GhosttyApplication) void { fn startupStyleManager(self: *Self) void {
const priv = self.private(); const priv = self.private();
const config = priv.config.get(); const config = priv.config.get();
@ -403,7 +404,7 @@ pub const GhosttyApplication = extern struct {
// Setup color change notifications // Setup color change notifications
_ = gobject.Object.signals.notify.connect( _ = gobject.Object.signals.notify.connect(
style, style,
*GhosttyApplication, *Self,
handleStyleManagerDark, handleStyleManagerDark,
self, self,
.{ .detail = "dark" }, .{ .detail = "dark" },
@ -420,7 +421,7 @@ pub const GhosttyApplication = extern struct {
/// The setup for cgroups involves creating the cgroup for our /// The setup for cgroups involves creating the cgroup for our
/// application, moving ourselves into it, and storing the base path /// application, moving ourselves into it, and storing the base path
/// so that created surfaces can also have their own cgroups. /// so that created surfaces can also have their own cgroups.
fn startupCgroup(self: *GhosttyApplication) CgroupError!void { fn startupCgroup(self: *Self) CgroupError!void {
const priv = self.private(); const priv = self.private();
const config = priv.config.get(); const config = priv.config.get();
@ -476,7 +477,7 @@ pub const GhosttyApplication = extern struct {
priv.transient_cgroup_base = path; priv.transient_cgroup_base = path;
} }
fn activate(self: *GhosttyApplication) callconv(.C) void { fn activate(self: *Self) callconv(.C) void {
log.debug("activate", .{}); log.debug("activate", .{});
// Call the parent activate method. // Call the parent activate method.
@ -485,11 +486,11 @@ pub const GhosttyApplication = extern struct {
self.as(Parent), self.as(Parent),
); );
// const win = GhosttyWindow.new(self); // const win = Window.new(self);
// gtk.Window.present(win.as(gtk.Window)); // gtk.Window.present(win.as(gtk.Window));
} }
fn finalize(self: *GhosttyApplication) callconv(.C) void { fn finalize(self: *Self) callconv(.C) void {
self.deinit(); self.deinit();
gobject.Object.virtual_methods.finalize.call( gobject.Object.virtual_methods.finalize.call(
Class.parent, Class.parent,
@ -500,7 +501,7 @@ pub const GhosttyApplication = extern struct {
fn handleStyleManagerDark( fn handleStyleManagerDark(
style: *adw.StyleManager, style: *adw.StyleManager,
_: *gobject.ParamSpec, _: *gobject.ParamSpec,
self: *GhosttyApplication, self: *Self,
) callconv(.c) void { ) callconv(.c) void {
_ = self; _ = self;
@ -512,7 +513,7 @@ pub const GhosttyApplication = extern struct {
log.debug("style manager changed scheme={}", .{color_scheme}); log.debug("style manager changed scheme={}", .{color_scheme});
} }
fn allocator(self: *GhosttyApplication) std.mem.Allocator { fn allocator(self: *Self) std.mem.Allocator {
return self.private().core_app.alloc; return self.private().core_app.alloc;
} }

View File

@ -5,7 +5,7 @@ const gobject = @import("gobject");
const gtk = @import("gtk"); const gtk = @import("gtk");
const configpkg = @import("../../../config.zig"); const configpkg = @import("../../../config.zig");
const Config = configpkg.Config; const CoreConfig = configpkg.Config;
const log = std.log.scoped(.gtk_ghostty_config); const log = std.log.scoped(.gtk_ghostty_config);
@ -19,11 +19,12 @@ const log = std.log.scoped(.gtk_ghostty_config);
/// ///
/// This can also expose helpers to access configuration in ways that /// This can also expose helpers to access configuration in ways that
/// may be more egonomic to GTK primitives. /// may be more egonomic to GTK primitives.
pub const GhosttyConfig = extern struct { pub const Config = extern struct {
const Self = @This(); const Self = @This();
parent_instance: Parent, parent_instance: Parent,
pub const Parent = gobject.Object; pub const Parent = gobject.Object;
pub const getGObjectType = gobject.ext.defineClass(Self, .{ pub const getGObjectType = gobject.ext.defineClass(Self, .{
.name = "GhosttyConfig",
.classInit = &Class.init, .classInit = &Class.init,
.parent_class = &Class.parent, .parent_class = &Class.parent,
.private = .{ .Type = Private, .offset = &Private.offset }, .private = .{ .Type = Private, .offset = &Private.offset },
@ -60,7 +61,7 @@ pub const GhosttyConfig = extern struct {
}; };
const Private = struct { const Private = struct {
config: Config, config: CoreConfig,
var offset: c_int = 0; var offset: c_int = 0;
}; };
@ -69,7 +70,7 @@ pub const GhosttyConfig = extern struct {
/// ///
/// This clones the given configuration, so it is safe for the /// This clones the given configuration, so it is safe for the
/// caller to free the original configuration after this call. /// caller to free the original configuration after this call.
pub fn new(alloc: Allocator, config: *const Config) Allocator.Error!*Self { pub fn new(alloc: Allocator, config: *const CoreConfig) Allocator.Error!*Self {
const self = gobject.ext.newInstance(Self, .{}); const self = gobject.ext.newInstance(Self, .{});
errdefer self.unref(); errdefer self.unref();
@ -81,7 +82,7 @@ pub const GhosttyConfig = extern struct {
/// Get the wrapped configuration. It's unsafe to store this or access /// Get the wrapped configuration. It's unsafe to store this or access
/// it in any way that may live beyond the lifetime of this object. /// it in any way that may live beyond the lifetime of this object.
pub fn get(self: *Self) *const Config { pub fn get(self: *Self) *const CoreConfig {
return &self.private().config; return &self.private().config;
} }
@ -89,7 +90,7 @@ pub const GhosttyConfig = extern struct {
/// because any changes to the config won't be propagated to anyone /// because any changes to the config won't be propagated to anyone
/// with a reference to this object. If you know what you're doing, then /// with a reference to this object. If you know what you're doing, then
/// you can use this. /// you can use this.
pub fn getMut(self: *Self) *Config { pub fn getMut(self: *Self) *CoreConfig {
return &self.private().config; return &self.private().config;
} }
@ -176,8 +177,8 @@ pub const GhosttyConfig = extern struct {
test "GhosttyConfig" { test "GhosttyConfig" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;
var config: Config = try .default(alloc); var config: CoreConfig = try .default(alloc);
defer config.deinit(); defer config.deinit();
const obj: *GhosttyConfig = try .new(alloc, &config); const obj: *Config = try .new(alloc, &config);
obj.unref(); obj.unref();
} }

View File

@ -5,7 +5,7 @@ const gtk = @import("gtk");
const gresource = @import("../build/gresource.zig"); const gresource = @import("../build/gresource.zig");
const adw_version = @import("../adw_version.zig"); const adw_version = @import("../adw_version.zig");
const Config = @import("config.zig").GhosttyConfig; const Config = @import("config.zig").Config;
const log = std.log.scoped(.gtk_ghostty_window); const log = std.log.scoped(.gtk_ghostty_window);

View File

@ -4,15 +4,16 @@ const gobject = @import("gobject");
const gtk = @import("gtk"); const gtk = @import("gtk");
const gresource = @import("../build/gresource.zig"); const gresource = @import("../build/gresource.zig");
const GhosttyApplication = @import("application.zig").GhosttyApplication; const Application = @import("application.zig").Application;
const log = std.log.scoped(.gtk_ghostty_window); const log = std.log.scoped(.gtk_ghostty_window);
pub const GhosttyWindow = extern struct { pub const Window = extern struct {
const Self = @This(); const Self = @This();
parent_instance: Parent, parent_instance: Parent,
pub const Parent = adw.ApplicationWindow; pub const Parent = adw.ApplicationWindow;
pub const getGObjectType = gobject.ext.defineClass(Self, .{ pub const getGObjectType = gobject.ext.defineClass(Self, .{
.name = "GhosttyWindow",
.instanceInit = &init, .instanceInit = &init,
.classInit = &Class.init, .classInit = &Class.init,
.parent_class = &Class.parent, .parent_class = &Class.parent,
@ -24,11 +25,11 @@ pub const GhosttyWindow = extern struct {
var offset: c_int = 0; var offset: c_int = 0;
}; };
pub fn new(app: *GhosttyApplication) *Self { pub fn new(app: *Application) *Self {
return gobject.ext.newInstance(Self, .{ .application = app }); return gobject.ext.newInstance(Self, .{ .application = app });
} }
fn init(self: *GhosttyWindow, _: *Class) callconv(.C) void { fn init(self: *Self, _: *Class) callconv(.C) void {
gtk.Widget.initTemplate(self.as(gtk.Widget)); gtk.Widget.initTemplate(self.as(gtk.Widget));
} }