macOS: new window can inherit font size

This is the second part of #281 and adds the same mechanism that was
added for tabs in #296 for windows.

It works exactly the same way.
This commit is contained in:
Thorsten Ball
2023-08-19 09:29:56 +02:00
parent 0b6de6928c
commit 2e9b787668
8 changed files with 99 additions and 20 deletions

View File

@@ -2119,11 +2119,15 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !void
} else log.warn("dev mode was not compiled into this binary", .{}),
.new_window => {
_ = self.app_mailbox.push(.{
.new_window = .{
.parent = self,
},
}, .{ .instant = {} });
if (@hasDecl(apprt.Surface, "newWindow")) {
try self.rt_surface.newWindow();
} else {
_ = self.app_mailbox.push(.{
.new_window = .{
.parent = self,
},
}, .{ .instant = {} });
}
},
.new_tab => {

View File

@@ -62,6 +62,9 @@ pub const App = struct {
/// New tab with options.
new_tab: ?*const fn (SurfaceUD, apprt.Surface.Options) callconv(.C) void = null,
/// New window with options.
new_window: ?*const fn (SurfaceUD, apprt.Surface.Options) callconv(.C) void = null,
/// Close the current surface given by this function.
close_surface: ?*const fn (SurfaceUD, bool) callconv(.C) void = null,
@@ -615,14 +618,29 @@ pub const Surface = struct {
return;
};
const options = self.newSurfaceOptions();
func(self.opts.userdata, options);
}
pub fn newWindow(self: *const Surface) !void {
const func = self.app.opts.new_window orelse {
log.info("runtime embedder does not support new_window", .{});
return;
};
const options = self.newSurfaceOptions();
func(self.opts.userdata, options);
}
fn newSurfaceOptions(self: *const Surface) apprt.Surface.Options {
const font_size: u16 = font_size: {
if (!self.app.config.@"window-inherit-font-size") break :font_size 0;
break :font_size self.core_surface.font_size.points;
};
func(self.opts.userdata, .{
return .{
.font_size = font_size,
});
};
}
/// The cursor position from the host directly is in screen coordinates but
@@ -855,6 +873,7 @@ pub const CAPI = struct {
.copy_to_clipboard => .{ .copy_to_clipboard = {} },
.paste_from_clipboard => .{ .paste_from_clipboard = {} },
.new_tab => .{ .new_tab = {} },
.new_window => .{ .new_window = {} },
};
ptr.core_surface.performBindingAction(action) catch |err| {

View File

@@ -277,6 +277,7 @@ pub const Key = enum(c_int) {
copy_to_clipboard,
paste_from_clipboard,
new_tab,
new_window,
};
/// Trigger is the associated key state that can trigger an action.