macos: set window resizeIncrements when cell size changes

The resizeIncrements property is only modified when the cell size of the
focused window changes. If two splits have the same cell size then the
property is not modified when focusing between the two splits.
This commit is contained in:
Gregory Anders
2023-10-24 21:18:40 -05:00
parent be46bea40f
commit 2ee80a52df
11 changed files with 67 additions and 31 deletions

View File

@@ -460,6 +460,9 @@ pub fn init(
.config = try DerivedConfig.init(alloc, config),
};
// Report initial cell size on surface creation
try rt_surface.setCellSize(cell_size.width, cell_size.height);
// Set a minimum size that is cols=10 h=4. This matches Mac's Terminal.app
// but is otherwise somewhat arbitrary.
try rt_surface.setSizeLimits(.{
@@ -896,6 +899,9 @@ fn setCellSize(self: *Surface, size: renderer.CellSize) !void {
},
}, .{ .forever = {} });
self.io_thread.wakeup.notify() catch {};
// Notify the window
try self.rt_surface.setCellSize(size.width, size.height);
}
/// Change the font size.

View File

@@ -98,6 +98,9 @@ pub const App = struct {
/// Render the inspector for the given surface.
render_inspector: ?*const fn (SurfaceUD) callconv(.C) void = null,
/// Called when the cell size changes.
set_cell_size: ?*const fn (SurfaceUD, u32, u32) callconv(.C) void = null,
};
/// Special values for the goto_tab callback.
@@ -818,6 +821,15 @@ pub const Surface = struct {
func(self.opts.userdata);
}
pub fn setCellSize(self: *const Surface, width: u32, height: u32) !void {
const func = self.app.opts.set_cell_size orelse {
log.info("runtime embedder does not support set_cell_size", .{});
return;
};
func(self.opts.userdata, width, height);
}
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;

View File

@@ -461,6 +461,13 @@ pub const Surface = struct {
self.window.setSize(.{ .width = width, .height = height });
}
/// Set the cell size. Unused by GLFW.
pub fn setCellSize(self: *const Surface, width: u32, height: u32) !void {
_ = self;
_ = width;
_ = height;
}
/// Set the size limits of the window.
/// Note: this interface is not good, we should redo it if we plan
/// to use this more. i.e. you can't set max width but no max height,

View File

@@ -374,6 +374,12 @@ pub fn setInitialWindowSize(self: *const Surface, width: u32, height: u32) !void
);
}
pub fn setCellSize(self: *const Surface, width: u32, height: u32) !void {
_ = self;
_ = width;
_ = height;
}
pub fn setSizeLimits(self: *Surface, min: apprt.SurfaceSize, max_: ?apprt.SurfaceSize) !void {
_ = self;
_ = min;