1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 05:42:03 +03:00

wayland: fix unintentional blend with other windows

@jsgf mentioned this to me, and since I've started running "proper"
wayland gnome-shell/mutter on my pixelbook go, I'm seeing it too.

The issue is that the alpha values are potentially <1.0 when they
are committed to the frame buffer and the mutter compositor is
faithfully blending wezterm with the window behind it, leading to
weird looking effects such as varying brightness of text, or for
cases where the window behind wezterm is bright white, a halo
effect that makes the text less sharp.

This commit addresses this issue by asking glium to ask opengl to
set the destination alpha to 1.0 in the final draw stage.
This commit is contained in:
Wez Furlong 2019-12-27 19:12:19 -08:00
parent de3ffb3428
commit c8cd600706

View File

@ -14,7 +14,7 @@ use crate::mux::window::WindowId as MuxWindowId;
use crate::mux::Mux;
use ::window::bitmaps::atlas::{OutOfTextureSpace, SpriteSlice};
use ::window::bitmaps::Texture2d;
use ::window::glium::{uniform, Surface};
use ::window::glium::{uniform, BlendingFunction, LinearBlendingFactor, Surface};
use ::window::*;
use anyhow::{anyhow, bail, ensure};
use portable_pty::PtySize;
@ -1392,7 +1392,8 @@ impl TermWindow {
.to_column_arrays();
let draw_params = glium::DrawParameters {
blend: glium::Blend::alpha_blending(),
// No alpha blending for the background layer: let's make
// sure that our background pixels are at 100% opacity.
..Default::default()
};
@ -1411,6 +1412,28 @@ impl TermWindow {
&draw_params,
)?;
let draw_params = glium::DrawParameters {
blend: glium::Blend {
color: BlendingFunction::Addition {
source: LinearBlendingFactor::SourceAlpha,
destination: LinearBlendingFactor::OneMinusSourceAlpha,
},
alpha: BlendingFunction::Addition {
source: LinearBlendingFactor::SourceAlpha,
// On Wayland, the compositor takes the destination alpha
// value and blends with the window behind our own, which
// can make the text look brighter or less sharp.
// We set the destination alpha to 1.0 to prevent that
// from happening.
// (The normal alpha blending operation would set this to
// OneMinusSourceAlpha).
destination: LinearBlendingFactor::One,
},
constant_value: (0.0, 0.0, 0.0, 0.0),
},
..Default::default()
};
// Pass 2: Draw glyphs
frame.draw(
&*vb,