mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
Balance padding uses the explicit padding value for grid calculations
This fixes window resize not working properly when `window-padding-balance` is set to true.
This commit is contained in:
@ -411,11 +411,17 @@ pub fn init(
|
|||||||
},
|
},
|
||||||
|
|
||||||
.cell = font_grid.cellSize(),
|
.cell = font_grid.cellSize(),
|
||||||
.padding = derived_config.scaledPadding(x_dpi, y_dpi),
|
.padding = .{},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const explicit: renderer.Padding = derived_config.scaledPadding(
|
||||||
|
x_dpi,
|
||||||
|
y_dpi,
|
||||||
|
);
|
||||||
if (derived_config.window_padding_balance) {
|
if (derived_config.window_padding_balance) {
|
||||||
size.balancePadding();
|
size.balancePadding(explicit);
|
||||||
|
} else {
|
||||||
|
size.padding = explicit;
|
||||||
}
|
}
|
||||||
|
|
||||||
break :size size;
|
break :size size;
|
||||||
@ -1358,7 +1364,7 @@ fn setSelection(self: *Surface, sel_: ?terminal.Selection) !void {
|
|||||||
fn setCellSize(self: *Surface, size: renderer.CellSize) !void {
|
fn setCellSize(self: *Surface, size: renderer.CellSize) !void {
|
||||||
// Update our cell size within our size struct
|
// Update our cell size within our size struct
|
||||||
self.size.cell = size;
|
self.size.cell = size;
|
||||||
if (self.config.window_padding_balance) self.size.balancePadding();
|
self.balancePaddingIfNeeded();
|
||||||
|
|
||||||
// Notify the terminal
|
// Notify the terminal
|
||||||
self.io.queueMessage(.{ .resize = self.size }, .unlocked);
|
self.io.queueMessage(.{ .resize = self.size }, .unlocked);
|
||||||
@ -1440,7 +1446,7 @@ pub fn sizeCallback(self: *Surface, size: apprt.SurfaceSize) !void {
|
|||||||
fn resize(self: *Surface, size: renderer.ScreenSize) !void {
|
fn resize(self: *Surface, size: renderer.ScreenSize) !void {
|
||||||
// Save our screen size
|
// Save our screen size
|
||||||
self.size.screen = size;
|
self.size.screen = size;
|
||||||
if (self.config.window_padding_balance) self.size.balancePadding();
|
self.balancePaddingIfNeeded();
|
||||||
|
|
||||||
// Recalculate our grid size. Because Ghostty supports fluid resizing,
|
// Recalculate our grid size. Because Ghostty supports fluid resizing,
|
||||||
// its possible the grid doesn't change at all even if the screen size changes.
|
// its possible the grid doesn't change at all even if the screen size changes.
|
||||||
@ -1460,6 +1466,15 @@ fn resize(self: *Surface, size: renderer.ScreenSize) !void {
|
|||||||
self.io.queueMessage(.{ .resize = self.size }, .unlocked);
|
self.io.queueMessage(.{ .resize = self.size }, .unlocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Recalculate the balanced padding if needed.
|
||||||
|
fn balancePaddingIfNeeded(self: *Surface) void {
|
||||||
|
if (!self.config.window_padding_balance) return;
|
||||||
|
const content_scale = try self.rt_surface.getContentScale();
|
||||||
|
const x_dpi = content_scale.x * font.face.default_dpi;
|
||||||
|
const y_dpi = content_scale.y * font.face.default_dpi;
|
||||||
|
self.size.balancePadding(self.config.scaledPadding(x_dpi, y_dpi));
|
||||||
|
}
|
||||||
|
|
||||||
/// Called to set the preedit state for character input. Preedit is used
|
/// Called to set the preedit state for character input. Preedit is used
|
||||||
/// with dead key states, for example, when typing an accent character.
|
/// with dead key states, for example, when typing an accent character.
|
||||||
/// This should be called with null to reset the preedit state.
|
/// This should be called with null to reset the preedit state.
|
||||||
|
@ -31,9 +31,14 @@ pub const Size = struct {
|
|||||||
return self.screen.subPadding(self.padding);
|
return self.screen.subPadding(self.padding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the padding to be balanced around the grid. Overwrites the current
|
/// Set the padding to be balanced around the grid. The balanced
|
||||||
/// padding.
|
/// padding is calculated AFTER the explicit padding is taken
|
||||||
pub fn balancePadding(self: *Size) void {
|
/// into account.
|
||||||
|
pub fn balancePadding(self: *Size, explicit: Padding) void {
|
||||||
|
// This ensure grid() does the right thing
|
||||||
|
self.padding = explicit;
|
||||||
|
|
||||||
|
// Now we can calculate the balanced padding
|
||||||
self.padding = Padding.balanced(
|
self.padding = Padding.balanced(
|
||||||
self.screen,
|
self.screen,
|
||||||
self.grid(),
|
self.grid(),
|
||||||
|
Reference in New Issue
Block a user