mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
renderer: some tweaks
This commit is contained in:
@ -631,7 +631,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
|
|||||||
.min_contrast = options.config.min_contrast,
|
.min_contrast = options.config.min_contrast,
|
||||||
.cursor_pos = .{ std.math.maxInt(u16), std.math.maxInt(u16) },
|
.cursor_pos = .{ std.math.maxInt(u16), std.math.maxInt(u16) },
|
||||||
.cursor_color = undefined,
|
.cursor_color = undefined,
|
||||||
.wide_cursor = false,
|
.cursor_wide = false,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Fonts
|
// Fonts
|
||||||
@ -2035,7 +2035,7 @@ pub fn setScreenSize(
|
|||||||
.min_contrast = old.min_contrast,
|
.min_contrast = old.min_contrast,
|
||||||
.cursor_pos = old.cursor_pos,
|
.cursor_pos = old.cursor_pos,
|
||||||
.cursor_color = old.cursor_color,
|
.cursor_color = old.cursor_color,
|
||||||
.wide_cursor = old.wide_cursor,
|
.cursor_wide = old.cursor_wide,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reset our cell contents if our grid size has changed.
|
// Reset our cell contents if our grid size has changed.
|
||||||
@ -2358,13 +2358,17 @@ fn rebuildCells(
|
|||||||
const wide = screen.cursor.page_cell.wide;
|
const wide = screen.cursor.page_cell.wide;
|
||||||
|
|
||||||
self.uniforms.cursor_pos = .{
|
self.uniforms.cursor_pos = .{
|
||||||
|
// If we are a spacer tail of a wide cell, our cursor needs
|
||||||
|
// to move back one cell. The saturate is to ensure we don't
|
||||||
|
// overflow but this shouldn't happen with well-formed input.
|
||||||
switch (wide) {
|
switch (wide) {
|
||||||
.narrow, .spacer_head, .wide => screen.cursor.x,
|
.narrow, .spacer_head, .wide => screen.cursor.x,
|
||||||
.spacer_tail => screen.cursor.x -| 1,
|
.spacer_tail => screen.cursor.x -| 1,
|
||||||
},
|
},
|
||||||
screen.cursor.y,
|
screen.cursor.y,
|
||||||
};
|
};
|
||||||
self.uniforms.wide_cursor = switch (wide) {
|
|
||||||
|
self.uniforms.cursor_wide = switch (wide) {
|
||||||
.narrow, .spacer_head => false,
|
.narrow, .spacer_head => false,
|
||||||
.wide, .spacer_tail => true,
|
.wide, .spacer_tail => true,
|
||||||
};
|
};
|
||||||
@ -2563,7 +2567,7 @@ fn updateCell(
|
|||||||
|
|
||||||
const color = style.underlineColor(palette) orelse colors.fg;
|
const color = style.underlineColor(palette) orelse colors.fg;
|
||||||
|
|
||||||
try self.cells.add(self.alloc, .underline, .{
|
var gpu_cell: mtl_cell.Key.underline.CellType() = .{
|
||||||
.mode = .fg,
|
.mode = .fg,
|
||||||
.grid_pos = .{ @intCast(coord.x), @intCast(coord.y) },
|
.grid_pos = .{ @intCast(coord.x), @intCast(coord.y) },
|
||||||
.constraint_width = 1,
|
.constraint_width = 1,
|
||||||
@ -2574,21 +2578,12 @@ fn updateCell(
|
|||||||
@intCast(render.glyph.offset_x),
|
@intCast(render.glyph.offset_x),
|
||||||
@intCast(render.glyph.offset_y),
|
@intCast(render.glyph.offset_y),
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
try self.cells.add(self.alloc, .underline, gpu_cell);
|
||||||
// If it's a wide cell we need to underline the right half as well.
|
// If it's a wide cell we need to underline the right half as well.
|
||||||
if (cell.gridWidth() > 1 and coord.x < self.cells.size.columns - 1) {
|
if (cell.gridWidth() > 1 and coord.x < self.cells.size.columns - 1) {
|
||||||
try self.cells.add(self.alloc, .underline, .{
|
gpu_cell.grid_pos[0] = @intCast(coord.x + 1);
|
||||||
.mode = .fg,
|
try self.cells.add(self.alloc, .underline, gpu_cell);
|
||||||
.grid_pos = .{ @intCast(coord.x + 1), @intCast(coord.y) },
|
|
||||||
.constraint_width = 1,
|
|
||||||
.color = .{ color.r, color.g, color.b, alpha },
|
|
||||||
.glyph_pos = .{ render.glyph.atlas_x, render.glyph.atlas_y },
|
|
||||||
.glyph_size = .{ render.glyph.width, render.glyph.height },
|
|
||||||
.bearings = .{
|
|
||||||
@intCast(render.glyph.offset_x),
|
|
||||||
@intCast(render.glyph.offset_y),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2646,7 +2641,7 @@ fn updateCell(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
try self.cells.add(self.alloc, .strikethrough, .{
|
var gpu_cell: mtl_cell.Key.strikethrough.CellType() = .{
|
||||||
.mode = .fg,
|
.mode = .fg,
|
||||||
.grid_pos = .{ @intCast(coord.x), @intCast(coord.y) },
|
.grid_pos = .{ @intCast(coord.x), @intCast(coord.y) },
|
||||||
.constraint_width = 1,
|
.constraint_width = 1,
|
||||||
@ -2657,21 +2652,12 @@ fn updateCell(
|
|||||||
@intCast(render.glyph.offset_x),
|
@intCast(render.glyph.offset_x),
|
||||||
@intCast(render.glyph.offset_y),
|
@intCast(render.glyph.offset_y),
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
try self.cells.add(self.alloc, .strikethrough, gpu_cell);
|
||||||
// If it's a wide cell we need to strike through the right half as well.
|
// If it's a wide cell we need to strike through the right half as well.
|
||||||
if (cell.gridWidth() > 1 and coord.x < self.cells.size.columns - 1) {
|
if (cell.gridWidth() > 1 and coord.x < self.cells.size.columns - 1) {
|
||||||
try self.cells.add(self.alloc, .strikethrough, .{
|
gpu_cell.grid_pos[0] = @intCast(coord.x + 1);
|
||||||
.mode = .fg,
|
try self.cells.add(self.alloc, .strikethrough, gpu_cell);
|
||||||
.grid_pos = .{ @intCast(coord.x + 1), @intCast(coord.y) },
|
|
||||||
.constraint_width = 1,
|
|
||||||
.color = .{ colors.fg.r, colors.fg.g, colors.fg.b, alpha },
|
|
||||||
.glyph_pos = .{ render.glyph.atlas_x, render.glyph.atlas_y },
|
|
||||||
.glyph_size = .{ render.glyph.width, render.glyph.height },
|
|
||||||
.bearings = .{
|
|
||||||
@intCast(render.glyph.offset_x),
|
|
||||||
@intCast(render.glyph.offset_y),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ pub const Key = enum {
|
|||||||
strikethrough,
|
strikethrough,
|
||||||
|
|
||||||
/// Returns the GPU vertex type for this key.
|
/// Returns the GPU vertex type for this key.
|
||||||
fn CellType(self: Key) type {
|
pub fn CellType(self: Key) type {
|
||||||
return switch (self) {
|
return switch (self) {
|
||||||
.bg => mtl_shaders.CellBg,
|
.bg => mtl_shaders.CellBg,
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ pub const Contents = struct {
|
|||||||
const bg_cells = try alloc.alloc(mtl_shaders.CellBg, cell_count);
|
const bg_cells = try alloc.alloc(mtl_shaders.CellBg, cell_count);
|
||||||
errdefer alloc.free(bg_cells);
|
errdefer alloc.free(bg_cells);
|
||||||
|
|
||||||
@memset(bg_cells, .{0, 0, 0, 0});
|
@memset(bg_cells, .{ 0, 0, 0, 0 });
|
||||||
|
|
||||||
// The foreground lists can hold 3 types of items:
|
// The foreground lists can hold 3 types of items:
|
||||||
// - Glyphs
|
// - Glyphs
|
||||||
@ -231,7 +231,7 @@ test Contents {
|
|||||||
for (0..rows) |y| {
|
for (0..rows) |y| {
|
||||||
try testing.expect(c.fg_rows.lists[y + 1].items.len == 0);
|
try testing.expect(c.fg_rows.lists[y + 1].items.len == 0);
|
||||||
for (0..cols) |x| {
|
for (0..cols) |x| {
|
||||||
try testing.expectEqual(.{0, 0, 0, 0}, c.bgCell(y, x).*);
|
try testing.expectEqual(.{ 0, 0, 0, 0 }, c.bgCell(y, x).*);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// And the cursor row should have a capacity of 1 and also be empty.
|
// And the cursor row should have a capacity of 1 and also be empty.
|
||||||
@ -256,7 +256,7 @@ test Contents {
|
|||||||
for (0..rows) |y| {
|
for (0..rows) |y| {
|
||||||
try testing.expect(c.fg_rows.lists[y + 1].items.len == 0);
|
try testing.expect(c.fg_rows.lists[y + 1].items.len == 0);
|
||||||
for (0..cols) |x| {
|
for (0..cols) |x| {
|
||||||
try testing.expectEqual(.{0, 0, 0, 0}, c.bgCell(y, x).*);
|
try testing.expectEqual(.{ 0, 0, 0, 0 }, c.bgCell(y, x).*);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ pub const Uniforms = extern struct {
|
|||||||
cursor_color: [4]u8 align(4),
|
cursor_color: [4]u8 align(4),
|
||||||
|
|
||||||
// Whether the cursor is 2 cells wide.
|
// Whether the cursor is 2 cells wide.
|
||||||
wide_cursor: bool align(1),
|
cursor_wide: bool align(1),
|
||||||
|
|
||||||
const PaddingExtend = packed struct(u8) {
|
const PaddingExtend = packed struct(u8) {
|
||||||
left: bool = false,
|
left: bool = false,
|
||||||
|
@ -18,7 +18,7 @@ struct Uniforms {
|
|||||||
float min_contrast;
|
float min_contrast;
|
||||||
ushort2 cursor_pos;
|
ushort2 cursor_pos;
|
||||||
uchar4 cursor_color;
|
uchar4 cursor_color;
|
||||||
bool wide_cursor;
|
bool cursor_wide;
|
||||||
};
|
};
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
@ -296,7 +296,7 @@ vertex CellTextVertexOut cell_text_vertex(
|
|||||||
in.mode != MODE_TEXT_CURSOR &&
|
in.mode != MODE_TEXT_CURSOR &&
|
||||||
(
|
(
|
||||||
in.grid_pos.x == uniforms.cursor_pos.x ||
|
in.grid_pos.x == uniforms.cursor_pos.x ||
|
||||||
uniforms.wide_cursor &&
|
uniforms.cursor_wide &&
|
||||||
in.grid_pos.x == uniforms.cursor_pos.x + 1
|
in.grid_pos.x == uniforms.cursor_pos.x + 1
|
||||||
) &&
|
) &&
|
||||||
in.grid_pos.y == uniforms.cursor_pos.y
|
in.grid_pos.y == uniforms.cursor_pos.y
|
||||||
|
Reference in New Issue
Block a user