From ff38d3e358506da143f8829123c56741d6a142c0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 14 Oct 2023 14:08:06 -0700 Subject: [PATCH] config: add cursor-opacity --- src/config/Config.zig | 7 +++++++ src/renderer/Metal.zig | 9 ++++++++- src/renderer/OpenGL.zig | 9 ++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index 82733bfba..656726084 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -174,6 +174,13 @@ palette: Palette = .{}, /// The color of the cursor. If this is not set, a default will be chosen. @"cursor-color": ?Color = null, +/// The opacity level (opposite of transparency) of the cursor. +/// A value of 1 is fully opaque and a value of 0 is fully transparent. +/// A value less than 0 or greater than 1 will be clamped to the nearest +/// valid value. Note that a sufficiently small value such as 0.3 may be +/// effectively invisible and may make it difficult to find the cursor. +@"cursor-opacity": f64 = 1.0, + /// The style of the cursor. This sets the default style. A running /// programn can still request an explicit cursor style using escape /// sequences (such as CSI q). Shell configurations will often request diff --git a/src/renderer/Metal.zig b/src/renderer/Metal.zig index 4d2517836..80e18aed2 100644 --- a/src/renderer/Metal.zig +++ b/src/renderer/Metal.zig @@ -104,6 +104,7 @@ pub const DerivedConfig = struct { font_features: std.ArrayList([]const u8), font_styles: font.Group.StyleStatus, cursor_color: ?terminal.color.RGB, + cursor_opacity: f64, cursor_text: ?terminal.color.RGB, background: terminal.color.RGB, background_opacity: f64, @@ -144,6 +145,8 @@ pub const DerivedConfig = struct { else null, + .cursor_opacity = @max(0, @min(1, config.@"cursor-opacity")), + .background = config.background.toTerminalRGB(), .foreground = config.foreground.toTerminalRGB(), @@ -1419,6 +1422,10 @@ fn addCursor( }; const color = self.config.cursor_color orelse self.config.foreground; + const alpha: u8 = alpha: { + const alpha = 255 * self.config.cursor_opacity; + break :alpha @intFromFloat(@ceil(alpha)); + }; const sprite: font.Sprite = switch (cursor_style) { .block => .cursor_rect, @@ -1444,7 +1451,7 @@ fn addCursor( @as(f32, @floatFromInt(screen.cursor.y)), }, .cell_width = if (cell.attrs.wide) 2 else 1, - .color = .{ color.r, color.g, color.b, 0xFF }, + .color = .{ color.r, color.g, color.b, alpha }, .glyph_pos = .{ glyph.atlas_x, glyph.atlas_y }, .glyph_size = .{ glyph.width, glyph.height }, .glyph_offset = .{ glyph.offset_x, glyph.offset_y }, diff --git a/src/renderer/OpenGL.zig b/src/renderer/OpenGL.zig index c0b255ca2..bebbecf2f 100644 --- a/src/renderer/OpenGL.zig +++ b/src/renderer/OpenGL.zig @@ -219,6 +219,7 @@ pub const DerivedConfig = struct { font_styles: font.Group.StyleStatus, cursor_color: ?terminal.color.RGB, cursor_text: ?terminal.color.RGB, + cursor_opacity: f64, background: terminal.color.RGB, background_opacity: f64, foreground: terminal.color.RGB, @@ -258,6 +259,8 @@ pub const DerivedConfig = struct { else null, + .cursor_opacity = @max(0, @min(1, config.@"cursor-opacity")), + .background = config.background.toTerminalRGB(), .foreground = config.foreground.toTerminalRGB(), @@ -870,6 +873,10 @@ fn addCursor( }; const color = self.config.cursor_color orelse self.config.foreground; + const alpha: u8 = alpha: { + const alpha = 255 * self.config.cursor_opacity; + break :alpha @intFromFloat(@ceil(alpha)); + }; const sprite: font.Sprite = switch (cursor_style) { .block => .cursor_rect, @@ -896,7 +903,7 @@ fn addCursor( .fg_r = color.r, .fg_g = color.g, .fg_b = color.b, - .fg_a = 255, + .fg_a = alpha, .bg_r = 0, .bg_g = 0, .bg_b = 0,