From b96fb2ddab64970783313850ed80dfd311c16158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 28 Nov 2019 19:22:21 +0100 Subject: [PATCH] render: fix rendering of cursor when cell is reversed When the user had configured the cursor color, we failed to invert (reverse) the foreground and background color when the cursor was on a cell with the 'reverse' attribute set. --- render.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/render.c b/render.c index 23f72870..64b64a13 100644 --- a/render.c +++ b/render.c @@ -202,12 +202,25 @@ render_cell(struct terminal *term, pixman_image_t *pix, bool block_cursor = has_cursor && term->cursor_style == CURSOR_BLOCK; bool is_selected = coord_is_selected(term, col, row); - uint32_t _fg = cell->attrs.have_fg - ? cell->attrs.fg - : !term->reverse ? term->colors.fg : term->colors.bg; - uint32_t _bg = cell->attrs.have_bg - ? cell->attrs.bg - : !term->reverse ? term->colors.bg : term->colors.fg; + uint32_t _fg = 0; + uint32_t _bg = 0; + + if (block_cursor && term->cursor_color.text >> 31) { + /* User configured cursor color overrides all attributes */ + assert(term->cursor_color.cursor >> 31); + + /* Slightly ugly... reverse here, since they'll be reversed again below */ + _fg = term->cursor_color.cursor; + _bg = term->cursor_color.text; + } else { + /* Use cell specific color, if set, otherwise the default colors (possible reversed) */ + _fg = cell->attrs.have_fg + ? cell->attrs.fg + : !term->reverse ? term->colors.fg : term->colors.bg; + _bg = cell->attrs.have_bg + ? cell->attrs.bg + : !term->reverse ? term->colors.bg : term->colors.fg; + } /* If *one* is set, we reverse */ if (block_cursor ^ cell->attrs.reverse ^ is_selected) { @@ -226,13 +239,6 @@ render_cell(struct terminal *term, pixman_image_t *pix, if (cell->attrs.dim) pixman_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_pixman(term->cursor_color.text); - bg = color_hex_to_pixman(term->cursor_color.cursor); - } - if (term->is_searching && !is_selected) { pixman_color_dim_for_search(&fg); pixman_color_dim_for_search(&bg);