mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
core: font size changes work
This commit is contained in:
@ -642,8 +642,6 @@ pub fn handleMessage(self: *Surface, msg: Message) !void {
|
|||||||
try self.rt_surface.setMouseShape(shape);
|
try self.rt_surface.setMouseShape(shape);
|
||||||
},
|
},
|
||||||
|
|
||||||
.cell_size => |size| try self.setCellSize(size),
|
|
||||||
|
|
||||||
.clipboard_read => |clipboard| {
|
.clipboard_read => |clipboard| {
|
||||||
if (self.config.clipboard_read == .deny) {
|
if (self.config.clipboard_read == .deny) {
|
||||||
log.info("application attempted to read clipboard, but 'clipboard-read' is set to deny", .{});
|
log.info("application attempted to read clipboard, but 'clipboard-read' is set to deny", .{});
|
||||||
@ -966,18 +964,25 @@ fn setCellSize(self: *Surface, size: renderer.CellSize) !void {
|
|||||||
/// Change the font size.
|
/// Change the font size.
|
||||||
///
|
///
|
||||||
/// This can only be called from the main thread.
|
/// This can only be called from the main thread.
|
||||||
pub fn setFontSize(self: *Surface, size: font.face.DesiredSize) void {
|
pub fn setFontSize(self: *Surface, 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;
|
||||||
|
|
||||||
// We need to build up a new font stack for this font size.
|
// We need to build up a new font stack for this font size.
|
||||||
const font_grid_key, const font_grid = self.app.font_grid_set.ref(
|
const font_grid_key, const font_grid = try self.app.font_grid_set.ref(
|
||||||
&self.config.font,
|
&self.config.font,
|
||||||
self.font_size,
|
self.font_size,
|
||||||
) catch unreachable;
|
);
|
||||||
errdefer self.app.font_grid_set.deref(font_grid_key);
|
errdefer self.app.font_grid_set.deref(font_grid_key);
|
||||||
|
|
||||||
// Notify our render thread of the new font stack
|
// Set our cell size
|
||||||
|
try self.setCellSize(.{
|
||||||
|
.width = font_grid.metrics.cell_width,
|
||||||
|
.height = font_grid.metrics.cell_height,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Notify our render thread of the new font stack. The renderer
|
||||||
|
// MUST accept the new font grid and deref the old.
|
||||||
_ = self.renderer_thread.mailbox.push(.{
|
_ = self.renderer_thread.mailbox.push(.{
|
||||||
.font_grid = .{
|
.font_grid = .{
|
||||||
.grid = font_grid,
|
.grid = font_grid,
|
||||||
@ -988,7 +993,6 @@ pub fn setFontSize(self: *Surface, size: font.face.DesiredSize) void {
|
|||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
|
|
||||||
// Once we've sent the key we can replace our key
|
// Once we've sent the key we can replace our key
|
||||||
// TODO(fontmem): we should not store this anymore
|
|
||||||
self.font_grid_key = font_grid_key;
|
self.font_grid_key = font_grid_key;
|
||||||
|
|
||||||
// Schedule render which also drains our mailbox
|
// Schedule render which also drains our mailbox
|
||||||
@ -1699,7 +1703,7 @@ pub fn contentScaleCallback(self: *Surface, content_scale: apprt.ContentScale) !
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.setFontSize(size);
|
try self.setFontSize(size);
|
||||||
|
|
||||||
// Update our padding which is dependent on DPI.
|
// Update our padding which is dependent on DPI.
|
||||||
self.padding = padding: {
|
self.padding = padding: {
|
||||||
@ -2998,7 +3002,7 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
|||||||
|
|
||||||
var size = self.font_size;
|
var size = self.font_size;
|
||||||
size.points +|= delta;
|
size.points +|= delta;
|
||||||
self.setFontSize(size);
|
try self.setFontSize(size);
|
||||||
},
|
},
|
||||||
|
|
||||||
.decrease_font_size => |delta| {
|
.decrease_font_size => |delta| {
|
||||||
@ -3006,7 +3010,7 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
|||||||
|
|
||||||
var size = self.font_size;
|
var size = self.font_size;
|
||||||
size.points = @max(1, size.points -| delta);
|
size.points = @max(1, size.points -| delta);
|
||||||
self.setFontSize(size);
|
try self.setFontSize(size);
|
||||||
},
|
},
|
||||||
|
|
||||||
.reset_font_size => {
|
.reset_font_size => {
|
||||||
@ -3014,7 +3018,7 @@ pub fn performBindingAction(self: *Surface, action: input.Binding.Action) !bool
|
|||||||
|
|
||||||
var size = self.font_size;
|
var size = self.font_size;
|
||||||
size.points = self.config.original_font_size;
|
size.points = self.config.original_font_size;
|
||||||
self.setFontSize(size);
|
try self.setFontSize(size);
|
||||||
},
|
},
|
||||||
|
|
||||||
.clear_screen => {
|
.clear_screen => {
|
||||||
|
@ -246,7 +246,7 @@ pub const App = struct {
|
|||||||
// If we have a parent, inherit some properties
|
// If we have a parent, inherit some properties
|
||||||
if (self.config.@"window-inherit-font-size") {
|
if (self.config.@"window-inherit-font-size") {
|
||||||
if (parent_) |parent| {
|
if (parent_) |parent| {
|
||||||
surface.core_surface.setFontSize(parent.font_size);
|
try surface.core_surface.setFontSize(parent.font_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,6 @@ pub const Message = union(enum) {
|
|||||||
/// Set the mouse shape.
|
/// Set the mouse shape.
|
||||||
set_mouse_shape: terminal.MouseShape,
|
set_mouse_shape: terminal.MouseShape,
|
||||||
|
|
||||||
/// Change the cell size.
|
|
||||||
cell_size: renderer.CellSize,
|
|
||||||
|
|
||||||
/// Read the clipboard and write to the pty.
|
/// Read the clipboard and write to the pty.
|
||||||
clipboard_read: apprt.Clipboard,
|
clipboard_read: apprt.Clipboard,
|
||||||
|
|
||||||
|
@ -566,18 +566,16 @@ pub fn setFocus(self: *Metal, focus: bool) !void {
|
|||||||
/// Set the new font size.
|
/// Set the new font size.
|
||||||
///
|
///
|
||||||
/// Must be called on the render thread.
|
/// Must be called on the render thread.
|
||||||
pub fn setFontGrid(self: *Metal, grid: *font.SharedGrid) !void {
|
pub fn setFontGrid(self: *Metal, grid: *font.SharedGrid) void {
|
||||||
// Update our grid
|
// Update our grid
|
||||||
self.font_grid = grid;
|
self.font_grid = grid;
|
||||||
self.texture_greyscale_modified = 0;
|
self.texture_greyscale_modified = 0;
|
||||||
self.texture_color_modified = 0;
|
self.texture_color_modified = 0;
|
||||||
|
|
||||||
// Recalculate our metrics
|
// Get our metrics from the grid. This doesn't require a lock because
|
||||||
const metrics = metrics: {
|
// the metrics are never recalculated.
|
||||||
grid.lock.lockShared();
|
const metrics = grid.metrics;
|
||||||
defer grid.lock.unlockShared();
|
self.grid_metrics = metrics;
|
||||||
break :metrics grid.metrics;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Update our uniforms
|
// Update our uniforms
|
||||||
self.uniforms = .{
|
self.uniforms = .{
|
||||||
@ -590,19 +588,6 @@ pub fn setFontGrid(self: *Metal, grid: *font.SharedGrid) !void {
|
|||||||
.strikethrough_thickness = @floatFromInt(metrics.strikethrough_thickness),
|
.strikethrough_thickness = @floatFromInt(metrics.strikethrough_thickness),
|
||||||
.min_contrast = self.uniforms.min_contrast,
|
.min_contrast = self.uniforms.min_contrast,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Recalculate our cell size. If it is the same as before, then we do
|
|
||||||
// nothing since the grid size couldn't have possibly changed.
|
|
||||||
if (std.meta.eql(self.grid_metrics, metrics)) return;
|
|
||||||
self.grid_metrics = metrics;
|
|
||||||
|
|
||||||
// Notify the window that the cell size changed.
|
|
||||||
_ = self.surface_mailbox.push(.{
|
|
||||||
.cell_size = .{
|
|
||||||
.width = metrics.cell_width,
|
|
||||||
.height = metrics.cell_height,
|
|
||||||
},
|
|
||||||
}, .{ .forever = {} });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the frame data.
|
/// Update the frame data.
|
||||||
|
@ -8,7 +8,7 @@ const Config = @import("../config.zig").Config;
|
|||||||
/// The derived configuration for this renderer implementation.
|
/// The derived configuration for this renderer implementation.
|
||||||
config: renderer.Renderer.DerivedConfig,
|
config: renderer.Renderer.DerivedConfig,
|
||||||
|
|
||||||
/// The font grid that should be used.
|
/// The font grid that should be used along with the key for deref-ing.
|
||||||
font_grid: *font.SharedGrid,
|
font_grid: *font.SharedGrid,
|
||||||
|
|
||||||
/// Padding options for the viewport.
|
/// Padding options for the viewport.
|
||||||
|
@ -321,13 +321,9 @@ fn drainMailbox(self: *Thread) !void {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
.font_grid => |grid| if (self.renderer.setFontGrid(grid.grid)) {
|
.font_grid => |grid| {
|
||||||
// Success, deref our old grid
|
self.renderer.setFontGrid(grid.grid);
|
||||||
grid.set.deref(grid.old_key);
|
grid.set.deref(grid.old_key);
|
||||||
} else |err| {
|
|
||||||
// Error, deref our new grid since we didn't use it.
|
|
||||||
grid.set.deref(grid.new_key);
|
|
||||||
return err;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
.foreground_color => |color| {
|
.foreground_color => |color| {
|
||||||
|
Reference in New Issue
Block a user