apprt/gtk-ng: close surface, close window

This commit is contained in:
Mitchell Hashimoto
2025-07-25 12:56:15 -07:00
parent f27fd0f550
commit 5b37e86391
4 changed files with 42 additions and 11 deletions

View File

@ -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 {

View File

@ -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(),

View File

@ -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.

View File

@ -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();