diff options
author | Mark Andrus Roberts <mroberts@twilio.com> | 2017-02-03 15:34:52 -0800 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2017-02-07 21:12:56 -0800 |
commit | fbc7b7227171b41d96ca52df52e4cf1833f5fc6f (patch) | |
tree | 8f33bd12933b129ec751f5dd643387eae254030f /src/renderer/mod.rs | |
parent | 92e1cec0880313d962d80bf16eca60cebb509eab (diff) | |
download | alacritty-fbc7b7227171b41d96ca52df52e4cf1833f5fc6f.tar.gz alacritty-fbc7b7227171b41d96ca52df52e4cf1833f5fc6f.zip |
Add visual bell support
This commit adds support for a visual bell. Although the Handler in src/ansi.rs
warns "Hopefully this is never implemented", I wanted to give it a try. A new
config option is added, `visual_bell`, which sets the `duration` and `animation`
function of the visual bell. The default `duration` is 150 ms, and the default
`animation` is `EaseOutExpo`. To disable the visual bell, set its duration to 0.
The visual bell is modeled by VisualBell in src/term/mod.rs. It has a method to
ring the bell, `ring`, and another method, `intensity`. Both return the
"intensity" of the bell, which ramps down from 1.0 to 0.0 at a rate set by
`duration` and `animation`.
Whether or not the Processor waits for events is now configurable in order to
allow for smooth drawing of the visual bell.
Diffstat (limited to 'src/renderer/mod.rs')
-rw-r--r-- | src/renderer/mod.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index fe4ff29f..2d466f79 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -110,6 +110,9 @@ pub struct ShaderProgram { /// Cell dimensions (pixels) u_cell_dim: GLint, + /// Visual bell + u_visual_bell: GLint, + /// Background pass flag /// /// Rendering is split into two passes; 1 for backgrounds, and one for text @@ -321,6 +324,7 @@ pub struct RenderApi<'a> { atlas: &'a mut Vec<Atlas>, program: &'a mut ShaderProgram, colors: &'a ColorList, + visual_bell: f32, } #[derive(Debug)] @@ -646,6 +650,7 @@ impl QuadRenderer { atlas: &mut self.atlas, program: &mut self.program, colors: config.color_list(), + visual_bell: 0.0, }); unsafe { @@ -708,13 +713,18 @@ impl QuadRenderer { } impl<'a> RenderApi<'a> { + pub fn set_visual_bell(&mut self, visual_bell: f32) { + self.visual_bell = visual_bell; + self.program.set_visual_bell(visual_bell); + } + pub fn clear(&self) { let color = self.colors[NamedColor::Background]; unsafe { gl::ClearColor( - color.r as f32 / 255.0, - color.g as f32 / 255.0, - color.b as f32 / 255.0, + (self.visual_bell + color.r as f32 / 255.0).min(1.0), + (self.visual_bell + color.g as f32 / 255.0).min(1.0), + (self.visual_bell + color.b as f32 / 255.0).min(1.0), 1.0 ); gl::Clear(gl::COLOR_BUFFER_BIT); @@ -736,7 +746,6 @@ impl<'a> RenderApi<'a> { } unsafe { - self.program.set_background_pass(true); gl::DrawElementsInstanced(gl::TRIANGLES, 6, gl::UNSIGNED_INT, ptr::null(), @@ -941,11 +950,12 @@ impl ShaderProgram { } // get uniform locations - let (projection, term_dim, cell_dim, background) = unsafe { + let (projection, term_dim, cell_dim, visual_bell, background) = unsafe { ( gl::GetUniformLocation(program, cptr!(b"projection\0")), gl::GetUniformLocation(program, cptr!(b"termDim\0")), gl::GetUniformLocation(program, cptr!(b"cellDim\0")), + gl::GetUniformLocation(program, cptr!(b"visualBell\0")), gl::GetUniformLocation(program, cptr!(b"backgroundPass\0")), ) }; @@ -957,6 +967,7 @@ impl ShaderProgram { u_projection: projection, u_term_dim: term_dim, u_cell_dim: cell_dim, + u_visual_bell: visual_bell, u_background: background, }; @@ -988,6 +999,12 @@ impl ShaderProgram { } } + fn set_visual_bell(&self, visual_bell: f32) { + unsafe { + gl::Uniform1f(self.u_visual_bell, visual_bell); + } + } + fn set_background_pass(&self, background_pass: bool) { let value = if background_pass { 1 |