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.
This commit is contained in:
Kirill Chibisov 2021-08-16 14:49:14 +03:00 committed by GitHub
parent 9a8ae43c0a
commit c24d7dfd0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 39 additions and 19 deletions

View file

@ -7,9 +7,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## 0.10.0-dev
### Added
- Option `colors.transparent_background_colors` to allow applying opacity to all background colors
### Changed
- `ExpandSelection` is now a configurable mouse binding action
- Config option `background_opacity`, you should use `window.opacity` instead
## 0.9.0

View file

@ -63,6 +63,12 @@
# - buttonless: Title bar, transparent background and no title bar buttons
#decorations: full
# Background opacity
#
# Window opacity as a floating point number from `0.0` to `1.0`.
# The value `0.0` is completely transparent and `1.0` is opaque.
#opacity: 1.0
# Startup Mode (changes require restart)
#
# Values for `startup_mode`:
@ -312,6 +318,13 @@
#
#indexed_colors: []
# Transparent cell backgrounds
#
# Whether or not `window.opacity` applies to all cell backgrounds or only to
# the default background. When set to `true` all cells will be transparent
# regardless of their background color.
#transparent_background_colors: false
# Bell
#
# The bell is rung every time the BEL control character is received.
@ -353,12 +366,6 @@
#
#command: None
# Background opacity
#
# Window opacity as a floating point number from `0.0` to `1.0`.
# The value `0.0` is completely transparent and `1.0` is opaque.
#background_opacity: 1.0
#selection:
# This string contains all characters that are used as separators for
# "semantic words" in Alacritty.

View file

@ -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);

View file

@ -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);
}

View file

@ -17,6 +17,7 @@ pub struct Colors {
pub search: SearchColors,
pub line_indicator: LineIndicatorColors,
pub hints: HintColors,
pub transparent_background_colors: bool,
}
impl Colors {

View file

@ -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]

View file

@ -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(),
}

View file

@ -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.
}

View file

@ -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.

View file

@ -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());

View file

@ -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,