win: fix a rare bug

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-11-06 16:35:30 +08:00
parent 32d29e39f6
commit 378f59f462
1 changed files with 23 additions and 21 deletions

View File

@ -1452,29 +1452,31 @@ void Utils::maybeFixupQtInternals(const WId windowId)
} else { } else {
WARNING << getSystemErrorMessage(kGetClassLongPtrW); WARNING << getSystemErrorMessage(kGetClassLongPtrW);
} }
SetLastError(ERROR_SUCCESS); if (!FramelessConfig::instance()->isSet(Option::UseCrossPlatformQtImplementation)) {
const auto windowStyle = static_cast<DWORD>(GetWindowLongPtrW(hwnd, GWL_STYLE)); SetLastError(ERROR_SUCCESS);
if (windowStyle != 0) { const auto windowStyle = static_cast<DWORD>(GetWindowLongPtrW(hwnd, GWL_STYLE));
// Qt by default adds the "WS_POPUP" flag to all Win32 windows it created and maintained, if (windowStyle != 0) {
// which is not a good thing (although it won't cause any obvious issues in most cases // Qt by default adds the "WS_POPUP" flag to all Win32 windows it created and maintained,
// either), because popup windows have some different behavior with normal overlapped // which is not a good thing (although it won't cause any obvious issues in most cases
// windows, for example, it will affect DWM's default policy. And Qt will also lack some // either), because popup windows have some different behavior with normal overlapped
// necessary window styles in some cases (caused by misconfigured setWindowFlag(s) calls) // windows, for example, it will affect DWM's default policy. And Qt will also lack some
// and this will also break the normal functionalities for our windows, so we do the // necessary window styles in some cases (caused by misconfigured setWindowFlag(s) calls)
// correction here unconditionally. // and this will also break the normal functionalities for our windows, so we do the
static constexpr const DWORD badWindowStyle = WS_POPUP; // correction here unconditionally.
static constexpr const DWORD goodWindowStyle = static constexpr const DWORD badWindowStyle = WS_POPUP;
(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME); static constexpr const DWORD goodWindowStyle =
if ((windowStyle & badWindowStyle) || !(windowStyle & goodWindowStyle)) { (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
SetLastError(ERROR_SUCCESS); if ((windowStyle & badWindowStyle) || !(windowStyle & goodWindowStyle)) {
if (SetWindowLongPtrW(hwnd, GWL_STYLE, ((windowStyle & ~badWindowStyle) | goodWindowStyle)) == 0) { SetLastError(ERROR_SUCCESS);
WARNING << getSystemErrorMessage(kSetWindowLongPtrW); if (SetWindowLongPtrW(hwnd, GWL_STYLE, ((windowStyle & ~badWindowStyle) | goodWindowStyle)) == 0) {
} else { WARNING << getSystemErrorMessage(kSetWindowLongPtrW);
shouldUpdateFrame = true; } else {
shouldUpdateFrame = true;
}
} }
} else {
WARNING << getSystemErrorMessage(kGetWindowLongPtrW);
} }
} else {
WARNING << getSystemErrorMessage(kGetWindowLongPtrW);
} }
if (shouldUpdateFrame) { if (shouldUpdateFrame) {
triggerFrameChange(windowId); triggerFrameChange(windowId);