From c49dd128559e8bebdb22c1a016e5d9ba7ddd26a6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 19 Jul 2018 12:13:39 +0530 Subject: [PATCH] Pass in cursor shape to cell shader --- kitty/cell_vertex.glsl | 14 ++++++++------ kitty/shaders.c | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/kitty/cell_vertex.glsl b/kitty/cell_vertex.glsl index dac6c9a3f..0c7d0a88c 100644 --- a/kitty/cell_vertex.glsl +++ b/kitty/cell_vertex.glsl @@ -13,7 +13,7 @@ layout(std140) uniform CellRenderData { uint default_fg, default_bg, highlight_fg, highlight_bg, cursor_color, url_color, url_style, inverted; - uint xnum, ynum; + uint xnum, ynum, cursor_fg_sprite_idx; float cursor_x, cursor_y, cursor_w; uint color_table[256]; @@ -153,6 +153,8 @@ void main() { int fg_index = fg_index_map[is_inverted]; int bg_index = 1 - fg_index; float cell_has_cursor = is_cursor(c, r); + float is_block_cursor = step(float(cursor_fg_sprite_idx), 0.5); + float cell_has_block_cursor = cell_has_cursor * is_block_cursor; vec3 bg = to_color(colors[bg_index], default_colors[bg_index]); // }}} @@ -177,8 +179,8 @@ void main() { strike_pos = to_sprite_pos(pos, ((text_attrs >> STRIKE_SHIFT) & ONE) * FOUR, ZERO, ZERO); // Cursor - foreground = choose_color(cell_has_cursor, CURSOR_TEXT_COLOR, foreground); - decoration_fg = choose_color(cell_has_cursor, CURSOR_TEXT_COLOR, decoration_fg); + foreground = choose_color(cell_has_block_cursor, CURSOR_TEXT_COLOR, foreground); + decoration_fg = choose_color(cell_has_block_cursor, CURSOR_TEXT_COLOR, decoration_fg); #endif // }}} @@ -193,17 +195,17 @@ void main() { // If the background color is default, set its opacity to background_opacity, otherwise it should be opaque bg_alpha = step(0.5, float(colors[bg_index] & BYTE_MASK)); // Cursor must not be affected by background_opacity - bg_alpha = mix(bg_alpha, 1.0, cell_has_cursor); + bg_alpha = mix(bg_alpha, 1.0, cell_has_block_cursor); bg_alpha = bg_alpha + (1.0f - bg_alpha) * background_opacity; #endif #if defined(SPECIAL) || defined(SIMPLE) // Selection and cursor bg = choose_color(float(is_selected & ONE), color_to_vec(highlight_bg), bg); - background = choose_color(cell_has_cursor, color_to_vec(cursor_color), bg); + background = choose_color(cell_has_block_cursor, color_to_vec(cursor_color), bg); #ifdef SPECIAL // bg_alpha should be 1 if cursor/selection otherwise 0 - bg_alpha = mix(0.0, 1.0, step(0.5, float(is_selected & ONE) + cell_has_cursor)); + bg_alpha = mix(0.0, 1.0, step(0.5, float(is_selected & ONE) + cell_has_block_cursor)); #endif #endif diff --git a/kitty/shaders.c b/kitty/shaders.c index 569cc1635..360ae9402 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -223,7 +223,7 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, G GLuint default_fg, default_bg, highlight_fg, highlight_bg, cursor_color, url_color, url_style, inverted; - GLuint xnum, ynum; + GLuint xnum, ynum, cursor_fg_sprite_idx; GLfloat cursor_x, cursor_y, cursor_w; }; static struct CellRenderData *rd; @@ -236,8 +236,10 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, G // Cursor position if (cursor->is_visible && cursor->shape == CURSOR_BLOCK && cursor->is_focused) { rd->cursor_x = screen->cursor->x, rd->cursor_y = screen->cursor->y; + rd->cursor_fg_sprite_idx = 0; } else { rd->cursor_x = screen->columns, rd->cursor_y = screen->lines; + rd->cursor_fg_sprite_idx = 0; } rd->cursor_w = rd->cursor_x + MAX(1, screen_current_char_width(screen)) - 1;