mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 08:16:13 +03:00
renderer/opengl: implement cursor-invert-fg-bg
This commit is contained in:
@ -291,8 +291,6 @@ palette: Palette = .{},
|
|||||||
|
|
||||||
/// Swap the foreground and background colors of the cell under the cursor. This
|
/// Swap the foreground and background colors of the cell under the cursor. This
|
||||||
/// option overrides the `cursor-color` and `cursor-text` options.
|
/// option overrides the `cursor-color` and `cursor-text` options.
|
||||||
///
|
|
||||||
/// This is currently only supported on macOS.
|
|
||||||
@"cursor-invert-fg-bg": bool = false,
|
@"cursor-invert-fg-bg": bool = false,
|
||||||
|
|
||||||
/// The opacity level (opposite of transparency) of the cursor. A value of 1
|
/// The opacity level (opposite of transparency) of the cursor. A value of 1
|
||||||
|
@ -95,6 +95,11 @@ background_color: terminal.color.RGB,
|
|||||||
/// by a terminal application
|
/// by a terminal application
|
||||||
cursor_color: ?terminal.color.RGB,
|
cursor_color: ?terminal.color.RGB,
|
||||||
|
|
||||||
|
/// When `cursor_color` is null, swap the foreground and background colors of
|
||||||
|
/// the cell under the cursor for the cursor color. Otherwise, use the default
|
||||||
|
/// foreground color as the cursor color.
|
||||||
|
cursor_invert: bool,
|
||||||
|
|
||||||
/// Padding options
|
/// Padding options
|
||||||
padding: renderer.Options.Padding,
|
padding: renderer.Options.Padding,
|
||||||
|
|
||||||
@ -235,6 +240,7 @@ pub const DerivedConfig = struct {
|
|||||||
font_features: std.ArrayListUnmanaged([:0]const u8),
|
font_features: std.ArrayListUnmanaged([:0]const u8),
|
||||||
font_styles: font.CodepointResolver.StyleStatus,
|
font_styles: font.CodepointResolver.StyleStatus,
|
||||||
cursor_color: ?terminal.color.RGB,
|
cursor_color: ?terminal.color.RGB,
|
||||||
|
cursor_invert: bool,
|
||||||
cursor_text: ?terminal.color.RGB,
|
cursor_text: ?terminal.color.RGB,
|
||||||
cursor_opacity: f64,
|
cursor_opacity: f64,
|
||||||
background: terminal.color.RGB,
|
background: terminal.color.RGB,
|
||||||
@ -274,17 +280,21 @@ pub const DerivedConfig = struct {
|
|||||||
config.link.links.items,
|
config.link.links.items,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const cursor_invert = config.@"cursor-invert-fg-bg";
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.background_opacity = @max(0, @min(1, config.@"background-opacity")),
|
.background_opacity = @max(0, @min(1, config.@"background-opacity")),
|
||||||
.font_thicken = config.@"font-thicken",
|
.font_thicken = config.@"font-thicken",
|
||||||
.font_features = font_features,
|
.font_features = font_features,
|
||||||
.font_styles = font_styles,
|
.font_styles = font_styles,
|
||||||
|
|
||||||
.cursor_color = if (config.@"cursor-color") |col|
|
.cursor_color = if (!cursor_invert and config.@"cursor-color" != null)
|
||||||
col.toTerminalRGB()
|
config.@"cursor-color".?.toTerminalRGB()
|
||||||
else
|
else
|
||||||
null,
|
null,
|
||||||
|
|
||||||
|
.cursor_invert = cursor_invert,
|
||||||
|
|
||||||
.cursor_text = if (config.@"cursor-text") |txt|
|
.cursor_text = if (config.@"cursor-text") |txt|
|
||||||
txt.toTerminalRGB()
|
txt.toTerminalRGB()
|
||||||
else
|
else
|
||||||
@ -354,6 +364,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !OpenGL {
|
|||||||
.foreground_color = options.config.foreground,
|
.foreground_color = options.config.foreground,
|
||||||
.background_color = options.config.background,
|
.background_color = options.config.background,
|
||||||
.cursor_color = options.config.cursor_color,
|
.cursor_color = options.config.cursor_color,
|
||||||
|
.cursor_invert = options.config.cursor_invert,
|
||||||
.padding = options.padding,
|
.padding = options.padding,
|
||||||
.surface_mailbox = options.surface_mailbox,
|
.surface_mailbox = options.surface_mailbox,
|
||||||
.deferred_font_size = .{ .metrics = grid.metrics },
|
.deferred_font_size = .{ .metrics = grid.metrics },
|
||||||
@ -1117,20 +1128,30 @@ pub fn rebuildCells(
|
|||||||
break :cursor_style;
|
break :cursor_style;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = try self.addCursor(screen, cursor_style);
|
const cursor_color = self.cursor_color orelse color: {
|
||||||
|
if (self.cursor_invert) {
|
||||||
|
const sty = screen.cursor.page_pin.style(screen.cursor.page_cell);
|
||||||
|
break :color sty.fg(color_palette, self.config.bold_is_bright) orelse self.foreground_color;
|
||||||
|
} else {
|
||||||
|
break :color self.foreground_color;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
_ = try self.addCursor(screen, cursor_style, cursor_color);
|
||||||
if (cursor_cell) |*cell| {
|
if (cursor_cell) |*cell| {
|
||||||
if (cell.mode == .fg or cell.mode == .fg_constrained) {
|
if (cell.mode == .fg or cell.mode == .fg_constrained) {
|
||||||
if (self.config.cursor_text) |txt| {
|
const cell_color = if (self.cursor_invert) blk: {
|
||||||
cell.r = txt.r;
|
const sty = screen.cursor.page_pin.style(screen.cursor.page_cell);
|
||||||
cell.g = txt.g;
|
break :blk sty.bg(screen.cursor.page_cell, color_palette) orelse self.background_color;
|
||||||
cell.b = txt.b;
|
} else if (self.config.cursor_text) |txt|
|
||||||
cell.a = 255;
|
txt
|
||||||
} else {
|
else
|
||||||
cell.r = self.background_color.r;
|
self.background_color;
|
||||||
cell.g = self.background_color.g;
|
|
||||||
cell.b = self.background_color.b;
|
cell.r = cell_color.r;
|
||||||
cell.a = 255;
|
cell.g = cell_color.g;
|
||||||
}
|
cell.b = cell_color.b;
|
||||||
|
cell.a = 255;
|
||||||
}
|
}
|
||||||
try self.cells.append(self.alloc, cell.*);
|
try self.cells.append(self.alloc, cell.*);
|
||||||
}
|
}
|
||||||
@ -1218,6 +1239,7 @@ fn addCursor(
|
|||||||
self: *OpenGL,
|
self: *OpenGL,
|
||||||
screen: *terminal.Screen,
|
screen: *terminal.Screen,
|
||||||
cursor_style: renderer.CursorStyle,
|
cursor_style: renderer.CursorStyle,
|
||||||
|
cursor_color: terminal.color.RGB,
|
||||||
) !?*const CellProgram.Cell {
|
) !?*const CellProgram.Cell {
|
||||||
// Add the cursor. We render the cursor over the wide character if
|
// Add the cursor. We render the cursor over the wide character if
|
||||||
// we're on the wide characer tail.
|
// we're on the wide characer tail.
|
||||||
@ -1233,7 +1255,6 @@ fn addCursor(
|
|||||||
break :cell .{ prev_cell.wide == .wide, screen.cursor.x - 1 };
|
break :cell .{ prev_cell.wide == .wide, screen.cursor.x - 1 };
|
||||||
};
|
};
|
||||||
|
|
||||||
const color = self.cursor_color orelse self.foreground_color;
|
|
||||||
const alpha: u8 = if (!self.focused) 255 else alpha: {
|
const alpha: u8 = if (!self.focused) 255 else alpha: {
|
||||||
const alpha = 255 * self.config.cursor_opacity;
|
const alpha = 255 * self.config.cursor_opacity;
|
||||||
break :alpha @intFromFloat(@ceil(alpha));
|
break :alpha @intFromFloat(@ceil(alpha));
|
||||||
@ -1264,9 +1285,9 @@ fn addCursor(
|
|||||||
.grid_col = @intCast(x),
|
.grid_col = @intCast(x),
|
||||||
.grid_row = @intCast(screen.cursor.y),
|
.grid_row = @intCast(screen.cursor.y),
|
||||||
.grid_width = if (wide) 2 else 1,
|
.grid_width = if (wide) 2 else 1,
|
||||||
.r = color.r,
|
.r = cursor_color.r,
|
||||||
.g = color.g,
|
.g = cursor_color.g,
|
||||||
.b = color.b,
|
.b = cursor_color.b,
|
||||||
.a = alpha,
|
.a = alpha,
|
||||||
.bg_r = 0,
|
.bg_r = 0,
|
||||||
.bg_g = 0,
|
.bg_g = 0,
|
||||||
@ -1583,7 +1604,8 @@ pub fn changeConfig(self: *OpenGL, config: *DerivedConfig) !void {
|
|||||||
// Set our new colors
|
// Set our new colors
|
||||||
self.background_color = config.background;
|
self.background_color = config.background;
|
||||||
self.foreground_color = config.foreground;
|
self.foreground_color = config.foreground;
|
||||||
self.cursor_color = config.cursor_color;
|
self.cursor_invert = config.cursor_invert;
|
||||||
|
self.cursor_color = if (!config.cursor_invert) config.cursor_color else null;
|
||||||
|
|
||||||
// Update our uniforms
|
// Update our uniforms
|
||||||
self.deferred_config = .{};
|
self.deferred_config = .{};
|
||||||
|
Reference in New Issue
Block a user