From bf4847d3e028516b0de446e8455d43833983c17b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 23 Jul 2019 18:54:58 +0200 Subject: conf: allow the user to configure a fixed cursor color The default is to reverse the foreground/background colors in the cell with the cursor. But, if the user configures a specific set of cursor colors, those will always be used, regardless of other cell attributes (dim, reverse etc). The cursor color is specified as two color values, 'text' and 'cursor'. The block cursor uses the 'cursor' color as background, and the 'text' color for the glyph. All other cursor styles uses the 'cursor' color for the cursor, but uses the cell's foreground color for the glyph (meaning, dim/reverse/etc applies). --- render.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 3e5730e0..16bc19b9 100644 --- a/render.c +++ b/render.c @@ -194,6 +194,13 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell, if (cell->attrs.dim) color_dim(&fg); + if (block_cursor && term->cursor_color.text >> 31) { + /* User configured cursor color overrides all attributes */ + assert(term->cursor_color.cursor >> 31); + fg = color_hex_to_rgb(term->cursor_color.text); + bg = color_hex_to_rgb(term->cursor_color.cursor); + } + /* Background */ cairo_set_source_rgb(buf->cairo, bg.r, bg.g, bg.b); cairo_rectangle(buf->cairo, x, y, width, height); @@ -201,11 +208,12 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell, /* Non-block cursors */ if (has_cursor) { + struct rgb cursor_color = color_hex_to_rgb(term->cursor_color.cursor); if (term->cursor_style == CURSOR_BAR) - draw_bar(term, buf, fg, x, y); + draw_bar(term, buf, cursor_color, x, y); else if (term->cursor_style == CURSOR_UNDERLINE) draw_underline( - term, buf, attrs_to_font(term, &cell->attrs), fg, x, y); + term, buf, attrs_to_font(term, &cell->attrs), cursor_color, x, y); } if (cell->attrs.blink && !term->blink.active) { -- cgit v1.3