mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-07-29 03:47:54 +00:00
apprt/embedded: close surface callback
This commit is contained in:
@@ -946,6 +946,12 @@ pub fn keyCallback(
|
||||
} else log.warn("runtime doesn't implement newSplit", .{});
|
||||
},
|
||||
|
||||
.close_surface => {
|
||||
if (@hasDecl(apprt.Surface, "closeSurface")) {
|
||||
try self.rt_surface.closeSurface();
|
||||
} else log.warn("runtime doesn't implement closeSurface", .{});
|
||||
},
|
||||
|
||||
.close_window => {
|
||||
_ = self.app_mailbox.push(.{ .close = self }, .{ .instant = {} });
|
||||
},
|
||||
|
||||
@@ -47,7 +47,10 @@ pub const App = struct {
|
||||
|
||||
/// Create a new split view. If the embedder doesn't support split
|
||||
/// views then this can be null.
|
||||
new_split: ?*const fn (SurfaceUD, input.Binding.Action.SplitDirection) callconv(.C) void = null,
|
||||
new_split: ?*const fn (SurfaceUD, input.SplitDirection) callconv(.C) void = null,
|
||||
|
||||
/// Close the current surface given by this function.
|
||||
close_surface: ?*const fn (SurfaceUD) callconv(.C) void = null,
|
||||
};
|
||||
|
||||
core_app: *CoreApp,
|
||||
@@ -161,6 +164,15 @@ pub const Surface = struct {
|
||||
func(self.opts.userdata, direction);
|
||||
}
|
||||
|
||||
pub fn closeSurface(self: *const Surface) !void {
|
||||
const func = self.app.opts.close_surface orelse {
|
||||
log.info("runtime embedder does not closing a surface", .{});
|
||||
return;
|
||||
};
|
||||
|
||||
func(self.opts.userdata);
|
||||
}
|
||||
|
||||
pub fn getContentScale(self: *const Surface) !apprt.ContentScale {
|
||||
return self.content_scale;
|
||||
}
|
||||
|
||||
@@ -278,8 +278,8 @@ pub const Config = struct {
|
||||
);
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
.{ .key = .w, .mods = .{ .super = true } },
|
||||
.{ .close_window = {} },
|
||||
.{ .key = .w, .mods = .{ .super = true, .shift = true } },
|
||||
.{ .close_surface = {} },
|
||||
);
|
||||
try result.keybind.set.put(
|
||||
alloc,
|
||||
|
||||
@@ -184,7 +184,11 @@ pub const Action = union(enum) {
|
||||
/// in the direction given.
|
||||
new_split: SplitDirection,
|
||||
|
||||
/// Close the current window or tab
|
||||
/// Close the current "surface", whether that is a window, tab, split,
|
||||
/// etc. This only closes ONE surface.
|
||||
close_surface: void,
|
||||
|
||||
/// Close the window, regardless of how many tabs or splits there may be.
|
||||
close_window: void,
|
||||
|
||||
/// Quit ghostty
|
||||
|
||||
Reference in New Issue
Block a user