mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-06-01 01:21:22 +00:00
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:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user