mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
Don't crash on huge padding, warn users if padding is absurd
This commit is contained in:
@ -581,6 +581,14 @@ fn sizeCallback(window: glfw.Window, width: i32, height: i32) void {
|
||||
|
||||
// Recalculate our grid size
|
||||
win.grid_size = win.renderer.gridSize(screen_size);
|
||||
if (win.grid_size.columns < 5 and (win.padding.left > 0 or win.padding.right > 0)) {
|
||||
log.warn("WARNING: very small terminal grid detected with padding " ++
|
||||
"set. Is your padding reasonable?", .{});
|
||||
}
|
||||
if (win.grid_size.rows < 2 and (win.padding.top > 0 or win.padding.bottom > 0)) {
|
||||
log.warn("WARNING: very small terminal grid detected with padding " ++
|
||||
"set. Is your padding reasonable?", .{});
|
||||
}
|
||||
|
||||
// Mail the IO thread
|
||||
_ = win.io_thread.mailbox.push(.{
|
||||
|
@ -93,6 +93,11 @@ pub const Config = struct {
|
||||
/// the window border. The "x" option applies to the left and right
|
||||
/// padding and the "y" option is top and bottom. The value is in points,
|
||||
/// meaning that it will be scaled appropriately for screen DPI.
|
||||
///
|
||||
/// If this value is set too large, the screen will render nothing, because
|
||||
/// the grid will be completely squished by the padding. It is up to you
|
||||
/// as the user to pick a reasonable value. If you pick an unreasonable
|
||||
/// value, a warning will appear in the logs.
|
||||
@"window-padding-x": u32 = 0,
|
||||
@"window-padding-y": u32 = 0,
|
||||
|
||||
|
@ -48,8 +48,8 @@ pub const ScreenSize = struct {
|
||||
/// Subtract padding from the screen size.
|
||||
pub fn subPadding(self: ScreenSize, padding: Padding) ScreenSize {
|
||||
return .{
|
||||
.width = self.width - @floatToInt(u32, padding.left + padding.right),
|
||||
.height = self.height - @floatToInt(u32, padding.top + padding.bottom),
|
||||
.width = self.width -| @floatToInt(u32, padding.left + padding.right),
|
||||
.height = self.height -| @floatToInt(u32, padding.top + padding.bottom),
|
||||
};
|
||||
}
|
||||
};
|
||||
@ -71,8 +71,8 @@ pub const GridSize = struct {
|
||||
/// Update the columns/rows for the grid based on the given screen and
|
||||
/// cell size.
|
||||
pub fn update(self: *GridSize, screen: ScreenSize, cell: CellSize) void {
|
||||
self.columns = @floatToInt(Unit, @intToFloat(f32, screen.width) / cell.width);
|
||||
self.rows = @floatToInt(Unit, @intToFloat(f32, screen.height) / cell.height);
|
||||
self.columns = @max(1, @floatToInt(Unit, @intToFloat(f32, screen.width) / cell.width));
|
||||
self.rows = @max(1, @floatToInt(Unit, @intToFloat(f32, screen.height) / cell.height));
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user