From 9ff2838844df45b6a1f20621ced870e9e1855ec8 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Sat, 26 Oct 2019 22:45:47 +0300 Subject: [PATCH] Fix visual bell rendering mode Fixes #2911. --- CHANGELOG.md | 2 ++ alacritty/src/display.rs | 41 ++++++++++++------------ alacritty_terminal/src/renderer/mod.rs | 26 +++++---------- alacritty_terminal/src/renderer/rects.rs | 7 ++-- 4 files changed, 35 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d498cf..cd67075 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Crash when trying to start on X11 with a Wayland compositor running - Crash with a virtual display connected on X11 - Use `\` instead of `\\` as path separators on Windows for logging config file location +- Underline/strikeout drawn above visual bell +- Terminal going transparent during visual bell ### Removed diff --git a/alacritty/src/display.rs b/alacritty/src/display.rs index a8f72b3..f20c958 100644 --- a/alacritty/src/display.rs +++ b/alacritty/src/display.rs @@ -400,27 +400,33 @@ impl Display { let mut rects = lines.into_rects(&metrics, &size_info); + // Push visual bell after underline/strikeout rects + if visual_bell_intensity != 0. { + let visual_bell_rect = RenderRect::new( + 0., + 0., + size_info.width, + size_info.height, + config.visual_bell.color, + visual_bell_intensity as f32, + ); + rects.push(visual_bell_rect); + } + if let Some(message) = message_buffer.message() { let text = message.text(&size_info); // Create a new rectangle for the background let start_line = size_info.lines().0 - text.len(); let y = size_info.padding_y + size_info.cell_height * start_line as f32; - rects.push(RenderRect::new( - 0., - y, - size_info.width, - size_info.height - y, - message.color(), - )); + let message_bar_rect = + RenderRect::new(0., y, size_info.width, size_info.height - y, message.color(), 1.); - // Draw rectangles including the new background - self.renderer.draw_rects( - &size_info, - config.visual_bell.color, - visual_bell_intensity, - rects, - ); + // Push message_bar in the end, so it'll be above all other content + rects.push(message_bar_rect); + + // Draw rectangles + self.renderer.draw_rects(&size_info, rects); // Relay messages to the user let mut offset = 1; @@ -437,12 +443,7 @@ impl Display { } } else { // Draw rectangles - self.renderer.draw_rects( - &size_info, - config.visual_bell.color, - visual_bell_intensity, - rects, - ); + self.renderer.draw_rects(&size_info, rects); } // Draw render timer diff --git a/alacritty_terminal/src/renderer/mod.rs b/alacritty_terminal/src/renderer/mod.rs index 51c0d0f..76daac9 100644 --- a/alacritty_terminal/src/renderer/mod.rs +++ b/alacritty_terminal/src/renderer/mod.rs @@ -713,13 +713,7 @@ impl QuadRenderer { } // Draw all rectangles simultaneously to prevent excessive program swaps - pub fn draw_rects( - &mut self, - props: &term::SizeInfo, - visual_bell_color: Rgb, - visual_bell_intensity: f64, - cell_line_rects: Vec, - ) { + pub fn draw_rects(&mut self, props: &term::SizeInfo, rects: Vec) { // Swap to rectangle rendering program unsafe { // Swap program @@ -729,7 +723,7 @@ impl QuadRenderer { gl::Viewport(0, 0, props.width as i32, props.height as i32); // Change blending strategy - gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); + gl::BlendFuncSeparate(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA, gl::SRC_ALPHA, gl::ONE); // Setup data and buffers gl::BindVertexArray(self.rect_vao); @@ -747,13 +741,9 @@ impl QuadRenderer { gl::EnableVertexAttribArray(0); } - // Draw visual bell - let rect = RenderRect::new(0., 0., props.width, props.height, visual_bell_color); - self.render_rect(&rect, visual_bell_intensity as f32, props); - - // Draw underlines and strikeouts - for cell_line_rect in cell_line_rects { - self.render_rect(&cell_line_rect, 255., props); + // Draw all the rects + for rect in rects { + self.render_rect(&rect, props); } // Deactivate rectangle program again @@ -881,9 +871,9 @@ impl QuadRenderer { // Render a rectangle // // This requires the rectangle program to be activated - fn render_rect(&mut self, rect: &RenderRect, alpha: f32, size: &term::SizeInfo) { + fn render_rect(&mut self, rect: &RenderRect, size: &term::SizeInfo) { // Do nothing when alpha is fully transparent - if alpha == 0. { + if rect.alpha == 0. { return; } @@ -908,7 +898,7 @@ impl QuadRenderer { ); // Color - self.rect_program.set_color(rect.color, alpha); + self.rect_program.set_color(rect.color, rect.alpha); // Draw the rectangle gl::DrawElements(gl::TRIANGLES, 6, gl::UNSIGNED_INT, ptr::null()); diff --git a/alacritty_terminal/src/renderer/rects.rs b/alacritty_terminal/src/renderer/rects.rs index dd72f67..c105c2e 100644 --- a/alacritty_terminal/src/renderer/rects.rs +++ b/alacritty_terminal/src/renderer/rects.rs @@ -27,11 +27,12 @@ pub struct RenderRect { pub width: f32, pub height: f32, pub color: Rgb, + pub alpha: f32, } impl RenderRect { - pub fn new(x: f32, y: f32, width: f32, height: f32, color: Rgb) -> Self { - RenderRect { x, y, width, height, color } + pub fn new(x: f32, y: f32, width: f32, height: f32, color: Rgb, alpha: f32) -> Self { + RenderRect { x, y, width, height, color, alpha } } } @@ -65,7 +66,7 @@ impl RenderLine { y = max_y; } - RenderRect::new(start_x + size.padding_x, y + size.padding_y, width, height, self.color) + RenderRect::new(start_x + size.padding_x, y + size.padding_y, width, height, self.color, 1.) } }