From 378f59f462939513a0f65433d06f6d5df65cd547 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Sun, 6 Nov 2022 16:35:30 +0800 Subject: [PATCH] win: fix a rare bug Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- src/core/utils_win.cpp | 44 ++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index 3ee4c45..b684a85 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -1452,29 +1452,31 @@ void Utils::maybeFixupQtInternals(const WId windowId) } else { WARNING << getSystemErrorMessage(kGetClassLongPtrW); } - SetLastError(ERROR_SUCCESS); - const auto windowStyle = static_cast(GetWindowLongPtrW(hwnd, GWL_STYLE)); - if (windowStyle != 0) { - // Qt by default adds the "WS_POPUP" flag to all Win32 windows it created and maintained, - // which is not a good thing (although it won't cause any obvious issues in most cases - // either), because popup windows have some different behavior with normal overlapped - // windows, for example, it will affect DWM's default policy. And Qt will also lack some - // necessary window styles in some cases (caused by misconfigured setWindowFlag(s) calls) - // and this will also break the normal functionalities for our windows, so we do the - // correction here unconditionally. - static constexpr const DWORD badWindowStyle = WS_POPUP; - static constexpr const DWORD goodWindowStyle = - (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME); - if ((windowStyle & badWindowStyle) || !(windowStyle & goodWindowStyle)) { - SetLastError(ERROR_SUCCESS); - if (SetWindowLongPtrW(hwnd, GWL_STYLE, ((windowStyle & ~badWindowStyle) | goodWindowStyle)) == 0) { - WARNING << getSystemErrorMessage(kSetWindowLongPtrW); - } else { - shouldUpdateFrame = true; + if (!FramelessConfig::instance()->isSet(Option::UseCrossPlatformQtImplementation)) { + SetLastError(ERROR_SUCCESS); + const auto windowStyle = static_cast(GetWindowLongPtrW(hwnd, GWL_STYLE)); + if (windowStyle != 0) { + // Qt by default adds the "WS_POPUP" flag to all Win32 windows it created and maintained, + // which is not a good thing (although it won't cause any obvious issues in most cases + // either), because popup windows have some different behavior with normal overlapped + // windows, for example, it will affect DWM's default policy. And Qt will also lack some + // necessary window styles in some cases (caused by misconfigured setWindowFlag(s) calls) + // and this will also break the normal functionalities for our windows, so we do the + // correction here unconditionally. + static constexpr const DWORD badWindowStyle = WS_POPUP; + static constexpr const DWORD goodWindowStyle = + (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME); + if ((windowStyle & badWindowStyle) || !(windowStyle & goodWindowStyle)) { + SetLastError(ERROR_SUCCESS); + if (SetWindowLongPtrW(hwnd, GWL_STYLE, ((windowStyle & ~badWindowStyle) | goodWindowStyle)) == 0) { + WARNING << getSystemErrorMessage(kSetWindowLongPtrW); + } else { + shouldUpdateFrame = true; + } } + } else { + WARNING << getSystemErrorMessage(kGetWindowLongPtrW); } - } else { - WARNING << getSystemErrorMessage(kGetWindowLongPtrW); } if (shouldUpdateFrame) { triggerFrameChange(windowId);