diff --git a/src/apprt/gtk-ng/Surface.zig b/src/apprt/gtk-ng/Surface.zig index 7613abd2d..d1a5cbec3 100644 --- a/src/apprt/gtk-ng/Surface.zig +++ b/src/apprt/gtk-ng/Surface.zig @@ -32,7 +32,7 @@ pub fn rtApp(self: *Self) *ApprtApp { } pub fn close(self: *Self, process_active: bool) void { - self.surface.close(process_active); + self.surface.close(.{ .surface = process_active }); } pub fn cgroup(self: *Self) ?[]const u8 { diff --git a/src/apprt/gtk-ng/class/application.zig b/src/apprt/gtk-ng/class/application.zig index 4847b1283..70dfa4c90 100644 --- a/src/apprt/gtk-ng/class/application.zig +++ b/src/apprt/gtk-ng/class/application.zig @@ -28,6 +28,7 @@ const ApprtApp = @import("../App.zig"); const Common = @import("../class.zig").Common; const WeakRef = @import("../weak_ref.zig").WeakRef; const Config = @import("config.zig").Config; +const Surface = @import("surface.zig").Surface; const Window = @import("window.zig").Window; const CloseConfirmationDialog = @import("close_confirmation_dialog.zig").CloseConfirmationDialog; const ConfigErrorsDialog = @import("config_errors_dialog.zig").ConfigErrorsDialog; @@ -469,6 +470,9 @@ pub const Application = extern struct { value: apprt.Action.Value(action), ) !bool { switch (action) { + .close_tab => Action.close(target, .tab), + .close_window => Action.close(target, .window), + .config_change => try Action.configChange( self, target, @@ -495,7 +499,7 @@ pub const Application = extern struct { .progress_report => return Action.progressReport(target, value), - .render => Action.render(self, target), + .render => Action.render(target), .ring_bell => Action.ringBell(target), @@ -506,11 +510,9 @@ pub const Application = extern struct { .show_gtk_inspector => Action.showGtkInspector(), // Unimplemented but todo on gtk-ng branch - .close_window, .toggle_maximize, .toggle_fullscreen, .new_tab, - .close_tab, .goto_tab, .move_tab, .new_split, @@ -1047,6 +1049,16 @@ pub const Application = extern struct { /// All apprt action handlers const Action = struct { + pub fn close( + target: apprt.Target, + scope: Surface.CloseScope, + ) void { + switch (target) { + .app => {}, + .surface => |v| v.rt_surface.surface.close(scope), + } + } + pub fn configChange( self: *Application, target: apprt.Target, @@ -1180,7 +1192,7 @@ const Action = struct { }; } - pub fn render(_: *Application, target: apprt.Target) void { + pub fn render(target: apprt.Target) void { switch (target) { .app => {}, .surface => |v| v.rt_surface.surface.redraw(), diff --git a/src/apprt/gtk-ng/class/surface.zig b/src/apprt/gtk-ng/class/surface.zig index 5b4c9da1b..79abc17e3 100644 --- a/src/apprt/gtk-ng/class/surface.zig +++ b/src/apprt/gtk-ng/class/surface.zig @@ -228,7 +228,7 @@ pub const Surface = extern struct { const impl = gobject.ext.defineSignal( name, Self, - &.{bool}, + &.{*const CloseScope}, void, ); }; @@ -829,11 +829,11 @@ pub const Surface = extern struct { //--------------------------------------------------------------- // Libghostty Callbacks - pub fn close(self: *Self, process_active: bool) void { + pub fn close(self: *Self, scope: CloseScope) void { signals.@"close-request".impl.emit( self, null, - .{process_active}, + .{&scope}, null, ); } @@ -1262,7 +1262,7 @@ pub const Surface = extern struct { self: *Self, ) callconv(.c) void { // This closes the surface with no confirmation. - self.close(false); + self.close(.{ .surface = false }); } fn dtDrop( @@ -2093,6 +2093,25 @@ pub const Surface = extern struct { pub const bindTemplateChildPrivate = C.Class.bindTemplateChildPrivate; pub const bindTemplateCallback = C.Class.bindTemplateCallback; }; + + /// The scope of a close request. + pub const CloseScope = union(enum) { + /// Close the surface. The boolean determines if there is a + /// process active. + surface: bool, + + /// Close the tab. We can't know if there are processes active + /// for the entire tab scope so listners must query the app. + tab, + + /// Close the window. + window, + + pub const getGObjectType = gobject.ext.defineBoxed( + CloseScope, + .{ .name = "GhosttySurfaceCloseScope" }, + ); + }; }; /// The state of the key event while we're doing IM composition. diff --git a/src/apprt/gtk-ng/class/window.zig b/src/apprt/gtk-ng/class/window.zig index 6e906b149..2166889fb 100644 --- a/src/apprt/gtk-ng/class/window.zig +++ b/src/apprt/gtk-ng/class/window.zig @@ -132,11 +132,11 @@ pub const Window = extern struct { fn surfaceCloseRequest( surface: *Surface, - process_active: bool, + scope: *const Surface.CloseScope, self: *Self, ) callconv(.c) void { // Todo - _ = process_active; + _ = scope; assert(surface == self.private().surface); self.as(gtk.Window).close();