mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 06:11:30 +11:00
Fix transparent window crash on Windows 11 (#2121)
Maybe the transparent setting in WM_NCCREATE on Windows 11 will cause a block when calling DwmEnableBlureBehindWindow and will crash. Puts them into WM_CREATE and it works.
This commit is contained in:
parent
6b250a74f8
commit
25ff30ee8c
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
- On X11, add mappings for numpad comma, numpad enter, numlock and pause.
|
- On X11, add mappings for numpad comma, numpad enter, numlock and pause.
|
||||||
- On macOS, fix Pinyin IME input by reverting a change that intended to improve IME.
|
- On macOS, fix Pinyin IME input by reverting a change that intended to improve IME.
|
||||||
|
- On Windows, fix a crash with transparent windows on Windows 11.
|
||||||
|
|
||||||
# 0.26.0 (2021-12-01)
|
# 0.26.0 (2021-12-01)
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ use winapi::{
|
||||||
shared::{
|
shared::{
|
||||||
minwindef::{HINSTANCE, LPARAM, UINT, WPARAM},
|
minwindef::{HINSTANCE, LPARAM, UINT, WPARAM},
|
||||||
windef::{HWND, POINT, POINTS, RECT},
|
windef::{HWND, POINT, POINTS, RECT},
|
||||||
|
winerror::SUCCEEDED,
|
||||||
},
|
},
|
||||||
um::{
|
um::{
|
||||||
combaseapi, dwmapi,
|
combaseapi, dwmapi,
|
||||||
|
@ -699,22 +700,6 @@ impl<'a, T: 'static> InitData<'a, T> {
|
||||||
let dpi = hwnd_dpi(window);
|
let dpi = hwnd_dpi(window);
|
||||||
let scale_factor = dpi_to_scale_factor(dpi);
|
let scale_factor = dpi_to_scale_factor(dpi);
|
||||||
|
|
||||||
// making the window transparent
|
|
||||||
if self.attributes.transparent && !self.pl_attribs.no_redirection_bitmap {
|
|
||||||
// Empty region for the blur effect, so the window is fully transparent
|
|
||||||
let region = CreateRectRgn(0, 0, -1, -1);
|
|
||||||
|
|
||||||
let bb = dwmapi::DWM_BLURBEHIND {
|
|
||||||
dwFlags: dwmapi::DWM_BB_ENABLE | dwmapi::DWM_BB_BLURREGION,
|
|
||||||
fEnable: 1,
|
|
||||||
hRgnBlur: region,
|
|
||||||
fTransitionOnMaximized: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
dwmapi::DwmEnableBlurBehindWindow(window, &bb);
|
|
||||||
DeleteObject(region as _);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the system theme is dark, we need to set the window theme now
|
// If the system theme is dark, we need to set the window theme now
|
||||||
// before we update the window flags (and possibly show the
|
// before we update the window flags (and possibly show the
|
||||||
// window for the first time).
|
// window for the first time).
|
||||||
|
@ -809,6 +794,28 @@ impl<'a, T: 'static> InitData<'a, T> {
|
||||||
|
|
||||||
pub unsafe fn on_create(&mut self) {
|
pub unsafe fn on_create(&mut self) {
|
||||||
let win = self.window.as_mut().expect("failed window creation");
|
let win = self.window.as_mut().expect("failed window creation");
|
||||||
|
|
||||||
|
// making the window transparent
|
||||||
|
if self.attributes.transparent && !self.pl_attribs.no_redirection_bitmap {
|
||||||
|
// Empty region for the blur effect, so the window is fully transparent
|
||||||
|
let region = CreateRectRgn(0, 0, -1, -1);
|
||||||
|
|
||||||
|
let bb = dwmapi::DWM_BLURBEHIND {
|
||||||
|
dwFlags: dwmapi::DWM_BB_ENABLE | dwmapi::DWM_BB_BLURREGION,
|
||||||
|
fEnable: 1,
|
||||||
|
hRgnBlur: region,
|
||||||
|
fTransitionOnMaximized: 0,
|
||||||
|
};
|
||||||
|
let hr = dwmapi::DwmEnableBlurBehindWindow(win.hwnd(), &bb);
|
||||||
|
if !SUCCEEDED(hr) {
|
||||||
|
warn!(
|
||||||
|
"Setting transparent window is failed. HRESULT Code: 0x{:X}",
|
||||||
|
hr
|
||||||
|
);
|
||||||
|
}
|
||||||
|
DeleteObject(region as _);
|
||||||
|
}
|
||||||
|
|
||||||
let attributes = self.attributes.clone();
|
let attributes = self.attributes.clone();
|
||||||
|
|
||||||
// Set visible before setting the size to ensure the
|
// Set visible before setting the size to ensure the
|
||||||
|
|
Loading…
Reference in a new issue