From 490ae248f8e0462b84fc501c45986bcb97792b20 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 19 Jul 2018 14:05:15 +0530 Subject: [PATCH] Render all cursor shapes in the cell shader --- kitty/cell_fragment.glsl | 6 +++++- kitty/cell_vertex.glsl | 4 ++++ kitty/shaders.c | 18 ++++++++++++------ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/kitty/cell_fragment.glsl b/kitty/cell_fragment.glsl index b5de428e3..f9eaf768d 100644 --- a/kitty/cell_fragment.glsl +++ b/kitty/cell_fragment.glsl @@ -22,8 +22,10 @@ uniform sampler2DArray sprites; in float effective_text_alpha; in vec3 sprite_pos; in vec3 underline_pos; +in vec3 cursor_pos; in vec3 strike_pos; in vec3 foreground; +in vec4 cursor_color_vec; in vec3 decoration_fg; in float colored_sprite; #endif @@ -58,10 +60,12 @@ vec4 calculate_foreground() { float text_alpha = text_fg.a; float underline_alpha = texture(sprites, underline_pos).a; float strike_alpha = texture(sprites, strike_pos).a; + float cursor_alpha = texture(sprites, cursor_pos).a; // Since strike and text are the same color, we simply add the alpha values float combined_alpha = min(text_alpha + strike_alpha, 1.0f); // Underline color might be different, so alpha blend - return alpha_blend(decoration_fg, underline_alpha * effective_text_alpha, fg, combined_alpha * effective_text_alpha); + vec4 ans = alpha_blend(decoration_fg, underline_alpha * effective_text_alpha, fg, combined_alpha * effective_text_alpha); + return mix(ans, cursor_color_vec, cursor_alpha); } #endif diff --git a/kitty/cell_vertex.glsl b/kitty/cell_vertex.glsl index 0c7d0a88c..707188cce 100644 --- a/kitty/cell_vertex.glsl +++ b/kitty/cell_vertex.glsl @@ -55,6 +55,8 @@ uniform float inactive_text_alpha; uniform float dim_opacity; out vec3 sprite_pos; out vec3 underline_pos; +out vec3 cursor_pos; +out vec4 cursor_color_vec; out vec3 strike_pos; out vec3 foreground; out vec3 decoration_fg; @@ -179,8 +181,10 @@ void main() { strike_pos = to_sprite_pos(pos, ((text_attrs >> STRIKE_SHIFT) & ONE) * FOUR, ZERO, ZERO); // Cursor + cursor_color_vec = vec4(color_to_vec(cursor_color), 1.0); foreground = choose_color(cell_has_block_cursor, CURSOR_TEXT_COLOR, foreground); decoration_fg = choose_color(cell_has_block_cursor, CURSOR_TEXT_COLOR, decoration_fg); + cursor_pos = to_sprite_pos(pos, cursor_fg_sprite_idx * uint(cell_has_cursor), ZERO, ZERO); #endif // }}} diff --git a/kitty/shaders.c b/kitty/shaders.c index d0d66d6cd..737e3664c 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -234,13 +234,19 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, G copy_color_table_to_buffer(screen->color_profile, (GLuint*)rd, cell_program_layouts[CELL_PROGRAM].color_table.offset / sizeof(GLuint), cell_program_layouts[CELL_PROGRAM].color_table.stride / sizeof(GLuint)); } // Cursor position - if (cursor->is_visible && cursor->shape == CURSOR_BLOCK && cursor->is_focused) { + if (cursor->is_visible) { 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; - } + if (cursor->is_focused) { + switch(cursor->shape) { + default: + rd->cursor_fg_sprite_idx = 0; break; + case CURSOR_BEAM: + rd->cursor_fg_sprite_idx = 6; break; + case CURSOR_UNDERLINE: + rd->cursor_fg_sprite_idx = 7; break; + } + } else rd->cursor_fg_sprite_idx = 8; + } else rd->cursor_x = screen->columns, rd->cursor_y = screen->lines; rd->cursor_w = rd->cursor_x + MAX(1, screen_current_char_width(screen)) - 1; rd->xnum = screen->columns; rd->ynum = screen->lines;