Pass in cursor shape to cell shader

This commit is contained in:
Kovid Goyal 2018-07-19 12:13:39 +05:30
parent 544f97a3fe
commit c49dd12855
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 7 deletions

View File

@ -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 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; float cursor_x, cursor_y, cursor_w;
uint color_table[256]; uint color_table[256];
@ -153,6 +153,8 @@ void main() {
int fg_index = fg_index_map[is_inverted]; int fg_index = fg_index_map[is_inverted];
int bg_index = 1 - fg_index; int bg_index = 1 - fg_index;
float cell_has_cursor = is_cursor(c, r); 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]); 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); strike_pos = to_sprite_pos(pos, ((text_attrs >> STRIKE_SHIFT) & ONE) * FOUR, ZERO, ZERO);
// Cursor // Cursor
foreground = choose_color(cell_has_cursor, CURSOR_TEXT_COLOR, foreground); foreground = choose_color(cell_has_block_cursor, CURSOR_TEXT_COLOR, foreground);
decoration_fg = choose_color(cell_has_cursor, CURSOR_TEXT_COLOR, decoration_fg); decoration_fg = choose_color(cell_has_block_cursor, CURSOR_TEXT_COLOR, decoration_fg);
#endif #endif
// }}} // }}}
@ -193,17 +195,17 @@ void main() {
// If the background color is default, set its opacity to background_opacity, otherwise it should be opaque // 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)); bg_alpha = step(0.5, float(colors[bg_index] & BYTE_MASK));
// Cursor must not be affected by background_opacity // 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; bg_alpha = bg_alpha + (1.0f - bg_alpha) * background_opacity;
#endif #endif
#if defined(SPECIAL) || defined(SIMPLE) #if defined(SPECIAL) || defined(SIMPLE)
// Selection and cursor // Selection and cursor
bg = choose_color(float(is_selected & ONE), color_to_vec(highlight_bg), bg); 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 #ifdef SPECIAL
// bg_alpha should be 1 if cursor/selection otherwise 0 // 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
#endif #endif

View File

@ -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 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; GLfloat cursor_x, cursor_y, cursor_w;
}; };
static struct CellRenderData *rd; static struct CellRenderData *rd;
@ -236,8 +236,10 @@ cell_update_uniform_block(ssize_t vao_idx, Screen *screen, int uniform_buffer, G
// Cursor position // Cursor position
if (cursor->is_visible && cursor->shape == CURSOR_BLOCK && cursor->is_focused) { 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_x = screen->cursor->x, rd->cursor_y = screen->cursor->y;
rd->cursor_fg_sprite_idx = 0;
} else { } else {
rd->cursor_x = screen->columns, rd->cursor_y = screen->lines; 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; rd->cursor_w = rd->cursor_x + MAX(1, screen_current_char_width(screen)) - 1;