aboutsummaryrefslogtreecommitdiff
path: root/alacritty
diff options
context:
space:
mode:
authorKirill Chibisov <contact@kchibisov.com>2021-08-16 14:49:14 +0300
committerGitHub <noreply@github.com>2021-08-16 14:49:14 +0300
commitc24d7dfd0d2d8849f0398d7cb1a65d6562ee7a0d (patch)
tree07470a57149be0fdb907ffb33ccd124dfb57848a /alacritty
parent9a8ae43c0aa9e598411964c458c88f58d6ec41d8 (diff)
downloadr-alacritty-c24d7dfd0d2d8849f0398d7cb1a65d6562ee7a0d.tar.gz
r-alacritty-c24d7dfd0d2d8849f0398d7cb1a65d6562ee7a0d.tar.bz2
r-alacritty-c24d7dfd0d2d8849f0398d7cb1a65d6562ee7a0d.zip
Add option to apply opacity to all background colors
In some cases it could be desired to apply 'background_opacity' to all background colors instead of just 'colors.primary.background', thus adding an 'colors.opaque_background_colors' option to control that. Fixes #741.
Diffstat (limited to 'alacritty')
-rw-r--r--alacritty/res/text.f.glsl2
-rw-r--r--alacritty/res/text.v.glsl2
-rw-r--r--alacritty/src/config/color.rs1
-rw-r--r--alacritty/src/config/ui_config.rs9
-rw-r--r--alacritty/src/config/window.rs8
-rw-r--r--alacritty/src/display/content.rs6
-rw-r--r--alacritty/src/display/mod.rs2
-rw-r--r--alacritty/src/event.rs2
-rw-r--r--alacritty/src/renderer/mod.rs2
9 files changed, 21 insertions, 13 deletions
diff --git a/alacritty/res/text.f.glsl b/alacritty/res/text.f.glsl
index d5e26881..5b4e3da6 100644
--- a/alacritty/res/text.f.glsl
+++ b/alacritty/res/text.f.glsl
@@ -18,7 +18,7 @@ void main() {
}
alphaMask = vec4(1.0);
- color = vec4(bg.rgb, 1.0);
+ color = vec4(bg.rgb, bg.a);
} else if ((int(fg.a) & COLORED) != 0) {
// Color glyphs, like emojis.
vec4 glyphColor = texture(mask, TexCoords);
diff --git a/alacritty/res/text.v.glsl b/alacritty/res/text.v.glsl
index 31e6f934..a4a31382 100644
--- a/alacritty/res/text.v.glsl
+++ b/alacritty/res/text.v.glsl
@@ -65,6 +65,6 @@ void main() {
TexCoords = uvOffset + position * uvSize;
}
- bg = vec4(backgroundColor.rgb / 255.0, backgroundColor.a);
+ bg = backgroundColor / 255.0;
fg = vec4(textColor.rgb / 255.0, textColor.a);
}
diff --git a/alacritty/src/config/color.rs b/alacritty/src/config/color.rs
index ddb1da29..c0076edb 100644
--- a/alacritty/src/config/color.rs
+++ b/alacritty/src/config/color.rs
@@ -17,6 +17,7 @@ pub struct Colors {
pub search: SearchColors,
pub line_indicator: LineIndicatorColors,
pub hints: HintColors,
+ pub transparent_background_colors: bool,
}
impl Colors {
diff --git a/alacritty/src/config/ui_config.rs b/alacritty/src/config/ui_config.rs
index cf0f9298..f0917cf5 100644
--- a/alacritty/src/config/ui_config.rs
+++ b/alacritty/src/config/ui_config.rs
@@ -69,7 +69,8 @@ pub struct UiConfig {
mouse_bindings: MouseBindings,
/// Background opacity from 0.0 to 1.0.
- background_opacity: Percentage,
+ #[config(deprecated = "use window.opacity instead")]
+ window_opacity: Option<Percentage>,
}
impl Default for UiConfig {
@@ -84,7 +85,7 @@ impl Default for UiConfig {
config_paths: Default::default(),
key_bindings: Default::default(),
mouse_bindings: Default::default(),
- background_opacity: Default::default(),
+ window_opacity: Default::default(),
bell: Default::default(),
colors: Default::default(),
draw_bold_text_with_bright_colors: Default::default(),
@@ -115,8 +116,8 @@ impl UiConfig {
}
#[inline]
- pub fn background_opacity(&self) -> f32 {
- self.background_opacity.as_f32()
+ pub fn window_opacity(&self) -> f32 {
+ self.window_opacity.unwrap_or(self.window.opacity).as_f32()
}
#[inline]
diff --git a/alacritty/src/config/window.rs b/alacritty/src/config/window.rs
index d74390d8..f7a7511c 100644
--- a/alacritty/src/config/window.rs
+++ b/alacritty/src/config/window.rs
@@ -7,7 +7,7 @@ use serde::de::{self, MapAccess, Visitor};
use serde::{Deserialize, Deserializer};
use alacritty_config_derive::ConfigDeserialize;
-use alacritty_terminal::config::LOG_TARGET_CONFIG;
+use alacritty_terminal::config::{Percentage, LOG_TARGET_CONFIG};
use alacritty_terminal::index::Column;
use crate::config::ui_config::Delta;
@@ -15,7 +15,7 @@ use crate::config::ui_config::Delta;
/// Default Alacritty name, used for window title and class.
pub const DEFAULT_NAME: &str = "Alacritty";
-#[derive(ConfigDeserialize, Debug, Clone, PartialEq, Eq)]
+#[derive(ConfigDeserialize, Debug, Clone, PartialEq)]
pub struct WindowConfig {
/// Initial position.
pub position: Option<Delta<i32>>,
@@ -45,6 +45,9 @@ pub struct WindowConfig {
/// Window class.
pub class: Class,
+ /// Background opacity from 0.0 to 1.0.
+ pub opacity: Percentage,
+
/// Pixel padding.
padding: Delta<u8>,
@@ -64,6 +67,7 @@ impl Default for WindowConfig {
gtk_theme_variant: Default::default(),
dynamic_padding: Default::default(),
class: Default::default(),
+ opacity: Default::default(),
padding: Default::default(),
dimensions: Default::default(),
}
diff --git a/alacritty/src/display/content.rs b/alacritty/src/display/content.rs
index 05bd0438..2deb3d3e 100644
--- a/alacritty/src/display/content.rs
+++ b/alacritty/src/display/content.rs
@@ -203,7 +203,7 @@ impl RenderableCell {
mem::swap(&mut fg, &mut bg);
1.0
} else {
- Self::compute_bg_alpha(cell.bg)
+ Self::compute_bg_alpha(&content.config.ui_config, cell.bg)
};
let is_selected = content.terminal_content.selection.map_or(false, |selection| {
@@ -350,9 +350,11 @@ impl RenderableCell {
/// using the named input color, rather than checking the RGB of the background after its color
/// is computed.
#[inline]
- fn compute_bg_alpha(bg: Color) -> f32 {
+ fn compute_bg_alpha(config: &UiConfig, bg: Color) -> f32 {
if bg == Color::Named(NamedColor::Background) {
0.
+ } else if config.colors.transparent_background_colors {
+ config.window_opacity()
} else {
1.
}
diff --git a/alacritty/src/display/mod.rs b/alacritty/src/display/mod.rs
index cce3c8bd..d4c5c274 100644
--- a/alacritty/src/display/mod.rs
+++ b/alacritty/src/display/mod.rs
@@ -299,7 +299,7 @@ impl Display {
// Disable shadows for transparent windows on macOS.
#[cfg(target_os = "macos")]
- window.set_has_shadow(config.ui_config.background_opacity() >= 1.0);
+ window.set_has_shadow(config.ui_config.window_opacity() >= 1.0);
// On Wayland we can safely ignore this call, since the window isn't visible until you
// actually draw something into it and commit those changes.
diff --git a/alacritty/src/event.rs b/alacritty/src/event.rs
index bc9c305a..cc817f6e 100644
--- a/alacritty/src/event.rs
+++ b/alacritty/src/event.rs
@@ -1436,7 +1436,7 @@ impl<N: Notify + OnResize> Processor<N> {
// Disable shadows for transparent windows on macOS.
#[cfg(target_os = "macos")]
- processor.ctx.window().set_has_shadow(config.ui_config.background_opacity() >= 1.0);
+ processor.ctx.window().set_has_shadow(config.ui_config.window_opacity() >= 1.0);
// Update hint keys.
processor.ctx.display.hint_state.update_alphabet(config.ui_config.hints.alphabet());
diff --git a/alacritty/src/renderer/mod.rs b/alacritty/src/renderer/mod.rs
index 5f71ddf5..11ccfc63 100644
--- a/alacritty/src/renderer/mod.rs
+++ b/alacritty/src/renderer/mod.rs
@@ -767,7 +767,7 @@ impl Drop for QuadRenderer {
impl<'a> RenderApi<'a> {
pub fn clear(&self, color: Rgb) {
unsafe {
- let alpha = self.config.background_opacity();
+ let alpha = self.config.window_opacity();
gl::ClearColor(
(f32::from(color.r) / 255.0).min(1.0) * alpha,
(f32::from(color.g) / 255.0).min(1.0) * alpha,