Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows transparency behavior to support fully-opaque regions #1621

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased

- On Android, calling `WindowEvent::Focused` now works properly instead of always returning false.
- On Windows, fix bug preventing windows with transparency enabled from having fully-opaque regions.

# 0.23.0 (2020-10-02)

Expand Down
25 changes: 5 additions & 20 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use winapi::{
ole2,
oleidl::LPDROPTARGET,
shobjidl_core::{CLSID_TaskbarList, ITaskbarList2},
wingdi::{CreateRectRgn, DeleteObject},
winnt::LPCWSTR,
winuser,
},
Expand Down Expand Up @@ -708,33 +707,19 @@ unsafe fn init<T: 'static>(

// making the window transparent
if attributes.transparent && !pl_attribs.no_redirection_bitmap {
let region = CreateRectRgn(0, 0, -1, -1); // makes the window transparent

let bb = dwmapi::DWM_BLURBEHIND {
dwFlags: dwmapi::DWM_BB_ENABLE | dwmapi::DWM_BB_BLURREGION,
dwFlags: dwmapi::DWM_BB_ENABLE,
fEnable: 1,
hRgnBlur: region,
hRgnBlur: ptr::null_mut(),
fTransitionOnMaximized: 0,
};

dwmapi::DwmEnableBlurBehindWindow(real_window.0, &bb);
DeleteObject(region as _);

if attributes.decorations {
// HACK: When opaque (opacity 255), there is a trail whenever
// the transparent window is moved. By reducing it to 254,
// the window is rendered properly.
let opacity = 254;

// The color key can be any value except for black (0x0).
let color_key = 0x0030c100;

winuser::SetLayeredWindowAttributes(
real_window.0,
color_key,
opacity,
winuser::LWA_ALPHA,
);
let opacity = 255;

winuser::SetLayeredWindowAttributes(real_window.0, 0, opacity, winuser::LWA_ALPHA);
}
}

Expand Down