From 119d10930b48b7a3f376a766caacd84edb4ffd9a Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Tue, 13 Sep 2022 11:02:53 +0800 Subject: [PATCH] win: minor tweaks Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- src/core/framelesshelper_win.cpp | 2 +- src/core/utils_win.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/framelesshelper_win.cpp b/src/core/framelesshelper_win.cpp index 12a908b..da0a087 100644 --- a/src/core/framelesshelper_win.cpp +++ b/src/core/framelesshelper_win.cpp @@ -458,7 +458,7 @@ Q_GLOBAL_STATIC(Win32Helper, g_win32Helper) const HWND fallbackTitleBarWindowHandle = CreateWindowExW((WS_EX_LAYERED | WS_EX_NOREDIRECTIONBITMAP), kFallbackTitleBarWindowClassName, nullptr, WS_CHILD, 0, 0, 0, 0, parentWindowHandle, nullptr, instance, nullptr); - Q_ASSERT_X(fallbackTitleBarWindowHandle, "createFallbackTitleBarWindow()", kFallbackTitleBarErrorMessage); + Q_ASSERT_X(fallbackTitleBarWindowHandle, __FUNCTION__, kFallbackTitleBarErrorMessage); if (!fallbackTitleBarWindowHandle) { WARNING << Utils::getSystemErrorMessage(kCreateWindowExW); WARNING << kFallbackTitleBarErrorMessage; diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index 3d46558..1f797ba 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -1176,11 +1176,13 @@ void Utils::fixupQtInternals(const WId windowId) // 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 not add - // the "WS_OVERLAPPED" flag to the windows in some cases, which also causes some trouble - // for us. To avoid some weird bugs, we do the correction here: remove the WS_POPUP flag - // and add the WS_OVERLAPPED flag, unconditionally. - const DWORD newWindowStyle = ((oldWindowStyle & ~WS_POPUP) | WS_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 normalWindowStyle = + (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME); + const DWORD newWindowStyle = ((oldWindowStyle & ~WS_POPUP) | normalWindowStyle); SetLastError(ERROR_SUCCESS); if (SetWindowLongPtrW(hwnd, GWL_STYLE, static_cast(newWindowStyle)) == 0) { WARNING << getSystemErrorMessage(kSetWindowLongPtrW);