mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-04 17:06:33 +00:00
Option (def true) to inherit font size on new window
This commit is contained in:
18
src/App.zig
18
src/App.zig
@@ -11,6 +11,7 @@ const tracy = @import("tracy");
|
|||||||
const Config = @import("config.zig").Config;
|
const Config = @import("config.zig").Config;
|
||||||
const BlockingQueue = @import("./blocking_queue.zig").BlockingQueue;
|
const BlockingQueue = @import("./blocking_queue.zig").BlockingQueue;
|
||||||
const renderer = @import("renderer.zig");
|
const renderer = @import("renderer.zig");
|
||||||
|
const font = @import("font/main.zig");
|
||||||
|
|
||||||
const log = std.log.scoped(.app);
|
const log = std.log.scoped(.app);
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ pub fn create(alloc: Allocator, config: *const Config) !*App {
|
|||||||
errdefer app.windows.deinit(alloc);
|
errdefer app.windows.deinit(alloc);
|
||||||
|
|
||||||
// Create the first window
|
// Create the first window
|
||||||
try app.newWindow();
|
try app.newWindow(.{});
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
@@ -108,7 +109,7 @@ fn drainMailbox(self: *App) !void {
|
|||||||
while (drain.next()) |message| {
|
while (drain.next()) |message| {
|
||||||
log.debug("mailbox message={s}", .{@tagName(message)});
|
log.debug("mailbox message={s}", .{@tagName(message)});
|
||||||
switch (message) {
|
switch (message) {
|
||||||
.new_window => try self.newWindow(),
|
.new_window => |msg| try self.newWindow(msg),
|
||||||
.quit => try self.setQuit(),
|
.quit => try self.setQuit(),
|
||||||
.window_message => |msg| try self.windowMessage(msg.window, msg.message),
|
.window_message => |msg| try self.windowMessage(msg.window, msg.message),
|
||||||
}
|
}
|
||||||
@@ -116,11 +117,14 @@ fn drainMailbox(self: *App) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new window
|
/// 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);
|
var window = try Window.create(self.alloc, self, self.config);
|
||||||
errdefer window.destroy();
|
errdefer window.destroy();
|
||||||
try self.windows.append(self.alloc, window);
|
try self.windows.append(self.alloc, window);
|
||||||
errdefer _ = self.windows.pop();
|
errdefer _ = self.windows.pop();
|
||||||
|
|
||||||
|
// Set initial font size if given
|
||||||
|
if (msg.font_size) |size| window.setFontSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start quitting
|
/// 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.
|
/// The message types that can be sent to the app thread.
|
||||||
pub const Message = union(enum) {
|
pub const Message = union(enum) {
|
||||||
/// Create a new terminal window.
|
/// Create a new terminal window.
|
||||||
new_window: void,
|
new_window: NewWindow,
|
||||||
|
|
||||||
/// Quit
|
/// Quit
|
||||||
quit: void,
|
quit: void,
|
||||||
@@ -163,4 +167,10 @@ pub const Message = union(enum) {
|
|||||||
window: *Window,
|
window: *Window,
|
||||||
message: Window.Message,
|
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,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
@@ -558,7 +558,9 @@ fn setCellSize(self: *Window, size: renderer.CellSize) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Change the font size.
|
/// 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
|
// Update our font size so future changes work
|
||||||
self.font_size = size;
|
self.font_size = size;
|
||||||
|
|
||||||
@@ -917,7 +919,12 @@ fn keyCallback(
|
|||||||
|
|
||||||
.new_window => {
|
.new_window => {
|
||||||
_ = win.app.mailbox.push(.{
|
_ = win.app.mailbox.push(.{
|
||||||
.new_window = {},
|
.new_window = .{
|
||||||
|
.font_size = if (win.config.@"window-inherit-font-size")
|
||||||
|
win.font_size
|
||||||
|
else
|
||||||
|
null,
|
||||||
|
},
|
||||||
}, .{ .instant = {} });
|
}, .{ .instant = {} });
|
||||||
win.app.wakeup();
|
win.app.wakeup();
|
||||||
},
|
},
|
||||||
|
@@ -115,6 +115,12 @@ pub const Config = struct {
|
|||||||
/// to balance the padding given a certain viewport size and grid cell size.
|
/// to balance the padding given a certain viewport size and grid cell size.
|
||||||
@"window-padding-balance": bool = true,
|
@"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.
|
/// Additional configuration files to read.
|
||||||
@"config-file": RepeatableString = .{},
|
@"config-file": RepeatableString = .{},
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user