apprt/embedded: close surface callback

This commit is contained in:
Mitchell Hashimoto
2023-03-08 15:05:15 -08:00
parent fa9ee0815f
commit 6c857877e8
8 changed files with 46 additions and 5 deletions

View File

@@ -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 = {} });
},

View File

@@ -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;
}

View File

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

View File

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