diff --git a/src/App.zig b/src/App.zig index 7986ed8d5..7776dc49d 100644 --- a/src/App.zig +++ b/src/App.zig @@ -144,14 +144,14 @@ fn newWindow(self: *App, rt_app: *apprt.App, msg: Message.NewWindow) !void { return; } - const window = try rt_app.newWindow(); - if (self.config.@"window-inherit-font-size") { - if (msg.parent) |parent| { - if (self.hasSurface(parent)) { - window.core_surface.setFontSize(parent.font_size); - } - } - } + const parent = if (msg.parent) |parent| parent: { + break :parent if (self.hasSurface(parent)) + parent + else + null; + } else null; + + try rt_app.newWindow(parent); } /// Create a new tab in the parent window @@ -172,8 +172,7 @@ fn newTab(self: *App, rt_app: *apprt.App, msg: Message.NewTab) !void { return; } - const window = try rt_app.newTab(parent); - if (self.config.@"window-inherit-font-size") window.core_surface.setFontSize(parent.font_size); + try rt_app.newTab(parent); } /// Start quitting diff --git a/src/apprt/glfw.zig b/src/apprt/glfw.zig index 59c79dfa5..3faab933d 100644 --- a/src/apprt/glfw.zig +++ b/src/apprt/glfw.zig @@ -74,27 +74,19 @@ pub const App = struct { } /// Create a new window for the app. - pub fn newWindow(self: *App) !*Surface { - // Grab a surface allocation because we're going to need it. - var surface = try self.app.alloc.create(Surface); - errdefer self.app.alloc.destroy(surface); - - // Create the surface -- because windows are surfaces for glfw. - try surface.init(self); - errdefer surface.deinit(); - - return surface; + pub fn newWindow(self: *App, parent_: ?*CoreSurface) !void { + _ = try self.newSurface(parent_); } /// Create a new tab in the parent surface. - pub fn newTab(self: *App, parent: *CoreSurface) !*Surface { + pub fn newTab(self: *App, parent: *CoreSurface) !void { if (!Darwin.enabled) { log.warn("tabbing is not supported on this platform", .{}); - return error.TabbingNotSupported; + return; } // Create the new window - const window = try self.newWindow(); + const window = try self.newWindow(parent); // Add the new window the parent window const parent_win = glfwNative.getCocoaWindow(parent.rt_surface.window).?; @@ -112,14 +104,31 @@ pub const App = struct { // point in the grid. const size = parent.rt_surface.getSize() catch |err| { log.err("error querying window size for size callback on new tab err={}", .{err}); - return window; + return; }; parent.sizeCallback(size) catch |err| { log.err("error in size callback from new tab err={}", .{err}); - return window; + return; }; + } - return window; + fn newSurface(self: *App, parent_: ?*CoreSurface) !*Surface { + // Grab a surface allocation because we're going to need it. + var surface = try self.app.alloc.create(Surface); + errdefer self.app.alloc.destroy(surface); + + // Create the surface -- because windows are surfaces for glfw. + try surface.init(self); + errdefer surface.deinit(); + + // If we have a parent, inherit some properties + if (self.app.config.@"window-inherit-font-size") { + if (parent_) |parent| { + surface.core_surface.setFontSize(parent.font_size); + } + } + + return surface; } /// Close the given surface. diff --git a/src/main.zig b/src/main.zig index 143fa0cca..52447f456 100644 --- a/src/main.zig +++ b/src/main.zig @@ -99,7 +99,7 @@ pub fn main() !void { defer app_runtime.terminate(); // Create an initial window - _ = try app_runtime.newWindow(); + try app_runtime.newWindow(null); // Run the GUI event loop try app_runtime.run();