diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 3d4176f9f6a..dd9265d8b50 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -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) { diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index d11e6289566..a7284cc30aa 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -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) / diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index a384b4b1c7a..424848503be 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -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);