mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 21:31:29 +11:00
Fix Windows transparency behavior to support fully-opaque regions (#1621)
This patch removes an unneeded workaround for transparent windows on the Windows platform. In addition, it simplifies a couple of related API calls: * Remove the `CreateRectRgn` call, since we want the entire window's region to have blur behind it, and `DwnEnableBlurBehindWindow` does that by default. * Remove the `color_key` for `SetLayeredWindowAttributes`, since it's not used (we're not passing `winuser::LWA_COLORKEY` to the flags).
This commit is contained in:
parent
5a78fe33e8
commit
6343059bc0
|
@ -1,6 +1,7 @@
|
||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
- On Android, calling `WindowEvent::Focused` now works properly instead of always returning false.
|
- 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)
|
# 0.23.0 (2020-10-02)
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ use winapi::{
|
||||||
ole2,
|
ole2,
|
||||||
oleidl::LPDROPTARGET,
|
oleidl::LPDROPTARGET,
|
||||||
shobjidl_core::{CLSID_TaskbarList, ITaskbarList2},
|
shobjidl_core::{CLSID_TaskbarList, ITaskbarList2},
|
||||||
wingdi::{CreateRectRgn, DeleteObject},
|
|
||||||
winnt::LPCWSTR,
|
winnt::LPCWSTR,
|
||||||
winuser,
|
winuser,
|
||||||
},
|
},
|
||||||
|
@ -708,33 +707,19 @@ unsafe fn init<T: 'static>(
|
||||||
|
|
||||||
// making the window transparent
|
// making the window transparent
|
||||||
if attributes.transparent && !pl_attribs.no_redirection_bitmap {
|
if attributes.transparent && !pl_attribs.no_redirection_bitmap {
|
||||||
let region = CreateRectRgn(0, 0, -1, -1); // makes the window transparent
|
|
||||||
|
|
||||||
let bb = dwmapi::DWM_BLURBEHIND {
|
let bb = dwmapi::DWM_BLURBEHIND {
|
||||||
dwFlags: dwmapi::DWM_BB_ENABLE | dwmapi::DWM_BB_BLURREGION,
|
dwFlags: dwmapi::DWM_BB_ENABLE,
|
||||||
fEnable: 1,
|
fEnable: 1,
|
||||||
hRgnBlur: region,
|
hRgnBlur: ptr::null_mut(),
|
||||||
fTransitionOnMaximized: 0,
|
fTransitionOnMaximized: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
dwmapi::DwmEnableBlurBehindWindow(real_window.0, &bb);
|
dwmapi::DwmEnableBlurBehindWindow(real_window.0, &bb);
|
||||||
DeleteObject(region as _);
|
|
||||||
|
|
||||||
if attributes.decorations {
|
if attributes.decorations {
|
||||||
// HACK: When opaque (opacity 255), there is a trail whenever
|
let opacity = 255;
|
||||||
// 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).
|
winuser::SetLayeredWindowAttributes(real_window.0, 0, opacity, winuser::LWA_ALPHA);
|
||||||
let color_key = 0x0030c100;
|
|
||||||
|
|
||||||
winuser::SetLayeredWindowAttributes(
|
|
||||||
real_window.0,
|
|
||||||
color_key,
|
|
||||||
opacity,
|
|
||||||
winuser::LWA_ALPHA,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue