Merge pull request #95009 from bruvzg/win_transp_checks

[Windows] Check if transparency is enabled in the project setting before applying DWM blur.
This commit is contained in:
Rémi Verschelde 2024-08-06 12:30:56 +02:00
commit 2b65ff9249
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 29 additions and 26 deletions

View File

@ -1333,13 +1333,15 @@ DisplayServer::WindowID DisplayServerWindows::create_sub_window(WindowMode p_mod
wd.is_popup = true; wd.is_popup = true;
} }
if (p_flags & WINDOW_FLAG_TRANSPARENT_BIT) { if (p_flags & WINDOW_FLAG_TRANSPARENT_BIT) {
DWM_BLURBEHIND bb; if (OS::get_singleton()->is_layered_allowed()) {
ZeroMemory(&bb, sizeof(bb)); DWM_BLURBEHIND bb;
HRGN hRgn = CreateRectRgn(0, 0, -1, -1); ZeroMemory(&bb, sizeof(bb));
bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; HRGN hRgn = CreateRectRgn(0, 0, -1, -1);
bb.hRgnBlur = hRgn; bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
bb.fEnable = TRUE; bb.hRgnBlur = hRgn;
DwmEnableBlurBehindWindow(wd.hWnd, &bb); bb.fEnable = TRUE;
DwmEnableBlurBehindWindow(wd.hWnd, &bb);
}
wd.layered_window = true; wd.layered_window = true;
} }
@ -2119,28 +2121,29 @@ void DisplayServerWindows::window_set_flag(WindowFlags p_flag, bool p_enabled, W
} break; } break;
case WINDOW_FLAG_TRANSPARENT: { case WINDOW_FLAG_TRANSPARENT: {
if (p_enabled) { if (p_enabled) {
//enable per-pixel alpha // Enable per-pixel alpha.
if (OS::get_singleton()->is_layered_allowed()) {
DWM_BLURBEHIND bb; DWM_BLURBEHIND bb;
ZeroMemory(&bb, sizeof(bb)); ZeroMemory(&bb, sizeof(bb));
HRGN hRgn = CreateRectRgn(0, 0, -1, -1); HRGN hRgn = CreateRectRgn(0, 0, -1, -1);
bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
bb.hRgnBlur = hRgn; bb.hRgnBlur = hRgn;
bb.fEnable = TRUE; bb.fEnable = TRUE;
DwmEnableBlurBehindWindow(wd.hWnd, &bb); DwmEnableBlurBehindWindow(wd.hWnd, &bb);
}
wd.layered_window = true; wd.layered_window = true;
} else { } else {
//disable per-pixel alpha // Disable per-pixel alpha.
wd.layered_window = false; wd.layered_window = false;
if (OS::get_singleton()->is_layered_allowed()) {
DWM_BLURBEHIND bb; DWM_BLURBEHIND bb;
ZeroMemory(&bb, sizeof(bb)); ZeroMemory(&bb, sizeof(bb));
HRGN hRgn = CreateRectRgn(0, 0, -1, -1); HRGN hRgn = CreateRectRgn(0, 0, -1, -1);
bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
bb.hRgnBlur = hRgn; bb.hRgnBlur = hRgn;
bb.fEnable = FALSE; bb.fEnable = FALSE;
DwmEnableBlurBehindWindow(wd.hWnd, &bb); DwmEnableBlurBehindWindow(wd.hWnd, &bb);
}
} }
} break; } break;
case WINDOW_FLAG_NO_FOCUS: { case WINDOW_FLAG_NO_FOCUS: {