Revert "Windows QPA: Remove usage of deprecated DwmEnableBlurBehindWindow"

This reverts commit b07876105788d519a3bb04a353eaa5ffa6269253.

Reason for revert: Introduced regression QTBUG-136098

Change-Id: Id1f4d7a485659c4150f6750866c2f702fcdc1bf6
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
Wladimir Leuschner 2025-05-15 09:29:26 +00:00
parent e48c19449e
commit 2d0e3c5001
3 changed files with 27 additions and 0 deletions

View File

@ -1233,6 +1233,7 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message,
return true;
}
case QtWindows::CompositionSettingsChanged:
platformWindow->handleCompositionSettingsChanged();
return true;
case QtWindows::ActivateWindowEvent:
if (platformWindow->window()->flags() & Qt::WindowDoesNotAcceptFocus) {

View File

@ -485,6 +485,22 @@ static inline bool windowIsAccelerated(const QWindow *w)
}
}
static bool applyBlurBehindWindow(HWND hwnd)
{
DWM_BLURBEHIND blurBehind = {0, 0, nullptr, 0};
blurBehind.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
blurBehind.fEnable = TRUE;
blurBehind.hRgnBlur = CreateRectRgn(0, 0, -1, -1);
const bool result = DwmEnableBlurBehindWindow(hwnd, &blurBehind) == S_OK;
if (blurBehind.hRgnBlur)
DeleteObject(blurBehind.hRgnBlur);
return result;
}
// from qwidget_win.cpp, pass flags separately in case they have been "autofixed".
static bool shouldShowMaximizeButton(const QWindow *w, Qt::WindowFlags flags)
{
@ -1044,6 +1060,8 @@ void WindowCreationData::initialize(const QWindow *w, HWND hwnd, bool frameChang
const bool isAccelerated = windowIsAccelerated(w);
const bool hasAlpha = w->format().hasAlpha();
if (isAccelerated && hasAlpha)
applyBlurBehindWindow(hwnd);
setWindowOpacity(hwnd, flags, hasAlpha, isAccelerated, opacityLevel);
}
@ -2096,6 +2114,13 @@ void QWindowsWindow::handleHidden()
fireExpose(QRegion());
}
void QWindowsWindow::handleCompositionSettingsChanged()
{
const QWindow *w = window();
if (windowIsAccelerated(w) && w->format().hasAlpha())
applyBlurBehindWindow(handle());
}
qreal QWindowsWindow::dpiRelativeScale(const UINT dpi) const
{
return QHighDpiScaling::roundScaleFactor(qreal(dpi) / QWindowsScreen::baseDpi) /

View File

@ -295,6 +295,7 @@ public:
void handleMoved();
void handleResized(int wParam, LPARAM lParam);
void handleHidden();
void handleCompositionSettingsChanged();
void handleDpiScaledSize(WPARAM wParam, LPARAM lParam, LRESULT *result);
void handleDpiChanged(HWND hwnd, WPARAM wParam, LPARAM lParam);
void handleDpiChangedAfterParent(HWND hwnd);