From cff907940f357f7183088389500b792ed6da1569 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 22 Aug 2024 14:57:03 -0700 Subject: [PATCH] renderer: do not extend padding color if any cell has default bg color Before, cells that were explicitly set to match the default bg color were treated as if they did NOT have the default and extending would occur. We now check the exact RGB of each cell. --- src/renderer/Metal.zig | 10 ++++++++-- src/renderer/OpenGL.zig | 10 ++++++++-- src/terminal/PageList.zig | 22 ++++++++++++++++++---- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 6a17ee094..89666e7bb 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -2224,9 +2224,15 @@ fn rebuildCells( // Apply heuristics for padding extension. .extend => if (y == 0) { - self.uniforms.padding_extend.up = !row.neverExtendBg(); + self.uniforms.padding_extend.up = !row.neverExtendBg( + color_palette, + self.background_color, + ); } else if (y == self.cells.size.rows - 1) { - self.uniforms.padding_extend.down = !row.neverExtendBg(); + self.uniforms.padding_extend.down = !row.neverExtendBg( + color_palette, + self.background_color, + ); }, } diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index 7e5e140a1..d220cdadc 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -1296,9 +1296,15 @@ pub fn rebuildCells( // Apply heuristics for padding extension. .extend => if (y == 0) { - self.padding_extend_top = !row.neverExtendBg(); + self.padding_extend_top = !row.neverExtendBg( + color_palette, + self.background_color, + ); } else if (y == self.grid_size.rows - 1) { - self.padding_extend_bottom = !row.neverExtendBg(); + self.padding_extend_bottom = !row.neverExtendBg( + color_palette, + self.background_color, + ); }, } diff --git a/src/terminal/PageList.zig b/src/terminal/PageList.zig index de0a5665e..523b0e195 100644 --- a/src/terminal/PageList.zig +++ b/src/terminal/PageList.zig @@ -6,6 +6,7 @@ const PageList = @This(); const std = @import("std"); const Allocator = std.mem.Allocator; const assert = std.debug.assert; +const color = @import("color.zig"); const fastmem = @import("../fastmem.zig"); const kitty = @import("kitty.zig"); const point = @import("point.zig"); @@ -3238,7 +3239,11 @@ pub const Pin = struct { /// Returns true if the row of this pin should never have its background /// color extended for filling padding space in the renderer. This is /// a set of heuristics that help making our padding look better. - pub fn neverExtendBg(self: Pin) bool { + pub fn neverExtendBg( + self: Pin, + palette: *const color.Palette, + default_background: color.RGB, + ) bool { // Any semantic prompts should not have their background extended // because prompts often contain special formatting (such as // powerline) that looks bad when extended. @@ -3253,8 +3258,12 @@ pub const Pin = struct { // extend because the default background color probably looks // good enough as an extension. switch (cell.content_tag) { - // We assume bg color cells are setting non-default colors. - .bg_color_palette, .bg_color_rgb => {}, + // If it is a background color cell, we check the color. + .bg_color_palette, .bg_color_rgb => { + const s = self.style(cell); + const bg = s.bg(cell, palette) orelse return true; + if (bg.eql(default_background)) return true; + }, // If its a codepoint cell we can check the style. .codepoint, .codepoint_grapheme => { @@ -3272,8 +3281,13 @@ pub const Pin = struct { else => {}, } + // Never extend cell that has a default background. + // A default background is if there is no background + // on the style OR the explicitly set background + // matches our default background. const s = self.style(cell); - if (s.bg_color == .none) return true; + const bg = s.bg(cell, palette) orelse return true; + if (bg.eql(default_background)) return true; }, } }