aboutsummaryrefslogtreecommitdiff
path: root/src/term
diff options
context:
space:
mode:
authorJoe Wilm <jwilm@users.noreply.github.com>2017-10-21 15:26:42 -0700
committerGitHub <noreply@github.com>2017-10-21 15:26:42 -0700
commitb79574ee823900c21759628f92cf036271847afc (patch)
tree0147c31cde54febf034749b095513d3b5b376130 /src/term
parent7a5eebd0941169396557b80084c0c8f354c6840f (diff)
downloadalacritty-b79574ee823900c21759628f92cf036271847afc.tar.gz
alacritty-b79574ee823900c21759628f92cf036271847afc.zip
Fix solid background color opacity (#847)
Since landing the patch adding transparency support to Alacritty, there's been an issue where othewise solid background cells were also being rendered partially transparent. Now, all filled background cells are rendered fully opaque. Some logic was added to support discarding filled backgrounds which had the same color as the default background. This means that, if the default background is #000 and a cell has that background, it will never be rendered opaque. This may not be correct. Note that many truecolor vim color schemes print spaces for default colored background cells. Performance can be dramatically improved by using ctermbg=NONE guibg=NONE to skip rendering those cells.
Diffstat (limited to 'src/term')
-rw-r--r--src/term/mod.rs39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/term/mod.rs b/src/term/mod.rs
index a16971b5..97460421 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -299,6 +299,14 @@ impl<'a> RenderableCellsIter<'a> {
}
}
+ #[inline]
+ fn compute_bg_alpha(&self, bg: &Color) -> f32 {
+ match *bg {
+ Color::Named(NamedColor::Background) => 0.0,
+ _ => 1.0
+ }
+ }
+
fn compute_bg_rgb(&self, bg: &Color) -> Rgb {
match *bg {
Color::Spec(rgb) => rgb,
@@ -314,6 +322,7 @@ pub struct RenderableCell {
pub c: char,
pub fg: Rgb,
pub bg: Rgb,
+ pub bg_alpha: f32,
pub flags: cell::Flags,
}
@@ -363,19 +372,35 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
};
// Apply inversion and lookup RGB values
- let (fg, bg) = if selected || cell.inverse() {
- (self.compute_bg_rgb(&cell.bg), self.compute_fg_rgb(&cell.fg, &cell))
+ let mut bg_alpha = 1.0;
+ let fg_rgb;
+ let bg_rgb;
+
+ let invert = selected ^ cell.inverse();
+
+ if invert {
+ if cell.fg == cell.bg {
+ bg_rgb = self.colors[NamedColor::Foreground];
+ fg_rgb = self.colors[NamedColor::Background];
+ bg_alpha = 1.0
+ } else {
+ bg_rgb = self.compute_fg_rgb(&cell.fg, &cell);
+ fg_rgb = self.compute_bg_rgb(&cell.bg);
+ }
} else {
- (self.compute_fg_rgb(&cell.fg, &cell), self.compute_bg_rgb(&cell.bg))
- };
+ fg_rgb = self.compute_fg_rgb(&cell.fg, &cell);
+ bg_rgb = self.compute_bg_rgb(&cell.bg);
+ bg_alpha = self.compute_bg_alpha(&cell.bg);
+ }
return Some(RenderableCell {
line: line,
column: column,
flags: cell.flags,
c: cell.c,
- fg: fg,
- bg: bg,
+ fg: fg_rgb,
+ bg: bg_rgb,
+ bg_alpha: bg_alpha,
})
}
@@ -976,7 +1001,7 @@ impl Term {
self.mode,
config,
selection,
- self.cursor_style
+ self.cursor_style,
)
}