style: use decl literals

This commit changes a LOT of areas of the code to use decl literals
instead of redundantly referring to the type.

These changes were mostly driven by some regex searches and then manual
adjustment on a case-by-case basis.

I almost certainly missed quite a few places where decl literals could
be used, but this is a good first step in converting things, and other
instances can be addressed when they're discovered.

I tested GLFW+Metal and building the framework on macOS and tested a GTK
build on Linux, so I'm 99% sure I didn't introduce any syntax errors or
other problems with this. (fingers crossed)
This commit is contained in:
Qwerasd
2025-05-26 21:39:15 -06:00
parent 2fe2ccdbde
commit 2384bd69cc
57 changed files with 177 additions and 177 deletions

View File

@@ -423,7 +423,7 @@ pub const Surface = struct {
pub fn init(self: *Surface, app: *App, opts: Options) !void {
self.* = .{
.app = app,
.platform = try Platform.init(opts.platform_tag, opts.platform),
.platform = try .init(opts.platform_tag, opts.platform),
.userdata = opts.userdata,
.core_surface = undefined,
.content_scale = .{
@@ -522,7 +522,7 @@ pub const Surface = struct {
const alloc = self.app.core_app.alloc;
const inspector = try alloc.create(Inspector);
errdefer alloc.destroy(inspector);
inspector.* = try Inspector.init(self);
inspector.* = try .init(self);
self.inspector = inspector;
return inspector;
}
@@ -1180,7 +1180,7 @@ pub const CAPI = struct {
// Create our runtime app
var app = try global.alloc.create(App);
errdefer global.alloc.destroy(app);
app.* = try App.init(core_app, config, opts.*);
app.* = try .init(core_app, config, opts.*);
errdefer app.terminate();
return app;
@@ -1949,7 +1949,7 @@ pub const CAPI = struct {
}
export fn ghostty_inspector_metal_init(ptr: *Inspector, device: objc.c.id) bool {
return ptr.initMetal(objc.Object.fromId(device));
return ptr.initMetal(.fromId(device));
}
export fn ghostty_inspector_metal_render(
@@ -1958,8 +1958,8 @@ pub const CAPI = struct {
descriptor: objc.c.id,
) void {
return ptr.renderMetal(
objc.Object.fromId(command_buffer),
objc.Object.fromId(descriptor),
.fromId(command_buffer),
.fromId(descriptor),
) catch |err| {
log.err("error rendering inspector err={}", .{err});
return;

View File

@@ -69,16 +69,16 @@ fn init(
request: apprt.ClipboardRequest,
is_secure_input: bool,
) !void {
var builder = switch (DialogType) {
var builder: Builder = switch (DialogType) {
adw.AlertDialog => switch (request) {
.osc_52_read => Builder.init("ccw-osc-52-read", 1, 5),
.osc_52_write => Builder.init("ccw-osc-52-write", 1, 5),
.paste => Builder.init("ccw-paste", 1, 5),
.osc_52_read => .init("ccw-osc-52-read", 1, 5),
.osc_52_write => .init("ccw-osc-52-write", 1, 5),
.paste => .init("ccw-paste", 1, 5),
},
adw.MessageDialog => switch (request) {
.osc_52_read => Builder.init("ccw-osc-52-read", 1, 2),
.osc_52_write => Builder.init("ccw-osc-52-write", 1, 2),
.paste => Builder.init("ccw-paste", 1, 2),
.osc_52_read => .init("ccw-osc-52-read", 1, 2),
.osc_52_write => .init("ccw-osc-52-write", 1, 2),
.paste => .init("ccw-paste", 1, 2),
},
else => unreachable,
};

View File

@@ -32,9 +32,9 @@ pub fn maybePresent(app: *App, window: ?*Window) void {
const config_errors_dialog = config_errors_dialog: {
if (app.config_errors_dialog) |config_errors_dialog| break :config_errors_dialog config_errors_dialog;
var builder = switch (DialogType) {
adw.AlertDialog => Builder.init("config-errors-dialog", 1, 5),
adw.MessageDialog => Builder.init("config-errors-dialog", 1, 2),
var builder: Builder = switch (DialogType) {
adw.AlertDialog => .init("config-errors-dialog", 1, 5),
adw.MessageDialog => .init("config-errors-dialog", 1, 2),
else => unreachable,
};

View File

@@ -50,12 +50,12 @@ first: bool = true,
pub fn init(self: *ResizeOverlay, surface: *Surface, config: *const configpkg.Config) void {
self.* = .{
.surface = surface,
.config = DerivedConfig.init(config),
.config = .init(config),
};
}
pub fn updateConfig(self: *ResizeOverlay, config: *const configpkg.Config) void {
self.config = DerivedConfig.init(config);
self.config = .init(config);
}
/// De-initialize the ResizeOverlay. This removes any pending idlers/timers that

View File

@@ -138,7 +138,7 @@ pub fn init(
.container = container,
.top_left = .{ .surface = tl },
.bottom_right = .{ .surface = br },
.orientation = Orientation.fromDirection(direction),
.orientation = .fromDirection(direction),
};
// Replace the previous containers element with our split. This allows a

View File

@@ -1191,7 +1191,7 @@ pub fn mouseOverLink(self: *Surface, uri_: ?[]const u8) void {
return;
}
self.url_widget = URLWidget.init(self.overlay, uriZ);
self.url_widget = .init(self.overlay, uriZ);
}
pub fn supportsClipboard(

View File

@@ -136,7 +136,7 @@ pub fn init(self: *Window, app: *App) !void {
self.* = .{
.app = app,
.last_config = @intFromPtr(&app.config),
.config = DerivedConfig.init(&app.config),
.config = .init(&app.config),
.window = undefined,
.headerbar = undefined,
.tab_overview = null,
@@ -148,7 +148,7 @@ pub fn init(self: *Window, app: *App) !void {
};
// Create the window
self.window = adw.ApplicationWindow.new(app.app.as(gtk.Application));
self.window = .new(app.app.as(gtk.Application));
const gtk_window = self.window.as(gtk.Window);
const gtk_widget = self.window.as(gtk.Widget);
errdefer gtk_window.destroy();
@@ -333,7 +333,7 @@ pub fn init(self: *Window, app: *App) !void {
}
// Setup our toast overlay if we have one
self.toast_overlay = adw.ToastOverlay.new();
self.toast_overlay = .new();
self.toast_overlay.setChild(self.notebook.asWidget());
box.append(self.toast_overlay.as(gtk.Widget));
@@ -463,7 +463,7 @@ pub fn updateConfig(
if (self.last_config == this_config) return;
self.last_config = this_config;
self.config = DerivedConfig.init(config);
self.config = .init(config);
// We always resync our appearance whenever the config changes.
try self.syncAppearance();

View File

@@ -138,7 +138,7 @@ const Window = struct {
};
// Create the window
self.window = gtk.ApplicationWindow.new(inspector.surface.app.app.as(gtk.Application));
self.window = .new(inspector.surface.app.app.as(gtk.Application));
errdefer self.window.as(gtk.Window).destroy();
self.window.as(gtk.Window).setTitle(i18n._("Ghostty: Terminal Inspector"));

View File

@@ -109,7 +109,7 @@ pub const App = struct {
return .{
.display = xlib_display,
.base_event_code = base_event_code,
.atoms = Atoms.init(gdk_x11_display),
.atoms = .init(gdk_x11_display),
};
}