mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
renderer/opengl: support window-padding-color=extend
This commit is contained in:
@ -138,10 +138,11 @@ const SetScreenSize = struct {
|
|||||||
return error.OpenGLUninitialized;
|
return error.OpenGLUninitialized;
|
||||||
|
|
||||||
// Apply our padding
|
// Apply our padding
|
||||||
|
const grid_size = r.gridSize(self.size);
|
||||||
const padding = if (r.padding.balance)
|
const padding = if (r.padding.balance)
|
||||||
renderer.Padding.balanced(
|
renderer.Padding.balanced(
|
||||||
self.size,
|
self.size,
|
||||||
r.gridSize(self.size),
|
grid_size,
|
||||||
.{
|
.{
|
||||||
.width = r.grid_metrics.cell_width,
|
.width = r.grid_metrics.cell_width,
|
||||||
.height = r.grid_metrics.cell_height,
|
.height = r.grid_metrics.cell_height,
|
||||||
@ -151,6 +152,18 @@ const SetScreenSize = struct {
|
|||||||
r.padding.explicit;
|
r.padding.explicit;
|
||||||
const padded_size = self.size.subPadding(padding);
|
const padded_size = self.size.subPadding(padding);
|
||||||
|
|
||||||
|
// Blank space around the grid.
|
||||||
|
const blank: renderer.Padding = switch (r.config.padding_color) {
|
||||||
|
// We can use zero padding because the backgroudn color is our
|
||||||
|
// clear color.
|
||||||
|
.background => .{},
|
||||||
|
|
||||||
|
.extend => self.size.blankPadding(padding, grid_size, .{
|
||||||
|
.width = r.grid_metrics.cell_width,
|
||||||
|
.height = r.grid_metrics.cell_height,
|
||||||
|
}).add(padding),
|
||||||
|
};
|
||||||
|
|
||||||
log.debug("GL api: screen size padded={} screen={} grid={} cell={} padding={}", .{
|
log.debug("GL api: screen size padded={} screen={} grid={} cell={} padding={}", .{
|
||||||
padded_size,
|
padded_size,
|
||||||
self.size,
|
self.size,
|
||||||
@ -189,6 +202,29 @@ const SetScreenSize = struct {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup our grid padding
|
||||||
|
{
|
||||||
|
const program = gl_state.cell_program;
|
||||||
|
const bind = try program.program.use();
|
||||||
|
defer bind.unbind();
|
||||||
|
try program.program.setUniform(
|
||||||
|
"grid_padding",
|
||||||
|
@Vector(4, f32){
|
||||||
|
@floatFromInt(blank.top),
|
||||||
|
@floatFromInt(blank.right),
|
||||||
|
@floatFromInt(blank.bottom),
|
||||||
|
@floatFromInt(blank.left),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
try program.program.setUniform(
|
||||||
|
"grid_size",
|
||||||
|
@Vector(2, f32){
|
||||||
|
@floatFromInt(grid_size.columns),
|
||||||
|
@floatFromInt(grid_size.rows),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Update our custom shader resolution
|
// Update our custom shader resolution
|
||||||
if (gl_state.custom) |*custom_state| {
|
if (gl_state.custom) |*custom_state| {
|
||||||
try custom_state.setScreenSize(self.size);
|
try custom_state.setScreenSize(self.size);
|
||||||
@ -252,6 +288,7 @@ pub const DerivedConfig = struct {
|
|||||||
invert_selection_fg_bg: bool,
|
invert_selection_fg_bg: bool,
|
||||||
bold_is_bright: bool,
|
bold_is_bright: bool,
|
||||||
min_contrast: f32,
|
min_contrast: f32,
|
||||||
|
padding_color: configpkg.WindowPaddingColor,
|
||||||
custom_shaders: std.ArrayListUnmanaged([:0]const u8),
|
custom_shaders: std.ArrayListUnmanaged([:0]const u8),
|
||||||
links: link.Set,
|
links: link.Set,
|
||||||
|
|
||||||
@ -308,6 +345,7 @@ pub const DerivedConfig = struct {
|
|||||||
.invert_selection_fg_bg = config.@"selection-invert-fg-bg",
|
.invert_selection_fg_bg = config.@"selection-invert-fg-bg",
|
||||||
.bold_is_bright = config.@"bold-is-bright",
|
.bold_is_bright = config.@"bold-is-bright",
|
||||||
.min_contrast = @floatCast(config.@"minimum-contrast"),
|
.min_contrast = @floatCast(config.@"minimum-contrast"),
|
||||||
|
.padding_color = config.@"window-padding-color",
|
||||||
|
|
||||||
.selection_background = if (config.@"selection-background") |bg|
|
.selection_background = if (config.@"selection-background") |bg|
|
||||||
bg.toTerminalRGB()
|
bg.toTerminalRGB()
|
||||||
|
@ -55,6 +55,8 @@ flat out uint mode;
|
|||||||
uniform sampler2D text;
|
uniform sampler2D text;
|
||||||
uniform sampler2D text_color;
|
uniform sampler2D text_color;
|
||||||
uniform vec2 cell_size;
|
uniform vec2 cell_size;
|
||||||
|
uniform vec2 grid_size;
|
||||||
|
uniform vec4 grid_padding;
|
||||||
uniform mat4 projection;
|
uniform mat4 projection;
|
||||||
uniform float min_contrast;
|
uniform float min_contrast;
|
||||||
|
|
||||||
@ -167,6 +169,21 @@ void main() {
|
|||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case MODE_BG:
|
case MODE_BG:
|
||||||
|
// If we're at the edge of the grid, we add our padding to the background
|
||||||
|
// to extend it. Note: grid_padding is top/right/bottom/left.
|
||||||
|
if (grid_coord.y == 0) {
|
||||||
|
cell_pos.y -= grid_padding.r;
|
||||||
|
cell_size_scaled.y += grid_padding.r;
|
||||||
|
} else if (grid_coord.y == grid_size.y - 1) {
|
||||||
|
cell_size_scaled.y += grid_padding.b;
|
||||||
|
}
|
||||||
|
if (grid_coord.x == 0) {
|
||||||
|
cell_pos.x -= grid_padding.a;
|
||||||
|
cell_size_scaled.x += grid_padding.a;
|
||||||
|
} else if (grid_coord.x == grid_size.x - 1) {
|
||||||
|
cell_size_scaled.x += grid_padding.g;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate the final position of our cell in world space.
|
// Calculate the final position of our cell in world space.
|
||||||
// We have to add our cell size since our vertices are offset
|
// We have to add our cell size since our vertices are offset
|
||||||
// one cell up and to the left. (Do the math to verify yourself)
|
// one cell up and to the left. (Do the math to verify yourself)
|
||||||
|
Reference in New Issue
Block a user