From f2b59353ab9732f3badb2fef18ef4ab02f6328d2 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 26 Jan 2023 08:54:09 -0800 Subject: [PATCH] window (mac): recalculate sizes on new tab When a new tab is added, the tab bar may appear which causes our size grid size calculation to become invalidated. We weren't updating this previously, which had the effect of mouse selection being in the wrong place. There were likely other effects... Fixes https://github.com/mitchellh/ghostty/issues/69 --- src/Window.zig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Window.zig b/src/Window.zig index 4e88fb77e..254b8766d 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -492,7 +492,7 @@ pub fn shouldClose(self: Window) bool { } /// Add a window to the tab group of this window. -pub fn addWindow(self: Window, other: *Window) void { +pub fn addWindow(self: *Window, other: *Window) void { assert(builtin.target.isDarwin()); // This has a hard dependency on GLFW currently. If we want to support @@ -507,6 +507,19 @@ pub fn addWindow(self: Window, other: *Window) void { objc.Object.fromId(other_win), NSWindowOrderingMode.above, }); + + // Adding a new tab can cause the tab bar to appear which changes + // our viewport size. We need to call the size callback in order to + // update values. For example, we need this to set the proper mouse selection + // point in the grid. + const size = self.window.getSize() catch |err| { + log.err("error querying window size for size callback on new tab err={}", .{err}); + return; + }; + self.sizeCallback(size) catch |err| { + log.err("error in size callback from new tab err={}", .{err}); + return; + }; } /// Called from the app thread to handle mailbox messages to our specific