1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2025-02-17 15:57:08 -05:00

Make visual bell flash color customizable

This addresses the main feedback in jwilm/alacritty/pull/430. I've
decided to go from scratch instead of basing my work on top of what
markandrus has already implemented to keep it as simple as possible.

If there's any stuff that I should take from the other PR, please let me
know. I can also try to send a PR to markandrus.
This commit is contained in:
Christian Dürr 2017-12-24 16:25:06 +01:00 committed by Christian Duerr
parent 03f9e0cd9a
commit d40f3b04f0
No known key found for this signature in database
GPG key ID: 85CDAE3C164BA7B4
4 changed files with 49 additions and 8 deletions

View file

@ -15,6 +15,7 @@
in vec2 TexCoords;
in vec3 fg;
in vec4 bg;
in vec3 vbc;
flat in float vb;
flat in int background;
@ -31,7 +32,11 @@ void main()
discard;
alphaMask = vec4(1.0);
color = vec4(bg.rgb + vb, 1.0);
if (vb == 0) {
color = vec4(bg.rgb, 1.0);
} else {
color = vec4(vbc, vb);
}
} else {
vec3 textColor = texture(mask, TexCoords).rgb;
alphaMask = vec4(textColor, textColor.r);

View file

@ -25,18 +25,21 @@ layout (location = 3) in vec4 uv;
// text fg color
layout (location = 4) in vec3 textColor;
// Background color
layout (location = 5) in vec4 backgroundColor;
out vec2 TexCoords;
out vec3 fg;
out vec4 bg;
out vec3 vbc;
// Terminal properties
uniform vec2 termDim;
uniform vec2 cellDim;
uniform float visualBell;
uniform vec3 visualBellColor;
uniform int backgroundPass;
// Orthographic projection
@ -74,6 +77,7 @@ void main()
}
vb = visualBell;
vbc = visualBellColor;
background = backgroundPass;
bg = vec4(backgroundColor.rgb / 255.0, backgroundColor.a);
fg = textColor / vec3(255.0, 255.0, 255.0);

View file

@ -150,6 +150,10 @@ pub struct VisualBellConfig {
#[serde(deserialize_with = "deserialize_visual_bell_duration")]
#[serde(default="default_visual_bell_duration")]
duration: u16,
/// Visual bell flash color
#[serde(default="default_visual_bell_color", deserialize_with = "rgb_from_hex")]
color: Rgb,
}
fn default_visual_bell_duration() -> u16 {
@ -168,6 +172,10 @@ fn deserialize_visual_bell_duration<'a, D>(deserializer: D) -> ::std::result::Re
}
}
fn default_visual_bell_color() -> Rgb {
Rgb { r: 255, g: 255, b: 255 }
}
impl VisualBellConfig {
/// Visual bell animation
#[inline]
@ -180,6 +188,12 @@ impl VisualBellConfig {
pub fn duration(&self) -> Duration {
Duration::from_millis(u64::from(self.duration))
}
/// Visual bell flash color
#[inline]
pub fn color(&self) -> Rgb {
self.color
}
}
impl Default for VisualBellConfig {
@ -187,6 +201,7 @@ impl Default for VisualBellConfig {
VisualBellConfig {
animation: VisualBellAnimation::default(),
duration: default_visual_bell_duration(),
color: default_visual_bell_color(),
}
}
}

View file

@ -118,6 +118,9 @@ pub struct ShaderProgram {
/// Visual bell
u_visual_bell: GLint,
/// Visual bell color
u_visual_bell_color: GLint,
/// Background pass flag
///
/// Rendering is split into two passes; 1 for backgrounds, and one for text
@ -644,10 +647,12 @@ impl QuadRenderer {
}
}
let visual_bell_color = config.visual_bell().color();
unsafe {
self.program.activate();
self.program.set_term_uniforms(props);
self.program.set_visual_bell(visual_bell_intensity as _);
self.program.set_visual_bell(visual_bell_intensity as _, visual_bell_color);
gl::BindVertexArray(self.vao);
gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, self.ebo);
@ -734,16 +739,21 @@ impl QuadRenderer {
}
}
fn mix(x: f32, y: f32, a: f32) -> f32 {
x * (1.0 - a) + y * a
}
impl<'a> RenderApi<'a> {
pub fn clear(&self, color: Rgb) {
let alpha = self.config.background_opacity().get();
let (flash, intensity) = (self.config.visual_bell().color(), self.visual_bell_intensity);
unsafe {
gl::ClearColor(
(self.visual_bell_intensity + f32::from(color.r) / 255.0).min(1.0) * alpha,
(self.visual_bell_intensity + f32::from(color.g) / 255.0).min(1.0) * alpha,
(self.visual_bell_intensity + f32::from(color.b) / 255.0).min(1.0) * alpha,
mix(color.r as f32 / 255.0, flash.r as f32 / 255.0, intensity).min(1.0) * alpha,
mix(color.g as f32 / 255.0, flash.g as f32 / 255.0, intensity).min(1.0) * alpha,
mix(color.b as f32 / 255.0, flash.b as f32 / 255.0, intensity).min(1.0) * alpha,
alpha
);
);
gl::Clear(gl::COLOR_BUFFER_BIT);
}
}
@ -998,12 +1008,13 @@ impl ShaderProgram {
}
// get uniform locations
let (projection, term_dim, cell_dim, visual_bell, background) = unsafe {
let (projection, term_dim, cell_dim, visual_bell, visual_bell_color, 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"visualBellColor\0")),
gl::GetUniformLocation(program, cptr!(b"backgroundPass\0")),
)
};
@ -1016,6 +1027,7 @@ impl ShaderProgram {
u_term_dim: term_dim,
u_cell_dim: cell_dim,
u_visual_bell: visual_bell,
u_visual_bell_color: visual_bell_color,
u_background: background,
padding_x: config.padding().x.floor(),
padding_y: config.padding().y.floor(),
@ -1061,9 +1073,14 @@ impl ShaderProgram {
}
}
fn set_visual_bell(&self, visual_bell: f32) {
fn set_visual_bell(&self, visual_bell: f32, vb_color: Rgb) {
unsafe {
gl::Uniform1f(self.u_visual_bell, visual_bell);
gl::Uniform3f(self.u_visual_bell_color,
vb_color.r as f32 / 255.,
vb_color.g as f32 / 255.,
vb_color.b as f32 / 255.
);
}
}