Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

feat(windows): try drawing through DirectComposition for acrylic

RoversXda555a2aa86e
diff --git a/config/src/background.rs b/config/src/background.rs
index 3dc21369..4e018b19 100644
--- a/config/src/background.rs
+++ b/config/src/background.rs
@@ -304,17 +304,16 @@ pub enum SystemBackdrop {
/// Another way of asking Windows for its acrylic backdrop, to find one that
/// shows it behind a window drawn with OpenGL: asked for the usual way, it
/// comes out opaque there (wezterm#6265). `Off` asks the usual way.
-/// `System` and `SystemBlur` ask for the system backdrop over the whole
-/// window, without and with the blur behind that lets the window's own
-/// alpha through; `Accent` asks with the undocumented accent policy, as on
-/// Windows 10, even where the system backdrop exists.
+/// `Accent` asks with the undocumented accent policy, as on Windows 10,
+/// even where the system backdrop exists. `Composition` draws through
+/// ANGLE onto a DirectComposition surface, whose alpha the system backdrop
+/// shows through; a window takes it, or leaves it, when opened.
#[derive(Debug, Copy, Clone, FromDynamic, ToDynamic, PartialEq, Eq, Default)]
pub enum Win32BackdropTrial {
#[default]
Off,
- System,
- SystemBlur,
Accent,
+ Composition,
}
pub fn default_win32_acrylic_accent_color() -> RgbaColor {
diff --git a/thinkterm-i18n/i18n/de-DE.ftl b/thinkterm-i18n/i18n/de-DE.ftl
index 666e4021..1aa355dc 100644
--- a/thinkterm-i18n/i18n/de-DE.ftl
+++ b/thinkterm-i18n/i18n/de-DE.ftl
@@ -124,11 +124,10 @@ settings-window-opacity-default = Standard
settings-window-opacity-reset = Zurücksetzen
settings-window-opacity-platforms = Unter Linux noch nicht verfügbar, unter Windows noch nicht stabil.
settings-windows-backdrop = Milchglas (Test)
-settings-windows-backdrop-description = Probiert aus, welche Methode unter Windows 11 Milchglas zeigt: zuerst den Renderer auf OpenGL stellen und die Deckkraft unter 100 % setzen.
+settings-windows-backdrop-description = Probiert aus, welche Methode unter Windows 11 Milchglas zeigt: zuerst den Renderer auf OpenGL stellen und die Deckkraft unter 100 % setzen. Methode 4 wirkt in Fenstern, die danach geöffnet werden.
settings-windows-backdrop-off = Aus
settings-windows-backdrop-accent = Methode 1
-settings-windows-backdrop-system = Methode 2
-settings-windows-backdrop-system-blur = Methode 3
+settings-windows-backdrop-composition = Methode 4
settings-badge-beta = Beta
settings-app-icon-simple = Blaue Pille
settings-app-icon-red = Rote Pille
diff --git a/thinkterm-i18n/i18n/en-US.ftl b/thinkterm-i18n/i18n/en-US.ftl
index df2e8bbb..f60d6407 100644
--- a/thinkterm-i18n/i18n/en-US.ftl
+++ b/thinkterm-i18n/i18n/en-US.ftl
@@ -124,11 +124,10 @@ settings-window-opacity-default = Default
settings-window-opacity-reset = Reset to Default
settings-window-opacity-platforms = Not available on Linux yet, and not yet stable on Windows.
settings-windows-backdrop = Frosted glass (trial)
-settings-windows-backdrop-description = Tries which way shows frosted glass on Windows 11: first switch the renderer to OpenGL and set the opacity below 100%.
+settings-windows-backdrop-description = Tries which way shows frosted glass on Windows 11: first switch the renderer to OpenGL and set the opacity below 100%. Way 4 takes effect in windows opened after it.
settings-windows-backdrop-off = Off
settings-windows-backdrop-accent = Way 1
-settings-windows-backdrop-system = Way 2
-settings-windows-backdrop-system-blur = Way 3
+settings-windows-backdrop-composition = Way 4
settings-badge-beta = Beta
settings-app-icon-simple = Blue Pill
settings-app-icon-red = Red Pill
diff --git a/thinkterm-i18n/i18n/fr-FR.ftl b/thinkterm-i18n/i18n/fr-FR.ftl
index 74561df2..4964769a 100644
--- a/thinkterm-i18n/i18n/fr-FR.ftl
+++ b/thinkterm-i18n/i18n/fr-FR.ftl
@@ -124,11 +124,10 @@ settings-window-opacity-default = Par défaut
settings-window-opacity-reset = Rétablir
settings-window-opacity-platforms = Pas encore disponible sous Linux, pas encore stable sous Windows.
settings-windows-backdrop = Verre dépoli (essai)
-settings-windows-backdrop-description = Essaie quelle méthode donne du verre dépoli sous Windows 11 : passez d'abord le rendu en OpenGL et l'opacité sous 100 %.
+settings-windows-backdrop-description = Essaie quelle méthode donne du verre dépoli sous Windows 11 : passez d'abord le rendu en OpenGL et l'opacité sous 100 %. La méthode 4 s'applique aux fenêtres ouvertes ensuite.
settings-windows-backdrop-off = Désactivé
settings-windows-backdrop-accent = Méthode 1
-settings-windows-backdrop-system = Méthode 2
-settings-windows-backdrop-system-blur = Méthode 3
+settings-windows-backdrop-composition = Méthode 4
settings-badge-beta = Bêta
settings-app-icon-simple = Pilule bleue
settings-app-icon-red = Pilule rouge
diff --git a/thinkterm-i18n/i18n/ja-JP.ftl b/thinkterm-i18n/i18n/ja-JP.ftl
index acd055ff..c0eef2cc 100644
--- a/thinkterm-i18n/i18n/ja-JP.ftl
+++ b/thinkterm-i18n/i18n/ja-JP.ftl
@@ -121,11 +121,10 @@ settings-window-opacity-default = デフォルト
settings-window-opacity-reset = デフォルトに戻す
settings-window-opacity-platforms = Linux では未対応、Windows ではまだ安定していません。
settings-windows-backdrop = すりガラス(試験)
-settings-windows-backdrop-description = Windows 11 でどの方法ですりガラスになるかを試します。先にレンダラーを OpenGL にし、不透明度を 100% 未満にしてください。
+settings-windows-backdrop-description = Windows 11 でどの方法ですりガラスになるかを試します。先にレンダラーを OpenGL にし、不透明度を 100% 未満にしてください。方法 4 は開き直したウインドウから効きます。
settings-windows-backdrop-off = オフ
settings-windows-backdrop-accent = 方法 1
-settings-windows-backdrop-system = 方法 2
-settings-windows-backdrop-system-blur = 方法 3
+settings-windows-backdrop-composition = 方法 4
settings-badge-beta = ベータ
settings-app-icon-simple = 青いピル
settings-app-icon-red = 赤いピル
diff --git a/thinkterm-i18n/i18n/zh-CN.ftl b/thinkterm-i18n/i18n/zh-CN.ftl
index 662508c9..f5025674 100644
--- a/thinkterm-i18n/i18n/zh-CN.ftl
+++ b/thinkterm-i18n/i18n/zh-CN.ftl
@@ -121,11 +121,10 @@ settings-window-opacity-default = 默认
settings-window-opacity-reset = 恢复默认
settings-window-opacity-platforms = Linux 暂时不支持,Windows 上还不够稳定。
settings-windows-backdrop = 毛玻璃方式(试验)
-settings-windows-backdrop-description = 在 Windows 11 上试哪种能透出毛玻璃:先把渲染器换成 OpenGL,透明度调到 100% 以下。
+settings-windows-backdrop-description = 在 Windows 11 上试哪种能透出毛玻璃:先把渲染器换成 OpenGL,透明度调到 100% 以下。方式四要重新打开窗口才生效。
settings-windows-backdrop-off = 关
settings-windows-backdrop-accent = 方式一
-settings-windows-backdrop-system = 方式二
-settings-windows-backdrop-system-blur = 方式三
+settings-windows-backdrop-composition = 方式四
settings-badge-beta = Beta
settings-app-icon-simple = 蓝色药丸
settings-app-icon-red = 红色药丸
diff --git a/wezterm-gui/src/native_settings.rs b/wezterm-gui/src/native_settings.rs
index a3a508f2..d1b6a4c7 100644
--- a/wezterm-gui/src/native_settings.rs
+++ b/wezterm-gui/src/native_settings.rs
@@ -435,20 +435,18 @@ pub(crate) enum NativeWindowsBackdrop {
#[default]
Off,
Accent,
- System,
- SystemBlur,
+ Composition,
}
impl NativeWindowsBackdrop {
/// Every way, in the order the settings window offers them.
- pub(crate) const ALL: [Self; 4] = [Self::Off, Self::Accent, Self::System, Self::SystemBlur];
+ pub(crate) const ALL: [Self; 3] = [Self::Off, Self::Accent, Self::Composition];
fn trial(self) -> config::Win32BackdropTrial {
match self {
Self::Off => config::Win32BackdropTrial::Off,
Self::Accent => config::Win32BackdropTrial::Accent,
- Self::System => config::Win32BackdropTrial::System,
- Self::SystemBlur => config::Win32BackdropTrial::SystemBlur,
+ Self::Composition => config::Win32BackdropTrial::Composition,
}
}
}
@@ -2964,7 +2962,9 @@ mod tests {
.appearance
.windows_backdrop
};
- assert_eq!(read(r#""system_blur""#), NativeWindowsBackdrop::SystemBlur);
+ assert_eq!(read(r#""composition""#), NativeWindowsBackdrop::Composition);
+ // Ways tried and dropped read as off, as one not known yet does.
+ assert_eq!(read(r#""system_blur""#), NativeWindowsBackdrop::Off);
assert_eq!(read(r#""something_new""#), NativeWindowsBackdrop::Off);
}
diff --git a/wezterm-gui/src/renderer_choice.rs b/wezterm-gui/src/renderer_choice.rs
index fa5fbb5b..2d7c0d6f 100644
--- a/wezterm-gui/src/renderer_choice.rs
+++ b/wezterm-gui/src/renderer_choice.rs
@@ -28,6 +28,11 @@ fn failure_record(backend: NativeRendererBackend) -> &'static std::thread::Local
}
}
+/// Whether `backend` has failed to come up in a window on this thread.
+pub(crate) fn has_failed(backend: NativeRendererBackend) -> bool {
+ failure_record(backend).with(Cell::get)
+}
+
fn label(backend: NativeRendererBackend) -> &'static str {
match backend {
NativeRendererBackend::WebGpu => "WebGPU",
diff --git a/wezterm-gui/src/settings_window.rs b/wezterm-gui/src/settings_window.rs
index 9cfee7a1..9e2ddc6d 100644
--- a/wezterm-gui/src/settings_window.rs
+++ b/wezterm-gui/src/settings_window.rs
@@ -1512,8 +1512,7 @@ fn localized_windows_backdrop_label(backdrop: NativeWindowsBackdrop) -> String {
crate::i18n::tr(match backdrop {
NativeWindowsBackdrop::Off => "settings-windows-backdrop-off",
NativeWindowsBackdrop::Accent => "settings-windows-backdrop-accent",
- NativeWindowsBackdrop::System => "settings-windows-backdrop-system",
- NativeWindowsBackdrop::SystemBlur => "settings-windows-backdrop-system-blur",
+ NativeWindowsBackdrop::Composition => "settings-windows-backdrop-composition",
})
}
diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs
index 93e182af..2a959fa9 100644
--- a/wezterm-gui/src/termwindow/mod.rs
+++ b/wezterm-gui/src/termwindow/mod.rs
@@ -4541,6 +4541,18 @@ impl TermWindow {
};
let main_renderer =
crate::native_settings::main_window_renderer(&native_settings, config.front_end);
+ // Only OpenGL draws onto DirectComposition: a window that will be
+ // drawn any other way is made the usual way, or it would show nothing.
+ let config = if config.win32_backdrop_trial == config::Win32BackdropTrial::Composition
+ && (main_renderer != crate::native_settings::NativeRendererBackend::OpenGL
+ || crate::renderer_choice::has_failed(
+ crate::native_settings::NativeRendererBackend::OpenGL,
+ ))
+ {
+ config.adjusted(|config| config.win32_backdrop_trial = config::Win32BackdropTrial::Off)
+ } else {
+ config
+ };
let dpi = config.dpi.unwrap_or_else(|| ::window::default_dpi()) as usize;
let fontconfig = Rc::new(FontConfiguration::new(Some(config.clone()), dpi)?);
diff --git a/window/src/egl.rs b/window/src/egl.rs
index 256b31af..1511ae82 100644
--- a/window/src/egl.rs
+++ b/window/src/egl.rs
@@ -50,6 +50,11 @@ impl std::fmt::Debug for EglWrapper {
}
}
+/// `EGL_ANGLE_direct_composition`: a window surface drawn onto a
+/// DirectComposition visual, alpha and all, rather than into the window.
+#[cfg(windows)]
+const DIRECT_COMPOSITION_ANGLE: i32 = 0x33A5;
+
#[derive(Debug)]
pub struct GlConnection {
egl: EglWrapper,
@@ -346,19 +351,14 @@ impl EglWrapper {
display: ffi::types::EGLDisplay,
config: ffi::types::EGLConfig,
window: ffi::EGLNativeWindowType,
+ extra_attributes: &[i32],
) -> anyhow::Result<ffi::types::EGLSurface> {
+ let mut attributes = vec![ffi::GL_COLORSPACE as i32, ffi::GL_COLORSPACE_SRGB as i32];
+ attributes.extend_from_slice(extra_attributes);
+ attributes.push(ffi::NONE as i32);
let surface = unsafe {
- self.egl.CreateWindowSurface(
- display,
- config,
- window,
- [
- ffi::GL_COLORSPACE as i32,
- ffi::GL_COLORSPACE_SRGB as i32,
- ffi::NONE as i32,
- ]
- .as_ptr(),
- )
+ self.egl
+ .CreateWindowSurface(display, config, window, attributes.as_ptr())
};
if surface.is_null() {
Err(self.error("EGL CreateWindowSurface"))
@@ -400,9 +400,9 @@ impl GlState {
&self.connection
}
- fn with_egl_lib<F: FnMut(EglWrapper) -> anyhow::Result<Self>>(
+ fn with_egl_lib<T, F: FnMut(EglWrapper) -> anyhow::Result<T>>(
mut func: F,
- ) -> anyhow::Result<Self> {
+ ) -> anyhow::Result<T> {
let mut paths: Vec<std::path::PathBuf> = vec![
#[cfg(target_os = "windows")]
"libEGL.dll".into(),
@@ -494,41 +494,75 @@ impl GlState {
window: ffi::EGLNativeWindowType,
) -> anyhow::Result<Self> {
Self::with_egl_lib(|egl| {
- let egl_display = egl.get_display(display)?;
-
- let (major, minor) = egl.initialize_and_get_version(egl_display)?;
- log::trace!("initialized EGL version {}.{}", major, minor);
-
- let is_opengl = unsafe {
- if egl.egl.BindAPI(ffi::OPENGL_API) != 0 {
- log::trace!("using OpenGL");
- true
- } else if egl.egl.BindAPI(ffi::OPENGL_ES_API) != 0 {
- log::trace!("using GLES");
- false
- } else {
- anyhow::bail!("Unable to bind to OpenGL or GL ES!?");
- }
- };
+ let connection = Self::connect_with(egl, display)?;
+ Self::create_with_existing_connection(&connection, window)
+ })
+ }
- let extensions = unsafe { egl.egl.QueryString(egl_display, ffi::EXTENSIONS as _) };
- let extensions = if extensions.is_null() {
- String::new()
- } else {
- let cstr = unsafe { std::ffi::CStr::from_ptr(extensions) };
- String::from_utf8_lossy(cstr.to_bytes()).to_string()
- };
- log::trace!("EGL extensions: {}", extensions);
+ /// An EGL connection that can draw onto DirectComposition, from the
+ /// first EGL found that can -- the ANGLE shipped beside the executable.
+ #[cfg(windows)]
+ pub fn connect_for_composition() -> anyhow::Result<Rc<GlConnection>> {
+ Self::with_egl_lib(|egl| {
+ let connection = Self::connect_with(egl, None)?;
+ ensure!(
+ connection.has_extension("EGL_ANGLE_direct_composition"),
+ "no EGL_ANGLE_direct_composition"
+ );
+ Ok(connection)
+ })
+ }
- let connection = Rc::new(GlConnection {
- display: egl_display,
- egl,
- is_opengl,
- extensions,
- });
+ /// A window surface on `connection` drawn onto DirectComposition: the
+ /// window was made without a redirection bitmap, so nothing else shows.
+ #[cfg(windows)]
+ pub fn create_for_composition(
+ connection: &Rc<GlConnection>,
+ window: ffi::EGLNativeWindowType,
+ ) -> anyhow::Result<GlState> {
+ Self::create_with_surface_attributes(
+ connection,
+ window,
+ &[DIRECT_COMPOSITION_ANGLE, ffi::TRUE as i32],
+ )
+ }
- Self::create_with_existing_connection(&connection, window)
- })
+ fn connect_with(
+ egl: EglWrapper,
+ display: Option<ffi::EGLNativeDisplayType>,
+ ) -> anyhow::Result<Rc<GlConnection>> {
+ let egl_display = egl.get_display(display)?;
+
+ let (major, minor) = egl.initialize_and_get_version(egl_display)?;
+ log::trace!("initialized EGL version {}.{}", major, minor);
+
+ let is_opengl = unsafe {
+ if egl.egl.BindAPI(ffi::OPENGL_API) != 0 {
+ log::trace!("using OpenGL");
+ true
+ } else if egl.egl.BindAPI(ffi::OPENGL_ES_API) != 0 {
+ log::trace!("using GLES");
+ false
+ } else {
+ anyhow::bail!("Unable to bind to OpenGL or GL ES!?");
+ }
+ };
+
+ let extensions = unsafe { egl.egl.QueryString(egl_display, ffi::EXTENSIONS as _) };
+ let extensions = if extensions.is_null() {
+ String::new()
+ } else {
+ let cstr = unsafe { std::ffi::CStr::from_ptr(extensions) };
+ String::from_utf8_lossy(cstr.to_bytes()).to_string()
+ };
+ log::trace!("EGL extensions: {}", extensions);
+
+ Ok(Rc::new(GlConnection {
+ display: egl_display,
+ egl,
+ is_opengl,
+ extensions,
+ }))
}
#[cfg(all(unix, not(target_os = "macos")))]
@@ -543,6 +577,14 @@ impl GlState {
pub fn create_with_existing_connection(
connection: &Rc<GlConnection>,
window: ffi::EGLNativeWindowType,
+ ) -> anyhow::Result<GlState> {
+ Self::create_with_surface_attributes(connection, window, &[])
+ }
+
+ fn create_with_surface_attributes(
+ connection: &Rc<GlConnection>,
+ window: ffi::EGLNativeWindowType,
+ surface_attributes: &[i32],
) -> anyhow::Result<GlState> {
let configs = connection.egl.choose_config(
connection.display,
@@ -600,7 +642,7 @@ impl GlState {
let surface =
match connection
.egl
- .create_window_surface(connection.display, config, window)
+ .create_window_surface(connection.display, config, window, surface_attributes)
{
Ok(s) => s,
Err(e) => {
diff --git a/window/src/os/windows/window.rs b/window/src/os/windows/window.rs
index 35e5f743..33d1f845 100644
--- a/window/src/os/windows/window.rs
+++ b/window/src/os/windows/window.rs
@@ -29,6 +29,7 @@ use std::os::windows::ffi::OsStringExt;
use std::path::PathBuf;
use std::ptr::{null, null_mut};
use std::rc::Rc;
+use std::sync::atomic::{AtomicBool, Ordering};
use wezterm_color_types::LinearRgba;
use wezterm_font::FontConfiguration;
use wezterm_input_types::KeyboardLedStatus;
@@ -146,6 +147,10 @@ pub(crate) struct WindowInner {
/// The way of asking for the backdrop last applied: one switched off is
/// undone, and a window that never tried one is left as it always was.
backdrop_trial: Win32BackdropTrial,
+ /// The EGL this window draws through onto DirectComposition, when it was
+ /// made for `Win32BackdropTrial::Composition`: without a redirection
+ /// bitmap, nothing it draws any other way would show.
+ composition: Option<Rc<crate::egl::GlConnection>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
@@ -457,6 +462,24 @@ impl WindowInner {
fn enable_opengl(&mut self) -> anyhow::Result<Rc<glium::backend::Context>> {
let conn = Connection::get().unwrap();
+ if let Some(glconn) = self.composition.as_ref() {
+ let gl_state = crate::egl::GlState::create_for_composition(glconn, self.hwnd.0)
+ .and_then(|state| unsafe {
+ Ok(glium::backend::Context::new(
+ Rc::new(state),
+ true,
+ callback_behavior(),
+ )?)
+ })
+ .map_err(|err| {
+ // Later windows are made the usual way.
+ COMPOSITION_FAILED.store(true, Ordering::Relaxed);
+ err
+ })?;
+ self.gl_state.replace(gl_state.clone());
+ return Ok(gl_state);
+ }
+
let gl_state = if self.config.prefer_egl {
match conn.gl_connection.borrow().as_ref() {
None => crate::egl::GlState::create(None, self.hwnd.0),
@@ -765,6 +788,7 @@ impl Window {
name: &str,
geometry: ResolvedGeometry,
frame_rect: Option<ScreenRect>,
+ ex_style: u32,
lparam: *const RefCell<WindowInner>,
) -> anyhow::Result<HWND> {
let class_name = wide_string(class_name);
@@ -807,7 +831,7 @@ impl Window {
let name = wide_string(name);
let hwnd = unsafe {
CreateWindowExW(
- 0,
+ ex_style,
class_name.as_ptr(),
name.as_ptr(),
style,
@@ -876,7 +900,7 @@ impl Window {
let name = wide_string(name);
let hwnd = unsafe {
CreateWindowExW(
- 0,
+ ex_style,
class_name.as_ptr(),
name.as_ptr(),
style,
@@ -943,6 +967,7 @@ impl Window {
occlusion_visible: None,
last_frame_event: None,
backdrop_trial: Win32BackdropTrial::Off,
+ composition: None,
}));
// Careful: `raw` owns a ref to inner, but there is no Drop impl
@@ -959,12 +984,25 @@ impl Window {
let frame_rect = geometry.windows_frame_rect;
let geometry = conn.resolve_geometry(geometry);
+ // Chosen for good when the window is made: the extended style that
+ // lets DirectComposition through cannot be taken off again.
+ let composition = (config.win32_backdrop_trial == Win32BackdropTrial::Composition)
+ .then(|| composition_connection(&conn))
+ .flatten();
+ let ex_style = if composition.is_some() {
+ WS_EX_NOREDIRECTIONBITMAP
+ } else {
+ 0
+ };
+ inner.borrow_mut().composition = composition;
+
let hwnd = match Self::create_window(
config.clone(),
class_name,
name,
geometry.clone(),
frame_rect,
+ ex_style,
raw,
) {
Ok(hwnd) => HWindow(hwnd),
@@ -1001,10 +1039,8 @@ impl Window {
}
apply_theme(hwnd.0);
- blur_behind(
- hwnd.0,
- config.win32_backdrop_trial != Win32BackdropTrial::System,
- );
+ let trial = window_backdrop_trial(inner.borrow().composition.is_some(), &config);
+ blur_behind(hwnd.0, blurs_behind(trial));
// Make window capable of accepting drag and drop
unsafe {
@@ -1196,6 +1232,29 @@ impl HasWindowHandle for Window {
#[async_trait(?Send)]
impl WindowOps for Window {
+ fn finish_frame(&self, frame: glium::Frame) -> anyhow::Result<()> {
+ // ANGLE resizes the swap chain behind a DirectComposition window only
+ // as it presents: a frame drawn just after a resize went into the
+ // old size's buffer, so draw once more at the new one.
+ let stale = rc_from_hwnd(self.0 .0).and_then(|inner| {
+ let inner = inner.borrow();
+ inner.composition.as_ref()?;
+ let drawn = inner.gl_state.as_ref()?.get_framebuffer_dimensions();
+ let mut rect: RECT = unsafe { std::mem::zeroed() };
+ unsafe { GetClientRect(self.0 .0, &mut rect) };
+ let client = (
+ (rect.right - rect.left).max(0) as u32,
+ (rect.bottom - rect.top).max(0) as u32,
+ );
+ Some(drawn != client)
+ });
+ frame.finish()?;
+ if stale == Some(true) {
+ self.invalidate();
+ }
+ Ok(())
+ }
+
async fn enable_opengl(&self) -> anyhow::Result<Rc<glium::backend::Context>> {
let window = self.0;
promise::spawn::spawn(async move {
@@ -1843,6 +1902,53 @@ fn get_window_state(hwnd: HWND) -> WindowState {
}
}
+/// A window made for DirectComposition could not be drawn that way: the
+/// rest are made the usual way, as nothing else shows in one.
+static COMPOSITION_FAILED: AtomicBool = AtomicBool::new(false);
+
+/// The EGL to draw a new window through onto DirectComposition: the one
+/// already open when it can, else one found for it. `None` when no EGL here
+/// can, and the window is made the usual way.
+fn composition_connection(conn: &Connection) -> Option<Rc<crate::egl::GlConnection>> {
+ if COMPOSITION_FAILED.load(Ordering::Relaxed) {
+ return None;
+ }
+ if let Some(glconn) = conn.gl_connection.borrow().as_ref() {
+ if glconn.has_extension("EGL_ANGLE_direct_composition") {
+ return Some(Rc::clone(glconn));
+ }
+ }
+ match crate::egl::GlState::connect_for_composition() {
+ Ok(glconn) => {
+ conn.gl_connection
+ .borrow_mut()
+ .get_or_insert_with(|| Rc::clone(&glconn));
+ Some(glconn)
+ }
+ Err(err) => {
+ log::warn!("DirectComposition backdrop unavailable: {err:#}");
+ None
+ }
+ }
+}
+
+/// The way of asking for the backdrop a window can take: whether it draws
+/// onto DirectComposition was settled when it was made, so a window made
+/// for it keeps it and one made without it waits for the next window.
+fn window_backdrop_trial(composition: bool, config: &ConfigHandle) -> Win32BackdropTrial {
+ match config.win32_backdrop_trial {
+ _ if composition => Win32BackdropTrial::Composition,
+ Win32BackdropTrial::Composition => Win32BackdropTrial::Off,
+ trial => trial,
+ }
+}
+
+/// Whether the old blur behind the window stays on: it is what lets the
+/// window's alpha through, except onto DirectComposition, which carries it.
+fn blurs_behind(trial: Win32BackdropTrial) -> bool {
+ trial != Win32BackdropTrial::Composition
+}
+
/// "Blur behind" is the old vista term for a cool blurring
/// effect that the DWM could enable. Subsequent windows
/// versions have removed the blurring. We use this call
@@ -1965,15 +2071,14 @@ fn apply_theme(hwnd: HWND) -> Option<LRESULT> {
// Set Acrylic or Mica system Backdrop; a trial is of acrylic,
// asked for its own way.
- let trial = inner.config.win32_backdrop_trial;
- let system_trial =
- matches!(trial, Win32BackdropTrial::System | Win32BackdropTrial::SystemBlur);
+ let trial = window_backdrop_trial(inner.composition.is_some(), &inner.config);
+ let composition = trial == Win32BackdropTrial::Composition;
let accent = !*IS_WIN11_22H2 || trial == Win32BackdropTrial::Accent;
let acrylic = trial != Win32BackdropTrial::Off
|| inner.config.win32_system_backdrop == SystemBackdrop::Acrylic;
let pv_attribute = match inner.config.win32_system_backdrop {
_ if trial == Win32BackdropTrial::Accent => DWM_SYSTEMBACKDROP_TYPE::DWMSBT_NONE,
- _ if system_trial => DWM_SYSTEMBACKDROP_TYPE::DWMSBT_TRANSIENTWINDOW,
+ _ if composition => DWM_SYSTEMBACKDROP_TYPE::DWMSBT_TRANSIENTWINDOW,
SystemBackdrop::Auto => DWM_SYSTEMBACKDROP_TYPE::DWMSBT_AUTO,
SystemBackdrop::Disable => DWM_SYSTEMBACKDROP_TYPE::DWMSBT_NONE,
SystemBackdrop::Acrylic => DWM_SYSTEMBACKDROP_TYPE::DWMSBT_TRANSIENTWINDOW,
@@ -1982,7 +2087,7 @@ fn apply_theme(hwnd: HWND) -> Option<LRESULT> {
};
let margins = match inner.config.window_decorations {
- _ if system_trial => -1,
+ _ if composition => -1,
WindowDecorations::TITLE => -1,
_ => 0,
};
@@ -2001,7 +2106,7 @@ fn apply_theme(hwnd: HWND) -> Option<LRESULT> {
// the window's alpha through goes with it.
let tried = std::mem::replace(&mut inner.backdrop_trial, trial);
if trial != Win32BackdropTrial::Off || tried != Win32BackdropTrial::Off {
- blur_behind(hwnd, trial != Win32BackdropTrial::System);
+ blur_behind(hwnd, blurs_behind(trial));
}
// Apply Acrylic or Mica Backdrop