1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-25 14:05:41 -05:00

Fix visual bell rendering mode

Fixes #2911.
This commit is contained in:
Kirill Chibisov 2019-10-26 22:45:47 +03:00 committed by Christian Duerr
parent 77127fbb41
commit 9ff2838844
4 changed files with 35 additions and 41 deletions

View file

@ -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 when trying to start on X11 with a Wayland compositor running
- Crash with a virtual display connected on X11 - Crash with a virtual display connected on X11
- Use `\` instead of `\\` as path separators on Windows for logging config file location - 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 ### Removed

View file

@ -400,27 +400,33 @@ impl Display {
let mut rects = lines.into_rects(&metrics, &size_info); 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() { if let Some(message) = message_buffer.message() {
let text = message.text(&size_info); let text = message.text(&size_info);
// Create a new rectangle for the background // Create a new rectangle for the background
let start_line = size_info.lines().0 - text.len(); let start_line = size_info.lines().0 - text.len();
let y = size_info.padding_y + size_info.cell_height * start_line as f32; let y = size_info.padding_y + size_info.cell_height * start_line as f32;
rects.push(RenderRect::new( let message_bar_rect =
0., RenderRect::new(0., y, size_info.width, size_info.height - y, message.color(), 1.);
y,
size_info.width,
size_info.height - y,
message.color(),
));
// Draw rectangles including the new background // Push message_bar in the end, so it'll be above all other content
self.renderer.draw_rects( rects.push(message_bar_rect);
&size_info,
config.visual_bell.color, // Draw rectangles
visual_bell_intensity, self.renderer.draw_rects(&size_info, rects);
rects,
);
// Relay messages to the user // Relay messages to the user
let mut offset = 1; let mut offset = 1;
@ -437,12 +443,7 @@ impl Display {
} }
} else { } else {
// Draw rectangles // Draw rectangles
self.renderer.draw_rects( self.renderer.draw_rects(&size_info, rects);
&size_info,
config.visual_bell.color,
visual_bell_intensity,
rects,
);
} }
// Draw render timer // Draw render timer

View file

@ -713,13 +713,7 @@ impl QuadRenderer {
} }
// Draw all rectangles simultaneously to prevent excessive program swaps // Draw all rectangles simultaneously to prevent excessive program swaps
pub fn draw_rects( pub fn draw_rects(&mut self, props: &term::SizeInfo, rects: Vec<RenderRect>) {
&mut self,
props: &term::SizeInfo,
visual_bell_color: Rgb,
visual_bell_intensity: f64,
cell_line_rects: Vec<RenderRect>,
) {
// Swap to rectangle rendering program // Swap to rectangle rendering program
unsafe { unsafe {
// Swap program // Swap program
@ -729,7 +723,7 @@ impl QuadRenderer {
gl::Viewport(0, 0, props.width as i32, props.height as i32); gl::Viewport(0, 0, props.width as i32, props.height as i32);
// Change blending strategy // 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 // Setup data and buffers
gl::BindVertexArray(self.rect_vao); gl::BindVertexArray(self.rect_vao);
@ -747,13 +741,9 @@ impl QuadRenderer {
gl::EnableVertexAttribArray(0); gl::EnableVertexAttribArray(0);
} }
// Draw visual bell // Draw all the rects
let rect = RenderRect::new(0., 0., props.width, props.height, visual_bell_color); for rect in rects {
self.render_rect(&rect, visual_bell_intensity as f32, props); self.render_rect(&rect, props);
// Draw underlines and strikeouts
for cell_line_rect in cell_line_rects {
self.render_rect(&cell_line_rect, 255., props);
} }
// Deactivate rectangle program again // Deactivate rectangle program again
@ -881,9 +871,9 @@ impl QuadRenderer {
// Render a rectangle // Render a rectangle
// //
// This requires the rectangle program to be activated // 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 // Do nothing when alpha is fully transparent
if alpha == 0. { if rect.alpha == 0. {
return; return;
} }
@ -908,7 +898,7 @@ impl QuadRenderer {
); );
// Color // Color
self.rect_program.set_color(rect.color, alpha); self.rect_program.set_color(rect.color, rect.alpha);
// Draw the rectangle // Draw the rectangle
gl::DrawElements(gl::TRIANGLES, 6, gl::UNSIGNED_INT, ptr::null()); gl::DrawElements(gl::TRIANGLES, 6, gl::UNSIGNED_INT, ptr::null());

View file

@ -27,11 +27,12 @@ pub struct RenderRect {
pub width: f32, pub width: f32,
pub height: f32, pub height: f32,
pub color: Rgb, pub color: Rgb,
pub alpha: f32,
} }
impl RenderRect { impl RenderRect {
pub fn new(x: f32, y: f32, width: f32, height: f32, color: Rgb) -> Self { pub fn new(x: f32, y: f32, width: f32, height: f32, color: Rgb, alpha: f32) -> Self {
RenderRect { x, y, width, height, color } RenderRect { x, y, width, height, color, alpha }
} }
} }
@ -65,7 +66,7 @@ impl RenderLine {
y = max_y; 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.)
} }
} }