1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-11 13:51:01 -05:00

Fix cursor disappearing

The cfc20d4f34 commit introduced a
regression which would cause the cursor to disappear after the glyph
cache has been filled.

Since the cursor was not cached on the glyph cache, the cursor would
quickly fill up the OpenGL texture with lots of cursor textures and then
things would break after the atlas was filled completely.

This adds a separate cursor cache which is keyed by the cursor style
that will persist the texture without flooding the atlas.

This fixes #2355.
This commit is contained in:
Christian Duerr 2019-04-25 20:01:23 +00:00 committed by GitHub
parent e964af8a5e
commit 494348abe8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 5 deletions

View file

@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- PTY size not getting updated when message bar is shown
- Text Cursor disappearing
## Version 0.3.2

View file

@ -343,7 +343,7 @@ pub trait Handler {
}
/// Describes shape of cursor
#[derive(Debug, Eq, PartialEq, Copy, Clone, Deserialize)]
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash, Deserialize)]
pub enum CursorStyle {
/// Cursor is a block like `▒`
Block,

View file

@ -26,6 +26,7 @@ use font::{self, FontDesc, FontKey, GlyphKey, Rasterize, RasterizedGlyph, Raster
use glutin::dpi::PhysicalSize;
use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
use crate::ansi::CursorStyle;
use crate::config::{self, Config, Delta};
use crate::gl;
use crate::gl::types::*;
@ -154,6 +155,9 @@ pub struct GlyphCache {
/// Cache of buffered glyphs
cache: HashMap<GlyphKey, Glyph, BuildHasherDefault<FnvHasher>>,
/// Cache of buffered cursor glyphs
cursor_cache: HashMap<CursorStyle, Glyph, BuildHasherDefault<FnvHasher>>,
/// Rasterizer for loading new glyphs
rasterizer: Rasterizer,
@ -195,6 +199,7 @@ impl GlyphCache {
let mut cache = GlyphCache {
cache: HashMap::default(),
cursor_cache: HashMap::default(),
rasterizer,
font_size: font.size(),
font_key: regular,
@ -302,6 +307,7 @@ impl GlyphCache {
// Clear currently cached data in both GL and the registry
loader.clear();
self.cache = HashMap::default();
self.cursor_cache = HashMap::default();
// Update dpi scaling
self.rasterizer.update_dpr(dpr as f32);
@ -984,9 +990,12 @@ impl<'a> RenderApi<'a> {
pub fn render_cell(&mut self, cell: RenderableCell, glyph_cache: &mut GlyphCache) {
let chars = match cell.inner {
RenderableCellContent::Raw(ref raw) => {
RenderableCellContent::Cursor((cursor_style, ref raw)) => {
// Raw cell pixel buffers like cursors don't need to go through font lookup
let glyph = self.load_glyph(raw);
let glyph = glyph_cache
.cursor_cache
.entry(cursor_style)
.or_insert_with(|| self.load_glyph(raw));
self.add_render_item(&cell, &glyph);
return;
},

View file

@ -259,7 +259,7 @@ impl<'a> RenderableCellsIter<'a> {
#[derive(Clone, Debug)]
pub enum RenderableCellContent {
Chars([char; cell::MAX_ZEROWIDTH_CHARS + 1]),
Raw(RasterizedGlyph),
Cursor((CursorStyle, RasterizedGlyph)),
}
#[derive(Clone, Debug)]
@ -388,7 +388,8 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
let mut renderable_cell =
RenderableCell::new(self.config, self.colors, cell, false);
renderable_cell.inner = RenderableCellContent::Raw(cursor_cell);
renderable_cell.inner =
RenderableCellContent::Cursor((self.cursor_style, cursor_cell));
if let Some(color) = self.config.cursor_cursor_color() {
renderable_cell.fg = color;