diff --git a/src/App.zig b/src/App.zig index 1a55538e2..a27e78ba0 100644 --- a/src/App.zig +++ b/src/App.zig @@ -11,6 +11,7 @@ const tracy = @import("tracy"); const Config = @import("config.zig").Config; const BlockingQueue = @import("./blocking_queue.zig").BlockingQueue; const renderer = @import("renderer.zig"); +const font = @import("font/main.zig"); const log = std.log.scoped(.app); @@ -55,7 +56,7 @@ pub fn create(alloc: Allocator, config: *const Config) !*App { errdefer app.windows.deinit(alloc); // Create the first window - try app.newWindow(); + try app.newWindow(.{}); return app; } @@ -108,7 +109,7 @@ fn drainMailbox(self: *App) !void { while (drain.next()) |message| { log.debug("mailbox message={s}", .{@tagName(message)}); switch (message) { - .new_window => try self.newWindow(), + .new_window => |msg| try self.newWindow(msg), .quit => try self.setQuit(), .window_message => |msg| try self.windowMessage(msg.window, msg.message), } @@ -116,11 +117,14 @@ fn drainMailbox(self: *App) !void { } /// Create a new window -fn newWindow(self: *App) !void { +fn newWindow(self: *App, msg: Message.NewWindow) !void { var window = try Window.create(self.alloc, self, self.config); errdefer window.destroy(); try self.windows.append(self.alloc, window); errdefer _ = self.windows.pop(); + + // Set initial font size if given + if (msg.font_size) |size| window.setFontSize(size); } /// Start quitting @@ -153,7 +157,7 @@ fn windowMessage(self: *App, win: *Window, msg: Window.Message) !void { /// The message types that can be sent to the app thread. pub const Message = union(enum) { /// Create a new terminal window. - new_window: void, + new_window: NewWindow, /// Quit quit: void, @@ -163,4 +167,10 @@ pub const Message = union(enum) { window: *Window, message: Window.Message, }, + + const NewWindow = struct { + /// The font size to create the window with or null to default to + /// the configuration amount. + font_size: ?font.face.DesiredSize = null, + }; }; diff --git a/src/Window.zig b/src/Window.zig index 7e26fad68..affafad21 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -558,7 +558,9 @@ fn setCellSize(self: *Window, size: renderer.CellSize) !void { } /// Change the font size. -fn setFontSize(self: *Window, size: font.face.DesiredSize) void { +/// +/// This can only be called from the main thread. +pub fn setFontSize(self: *Window, size: font.face.DesiredSize) void { // Update our font size so future changes work self.font_size = size; @@ -917,7 +919,12 @@ fn keyCallback( .new_window => { _ = win.app.mailbox.push(.{ - .new_window = {}, + .new_window = .{ + .font_size = if (win.config.@"window-inherit-font-size") + win.font_size + else + null, + }, }, .{ .instant = {} }); win.app.wakeup(); }, diff --git a/src/config.zig b/src/config.zig index 2d94fc42c..74b5e93d3 100644 --- a/src/config.zig +++ b/src/config.zig @@ -115,6 +115,12 @@ pub const Config = struct { /// to balance the padding given a certain viewport size and grid cell size. @"window-padding-balance": bool = true, + /// If true, new windows will inherit the font size of the previously + /// focused window. If no window was previously focused, the default + /// font size will be used. If this is false, the default font size + /// specified in the configuration "font-size" will be used. + @"window-inherit-font-size": bool = true, + /// Additional configuration files to read. @"config-file": RepeatableString = .{},