Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
win: fix snap layout not working unless resize once
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenx190 committed Jul 28, 2023
1 parent 03832ac commit d9ce1c4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/core/framelesshelper_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ static inline void cleanupFallbackWindow()
}
g_win32Helper()->data[parentWindowId].fallbackTitleBarWindowId = fallbackTitleBarWindowId;
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;
}

Expand All @@ -529,13 +533,10 @@ void FramelessHelperWin::addWindow(FramelessParamsConst params)
qApp->installNativeEventFilter(g_win32Helper()->nativeEventFilter.get());
}
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
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
// 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
Expand Down
4 changes: 3 additions & 1 deletion src/core/utils_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@ void Utils::maybeFixupQtInternals(const WId windowId)
}
bool shouldUpdateFrame = false;
const auto hwnd = reinterpret_cast<HWND>(windowId);
#if 0
SetLastError(ERROR_SUCCESS);
const auto classStyle = static_cast<DWORD>(GetClassLongPtrW(hwnd, GCL_STYLE));
if (classStyle != 0) {
Expand All @@ -1304,6 +1305,7 @@ void Utils::maybeFixupQtInternals(const WId windowId)
} else {
WARNING << getSystemErrorMessage(kGetClassLongPtrW);
}
#endif
SetLastError(ERROR_SUCCESS);
const auto windowStyle = static_cast<DWORD>(GetWindowLongPtrW(hwnd, GWL_STYLE));
if (windowStyle == 0) {
Expand Down Expand Up @@ -2506,7 +2508,7 @@ bool Utils::isValidWindow(const WId windowId, const bool checkVisible, const boo
return false;
}
const LONG_PTR exStyles = ::GetWindowLongPtrW(hwnd, GWL_EXSTYLE);
if (exStyles & WS_EX_TOOLWINDOW) {
if ((exStyles != 0) && (exStyles & WS_EX_TOOLWINDOW)) {
return false;
}
RECT rect = { 0, 0, 0, 0 };
Expand Down

0 comments on commit d9ce1c4

Please sign in to comment.