Implement asymmetric window padding.

Add `window-padding-top`, `window-padding-bottom`,
`window-padding-left`, and `window-padding-right` options. The
`window-padding-x` and `window-padding-y` options will override the
individual options.
This commit is contained in:
Jeffrey C. Ollie
2024-08-03 14:36:06 -05:00
parent 288a1fe549
commit 0f27fc2a0d
3 changed files with 140 additions and 31 deletions

View File

@ -217,8 +217,10 @@ const DerivedConfig = struct {
macos_non_native_fullscreen: configpkg.NonNativeFullscreen, macos_non_native_fullscreen: configpkg.NonNativeFullscreen,
macos_option_as_alt: configpkg.OptionAsAlt, macos_option_as_alt: configpkg.OptionAsAlt,
vt_kam_allowed: bool, vt_kam_allowed: bool,
window_padding_x: u32, window_padding_top: u32,
window_padding_y: u32, window_padding_bottom: u32,
window_padding_left: u32,
window_padding_right: u32,
window_padding_balance: bool, window_padding_balance: bool,
title: ?[:0]const u8, title: ?[:0]const u8,
links: []Link, links: []Link,
@ -275,8 +277,10 @@ const DerivedConfig = struct {
.macos_non_native_fullscreen = config.@"macos-non-native-fullscreen", .macos_non_native_fullscreen = config.@"macos-non-native-fullscreen",
.macos_option_as_alt = config.@"macos-option-as-alt", .macos_option_as_alt = config.@"macos-option-as-alt",
.vt_kam_allowed = config.@"vt-kam-allowed", .vt_kam_allowed = config.@"vt-kam-allowed",
.window_padding_x = config.@"window-padding-x", .window_padding_top = config.@"window-padding-y" orelse config.@"window-padding-top",
.window_padding_y = config.@"window-padding-y", .window_padding_bottom = config.@"window-padding-y" orelse config.@"window-padding-bottom",
.window_padding_left = config.@"window-padding-x" orelse config.@"window-padding-left",
.window_padding_right = config.@"window-padding-x" orelse config.@"window-padding-right",
.window_padding_balance = config.@"window-padding-balance", .window_padding_balance = config.@"window-padding-balance",
.title = config.title, .title = config.title,
.links = links, .links = links,
@ -341,19 +345,27 @@ pub fn init(
const cell_size = font_grid.cellSize(); const cell_size = font_grid.cellSize();
// Convert our padding from points to pixels // Convert our padding from points to pixels
const padding_x: u32 = padding_x: { const padding_top: u32 = padding_top: {
const padding_x: f32 = @floatFromInt(config.@"window-padding-x"); const padding_top: f32 = @floatFromInt(config.@"window-padding-y" orelse config.@"window-padding-top");
break :padding_x @intFromFloat(@floor(padding_x * x_dpi / 72)); break :padding_top @intFromFloat(@floor(padding_top * y_dpi / 72));
}; };
const padding_y: u32 = padding_y: { const padding_bottom: u32 = padding_bottom: {
const padding_y: f32 = @floatFromInt(config.@"window-padding-y"); const padding_bottom: f32 = @floatFromInt(config.@"window-padding-y" orelse config.@"window-padding-bottom");
break :padding_y @intFromFloat(@floor(padding_y * y_dpi / 72)); break :padding_bottom @intFromFloat(@floor(padding_bottom * y_dpi / 72));
};
const padding_left: u32 = padding_left: {
const padding_left: f32 = @floatFromInt(config.@"window-padding-x" orelse config.@"window-padding-left");
break :padding_left @intFromFloat(@floor(padding_left * x_dpi / 72));
};
const padding_right: u32 = padding_right: {
const padding_right: f32 = @floatFromInt(config.@"window-padding-y" orelse config.@"window-padding-right");
break :padding_right @intFromFloat(@floor(padding_right * x_dpi / 72));
}; };
const padding: renderer.Padding = .{ const padding: renderer.Padding = .{
.top = padding_y, .top = padding_top,
.bottom = padding_y, .bottom = padding_bottom,
.right = padding_x, .left = padding_left,
.left = padding_x, .right = padding_right,
}; };
// Create our terminal grid with the initial size // Create our terminal grid with the initial size
@ -1825,20 +1837,28 @@ pub fn contentScaleCallback(self: *Surface, content_scale: apprt.ContentScale) !
// Update our padding which is dependent on DPI. // Update our padding which is dependent on DPI.
self.padding = padding: { self.padding = padding: {
const padding_x: u32 = padding_x: { const padding_top: u32 = padding_top: {
const padding_x: f32 = @floatFromInt(self.config.window_padding_x); const padding_top: f32 = @floatFromInt(self.config.window_padding_top);
break :padding_x @intFromFloat(@floor(padding_x * x_dpi / 72)); break :padding_top @intFromFloat(@floor(padding_top * y_dpi / 72));
}; };
const padding_y: u32 = padding_y: { const padding_bottom: u32 = padding_bottom: {
const padding_y: f32 = @floatFromInt(self.config.window_padding_y); const padding_bottom: f32 = @floatFromInt(self.config.window_padding_bottom);
break :padding_y @intFromFloat(@floor(padding_y * y_dpi / 72)); break :padding_bottom @intFromFloat(@floor(padding_bottom * y_dpi / 72));
};
const padding_left: u32 = padding_left: {
const padding_left: f32 = @floatFromInt(self.config.window_padding_left);
break :padding_left @intFromFloat(@floor(padding_left * x_dpi / 72));
};
const padding_right: u32 = padding_right: {
const padding_right: f32 = @floatFromInt(self.config.window_padding_right);
break :padding_right @intFromFloat(@floor(padding_right * x_dpi / 72));
}; };
break :padding .{ break :padding .{
.top = padding_y, .top = padding_top,
.bottom = padding_y, .bottom = padding_bottom,
.right = padding_x, .left = padding_left,
.left = padding_x, .right = padding_right,
}; };
}; };

View File

@ -12,7 +12,7 @@ pub const fish_completions = comptimeGenerateFishCompletions();
fn comptimeGenerateFishCompletions() []const u8 { fn comptimeGenerateFishCompletions() []const u8 {
comptime { comptime {
@setEvalBranchQuota(15000); @setEvalBranchQuota(16000);
var counter = std.io.countingWriter(std.io.null_writer); var counter = std.io.countingWriter(std.io.null_writer);
try writeFishCompletions(&counter.writer()); try writeFishCompletions(&counter.writer());

View File

@ -640,10 +640,27 @@ class: ?[:0]const u8 = null,
/// "unconsumed:ctrl+a=reload_config" /// "unconsumed:ctrl+a=reload_config"
keybind: Keybinds = .{}, keybind: Keybinds = .{},
/// Window padding. This applies padding between the terminal cells and the /// Horizontal window padding. This applies padding between the terminal cells
/// window border. The `x` option applies to the left and right padding and the /// and the left and right window borders. The value is in points, meaning that
/// `y` option is top and bottom. The value is in points, meaning that it will /// it will be scaled appropriately for screen DPI.
/// 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.
///
/// Changing this configuration at runtime will only affect new terminals, i.e.
/// new windows, tabs, etc.
///
/// If this value is set, the value of `window-padding-left` and
/// `window-padding-right` will have no effect.
///
/// By default, this value is unset.
@"window-padding-x": ?u32 = null,
/// Vertical window padding. This applies padding between the terminal cells and
/// the top and bottom window borders. 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 /// 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 /// grid will be completely squished by the padding. It is up to you as the user
@ -652,8 +669,80 @@ keybind: Keybinds = .{},
/// ///
/// Changing this configuration at runtime will only affect new terminals, /// Changing this configuration at runtime will only affect new terminals,
/// i.e. new windows, tabs, etc. /// i.e. new windows, tabs, etc.
@"window-padding-x": u32 = 2, ///
@"window-padding-y": u32 = 2, /// If this value is set, the value of `window-padding-top` and
/// `window-padding-bottom` will have no effect.
///
/// By default, this value is unset.
@"window-padding-y": ?u32 = null,
/// Top window padding. This applies padding between the terminal cells and the
/// top window border. 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.
///
/// Changing this configuration at runtime will only affect new terminals,
/// i.e. new windows, tabs, etc.
///
/// If `window-padding-y` is set, this value will be ignored.
///
/// This value is set to 2 by default.
@"window-padding-top": u32 = 2,
/// Bottom window padding. This applies padding between the terminal cells and
/// the bottom window border. 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.
///
/// Changing this configuration at runtime will only affect new terminals,
/// i.e. new windows, tabs, etc.
///
/// If `window-padding-y` is set, this value will be ignored.
///
/// This value is set to 2 by default.
@"window-padding-bottom": u32 = 2,
/// Left window padding. This applies padding between the terminal cells and the
/// left window border. 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.
///
/// Changing this configuration at runtime will only affect new terminals,
/// i.e. new windows, tabs, etc.
///
/// If `window-padding-x` is set, this value will be ignored.
///
/// This value is set to 2 by default.
@"window-padding-left": u32 = 2,
/// Right window padding. This applies padding between the terminal cells and
/// the right window border. 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.
///
/// Changing this configuration at runtime will only affect new terminals,
/// i.e. new windows, tabs, etc.
///
/// If `window-padding-x` is set, this value will be ignored.
///
/// This value is set to 2 by default.
@"window-padding-right": u32 = 2,
/// The viewport dimensions are usually not perfectly divisible by the cell /// The viewport dimensions are usually not perfectly divisible by the cell
/// size. In this case, some extra padding on the end of a column and the bottom /// size. In this case, some extra padding on the end of a column and the bottom