mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-08-27 17:41:40 +00:00
core: con't copy App and apprt.App
Besides avoiding copying, this allows consumers to choose to allocate these structs on the stack or to allocate on the heap. It also gives the apprt.App a stable pointer sooner in the process.
This commit is contained in:
committed by
Mitchell Hashimoto
parent
070e017b1b
commit
c6f23bbb32
17
src/App.zig
17
src/App.zig
@@ -82,28 +82,23 @@ pub const CreateError = Allocator.Error || font.SharedGridSet.InitError;
|
||||
///
|
||||
/// After calling this function, well behaved apprts should then call
|
||||
/// `focusEvent` to set the initial focus state of the app.
|
||||
pub fn create(
|
||||
pub fn init(
|
||||
self: *App,
|
||||
alloc: Allocator,
|
||||
) CreateError!*App {
|
||||
var app = try alloc.create(App);
|
||||
errdefer alloc.destroy(app);
|
||||
|
||||
) CreateError!void {
|
||||
var font_grid_set = try font.SharedGridSet.init(alloc);
|
||||
errdefer font_grid_set.deinit();
|
||||
|
||||
app.* = .{
|
||||
self.* = .{
|
||||
.alloc = alloc,
|
||||
.surfaces = .{},
|
||||
.mailbox = .{},
|
||||
.font_grid_set = font_grid_set,
|
||||
.config_conditional_state = .{},
|
||||
};
|
||||
errdefer app.surfaces.deinit(alloc);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
pub fn destroy(self: *App) void {
|
||||
pub fn deinit(self: *App) void {
|
||||
// Clean up all our surfaces
|
||||
for (self.surfaces.items) |surface| surface.deinit();
|
||||
self.surfaces.deinit(self.alloc);
|
||||
@@ -114,8 +109,6 @@ pub fn destroy(self: *App) void {
|
||||
// should gracefully close all surfaces.
|
||||
assert(self.font_grid_set.count() == 0);
|
||||
self.font_grid_set.deinit();
|
||||
|
||||
self.alloc.destroy(self);
|
||||
}
|
||||
|
||||
/// Tick ticks the app loop. This will drain our mailbox and process those
|
||||
|
||||
Reference in New Issue
Block a user