From e5370435a9d4297d0ba227f2237d7ed16bba7e82 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <zhaoyuhang@rankyee.com> Date: 周三, 27 12月 2023 17:15:52 +0800 Subject: [PATCH] fix some win32 issues --- src/core/shared/qwkwindowsextra_p.h | 2 ++ src/core/qwindowkit_windows.h | 6 +++--- src/core/contexts/win32windowcontext.cpp | 28 +++++++++++++++++----------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp index dfbf2e2..00d42c1 100644 --- a/src/core/contexts/win32windowcontext.cpp +++ b/src/core/contexts/win32windowcontext.cpp @@ -684,10 +684,20 @@ if (!m_windowHandle) return {}; - auto hwnd = reinterpret_cast<HWND>(windowId); - RECT frame{}; - ::AdjustWindowRectExForDpi(&frame, ::GetWindowLongPtrW(hwnd, GWL_STYLE), FALSE, 0, - getDpiForWindow(hwnd)); + auto frame = [this]() -> RECT { + auto hwnd = reinterpret_cast<HWND>(windowId); + // According to MSDN, WS_OVERLAPPED is not allowed for AdjustWindowRect. + auto style = static_cast<DWORD>(::GetWindowLongPtrW(hwnd, GWL_STYLE) & ~WS_OVERLAPPED); + auto exStyle = static_cast<DWORD>(::GetWindowLongPtrW(hwnd, GWL_EXSTYLE)); + RECT result{}; + const DynamicApis &apis = DynamicApis::instance(); + if (apis.pAdjustWindowRectExForDpi) { + apis.pAdjustWindowRectExForDpi(&result, style, FALSE, exStyle, getDpiForWindow(hwnd)); + } else { + ::AdjustWindowRectEx(&result, style, FALSE, exStyle); + } + return result; + }(); return QVariant::fromValue(rect2qrect(frame)); } @@ -809,7 +819,7 @@ if (key == QStringLiteral("extra-margins")) { auto margins = qmargins2margins(attribute.value<QMargins>()); - DynamicApis::instance().pDwmExtendFrameIntoClientArea(hwnd, &margins); + apis.pDwmExtendFrameIntoClientArea(hwnd, &margins); return true; } @@ -940,12 +950,9 @@ } if (key == QStringLiteral("dwm-blur")) { - // TODO: Optimize - // Currently not available!!! if (attribute.toBool()) { - // We need to extend the window frame into the whole client area to be able - // to see the blurred window background. - apis.pDwmExtendFrameIntoClientArea(hwnd, &extendedMargins); + // We can't extend the window frame for this effect. + restoreMargins(); if (isWin8OrGreater()) { ACCENT_POLICY policy{}; policy.dwAccentState = ACCENT_ENABLE_BLURBEHIND; @@ -977,7 +984,6 @@ bb.dwFlags = DWM_BB_ENABLE; apis.pDwmEnableBlurBehindWindow(hwnd, &bb); } - restoreMargins(); } return true; } diff --git a/src/core/qwindowkit_windows.h b/src/core/qwindowkit_windows.h index 8b3448b..2e0c2dd 100644 --- a/src/core/qwindowkit_windows.h +++ b/src/core/qwindowkit_windows.h @@ -99,7 +99,7 @@ (rovi.dwMajorVersion == 6 && rovi.dwMinorVersion >= 2); } - inline bool IsWindows10_Real() { + inline bool IsWindows10Only_Real() { return IsWindows10OrGreater_Real() && !IsWindows11OrGreater_Real(); } @@ -144,8 +144,8 @@ return result; } - static inline bool isWin10() { - static const bool result = Private::IsWindows10_Real(); + static inline bool isWin10Only() { + static const bool result = Private::IsWindows10Only_Real(); return result; }; diff --git a/src/core/shared/qwkwindowsextra_p.h b/src/core/shared/qwkwindowsextra_p.h index 0b24382..29f69d0 100644 --- a/src/core/shared/qwkwindowsextra_p.h +++ b/src/core/shared/qwkwindowsextra_p.h @@ -170,6 +170,7 @@ DYNAMIC_API_DECLARE(DwmEnableBlurBehindWindow); DYNAMIC_API_DECLARE(GetDpiForWindow); DYNAMIC_API_DECLARE(GetSystemMetricsForDpi); + DYNAMIC_API_DECLARE(AdjustWindowRectExForDpi); DYNAMIC_API_DECLARE(GetDpiForMonitor); DYNAMIC_API_DECLARE(timeGetDevCaps); DYNAMIC_API_DECLARE(timeBeginPeriod); @@ -193,6 +194,7 @@ DYNAMIC_API_RESOLVE(user32, GetDpiForWindow); DYNAMIC_API_RESOLVE(user32, GetSystemMetricsForDpi); DYNAMIC_API_RESOLVE(user32, SetWindowCompositionAttribute); + DYNAMIC_API_RESOLVE(user32, AdjustWindowRectExForDpi); QSystemLibrary shcore(QStringLiteral("shcore")); DYNAMIC_API_RESOLVE(shcore, GetDpiForMonitor); -- Gitblit v1.9.1