From 2364b0a20ed576594effeca37c657473bab623d2 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 18 Oct 2020 11:13:34 -0700 Subject: [PATCH] Windows: enable window_background_opacity This causes DWM to respect the alpha channel we set during rendering, allowing the window opacity to be respected on Windows. refs: #141 --- window/src/os/windows/window.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/window/src/os/windows/window.rs b/window/src/os/windows/window.rs index f6c1d3835..c1d7417b9 100644 --- a/window/src/os/windows/window.rs +++ b/window/src/os/windows/window.rs @@ -316,6 +316,7 @@ impl Window { }; enable_dark_mode(hwnd.0); + enable_blur_behind(hwnd.0); Connection::get() .expect("Connection::init was not called") @@ -558,6 +559,27 @@ unsafe fn wm_ncdestroy( None } +/// "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 +/// to tell DWM that we set proper alpha channel info as +/// a result of rendering our window content. +fn enable_blur_behind(hwnd: HWND) { + use winapi::shared::minwindef::*; + use winapi::um::dwmapi::*; + + let bb = DWM_BLURBEHIND { + dwFlags: DWM_BB_ENABLE, + fEnable: TRUE, + hRgnBlur: null_mut(), + fTransitionOnMaximized: FALSE, + }; + + unsafe { + DwmEnableBlurBehindWindow(hwnd, &bb); + } +} + fn enable_dark_mode(hwnd: HWND) { // Prefer to run in dark mode. This could be made configurable without // a huge amount of effort, but I think it's fine to just be always