summaryrefslogtreecommitdiff
path: root/src/App.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/App.zig')
-rw-r--r--src/App.zig34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/App.zig b/src/App.zig
index 005b745a6..02089ae5b 100644
--- a/src/App.zig
+++ b/src/App.zig
@@ -76,34 +76,38 @@ first: bool = true,
pub const CreateError = Allocator.Error || font.SharedGridSet.InitError;
+/// Create a new app instance. This returns a stable pointer to the app
+/// instance which is required for callbacks.
+pub fn create(alloc: Allocator) CreateError!*App {
+ var app = try alloc.create(App);
+ errdefer alloc.destroy(app);
+ try app.init(alloc);
+ return app;
+}
+
/// Initialize the main app instance. This creates the main window, sets
/// up the renderer state, compiles the shaders, etc. This is the primary
/// "startup" logic.
///
/// 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,7 +118,13 @@ pub fn destroy(self: *App) void {
// should gracefully close all surfaces.
assert(self.font_grid_set.count() == 0);
self.font_grid_set.deinit();
+}
+
+pub fn destroy(self: *App) void {
+ // Deinitialize the app
+ self.deinit();
+ // Free the app memory
self.alloc.destroy(self);
}
@@ -445,6 +455,10 @@ pub fn performAction(
.toggle_quick_terminal => _ = try rt_app.performAction(.app, .toggle_quick_terminal, {}),
.toggle_visibility => _ = try rt_app.performAction(.app, .toggle_visibility, {}),
.check_for_updates => _ = try rt_app.performAction(.app, .check_for_updates, {}),
+ .show_gtk_inspector => _ = try rt_app.performAction(.app, .show_gtk_inspector, {}),
+ .undo => _ = try rt_app.performAction(.app, .undo, {}),
+
+ .redo => _ = try rt_app.performAction(.app, .redo, {}),
}
}