win: fix snap layout not working unless resize once

This commit is contained in:
Yuhang Zhao 2023-07-28 15:20:25 +08:00
parent 03832ac86f
commit d9ce1c4302
2 changed files with 9 additions and 6 deletions

View File

@ -503,6 +503,10 @@ static inline void cleanupFallbackWindow()
} }
g_win32Helper()->data[parentWindowId].fallbackTitleBarWindowId = fallbackTitleBarWindowId; g_win32Helper()->data[parentWindowId].fallbackTitleBarWindowId = fallbackTitleBarWindowId;
g_win32Helper()->fallbackTitleBarToParentWindowMapping.insert(fallbackTitleBarWindowId, parentWindowId); g_win32Helper()->fallbackTitleBarToParentWindowMapping.insert(fallbackTitleBarWindowId, parentWindowId);
// ### Why do we need an extra resize here?
QTimer::singleShot(0, qApp, [parentWindowId, fallbackTitleBarWindowId, hide](){
std::ignore = resizeFallbackTitleBarWindow(parentWindowId, fallbackTitleBarWindowId, hide);
});
return true; return true;
} }
@ -529,13 +533,10 @@ void FramelessHelperWin::addWindow(FramelessParamsConst params)
qApp->installNativeEventFilter(g_win32Helper()->nativeEventFilter.get()); qApp->installNativeEventFilter(g_win32Helper()->nativeEventFilter.get());
} }
DEBUG.noquote() << "The DPI of window" << hwnd2str(windowId) << "is" << data.dpi; DEBUG.noquote() << "The DPI of window" << hwnd2str(windowId) << "is" << data.dpi;
// Remove the bad window styles added by Qt (it's not that "bad" though).
Utils::maybeFixupQtInternals(windowId);
#if 0 #if 0
params->setWindowFlags(params->getWindowFlags() | Qt::FramelessWindowHint); params->setWindowFlags(params->getWindowFlags() | Qt::FramelessWindowHint);
// We need some delay here, otherwise the window styles will be overwritten by
// QPA itself. But don't use QThread::sleep(), it doesn't help in our case.
QTimer::singleShot(0, qApp, [windowId](){
Utils::maybeFixupQtInternals(windowId);
});
#else #else
// Qt maintains a frame margin internally, we need to update it accordingly // Qt maintains a frame margin internally, we need to update it accordingly
// otherwise we'll get lots of warning messages when we change the window // otherwise we'll get lots of warning messages when we change the window

View File

@ -1284,6 +1284,7 @@ void Utils::maybeFixupQtInternals(const WId windowId)
} }
bool shouldUpdateFrame = false; bool shouldUpdateFrame = false;
const auto hwnd = reinterpret_cast<HWND>(windowId); const auto hwnd = reinterpret_cast<HWND>(windowId);
#if 0
SetLastError(ERROR_SUCCESS); SetLastError(ERROR_SUCCESS);
const auto classStyle = static_cast<DWORD>(GetClassLongPtrW(hwnd, GCL_STYLE)); const auto classStyle = static_cast<DWORD>(GetClassLongPtrW(hwnd, GCL_STYLE));
if (classStyle != 0) { if (classStyle != 0) {
@ -1304,6 +1305,7 @@ void Utils::maybeFixupQtInternals(const WId windowId)
} else { } else {
WARNING << getSystemErrorMessage(kGetClassLongPtrW); WARNING << getSystemErrorMessage(kGetClassLongPtrW);
} }
#endif
SetLastError(ERROR_SUCCESS); SetLastError(ERROR_SUCCESS);
const auto windowStyle = static_cast<DWORD>(GetWindowLongPtrW(hwnd, GWL_STYLE)); const auto windowStyle = static_cast<DWORD>(GetWindowLongPtrW(hwnd, GWL_STYLE));
if (windowStyle == 0) { if (windowStyle == 0) {
@ -2506,7 +2508,7 @@ bool Utils::isValidWindow(const WId windowId, const bool checkVisible, const boo
return false; return false;
} }
const LONG_PTR exStyles = ::GetWindowLongPtrW(hwnd, GWL_EXSTYLE); const LONG_PTR exStyles = ::GetWindowLongPtrW(hwnd, GWL_EXSTYLE);
if (exStyles & WS_EX_TOOLWINDOW) { if ((exStyles != 0) && (exStyles & WS_EX_TOOLWINDOW)) {
return false; return false;
} }
RECT rect = { 0, 0, 0, 0 }; RECT rect = { 0, 0, 0, 0 };