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

Commit

Permalink
little fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenx190 committed Aug 27, 2023
1 parent 6abb636 commit f584bd3
Showing 1 changed file with 22 additions and 37 deletions.
59 changes: 22 additions & 37 deletions src/core/framelesshelper_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,13 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
}
};

const auto clearWindowPartCache = [&data, &muData, &emulateClientAreaMessage]() -> void {
if (getHittedWindowPart(data.hitTestResult.second.value_or(HTNOWHERE)) == WindowPart::ChromeButton) {
emulateClientAreaMessage(WM_NCMOUSELEAVE);
muData.hitTestResult = {};
}
};

if ((uMsg == WM_MOUSELEAVE) && !isTaggedMessage(wParam)) {
// Qt will call TrackMouseEvent() to get the WM_MOUSELEAVE message when it receives
// WM_MOUSEMOVE messages, and since we are converting every WM_NCMOUSEMOVE message
Expand All @@ -461,6 +468,12 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
}
}

if (uMsg == WM_SIZE) {
if ((wParam == SIZE_MAXIMIZED) || (wParam == SIZE_MINIMIZED)) {
clearWindowPartCache();
}
}

switch (uMsg) {
#if (QT_VERSION < QT_VERSION_CHECK(5, 9, 0)) // Qt has done this for us since 5.9.0
case WM_NCCREATE: {
Expand Down Expand Up @@ -828,7 +841,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
// Even if the mouse is inside the chrome button area now, we should still allow the user
// to be able to resize the window with the top or right window border, this is also the
// normal behavior of a native Win32 window.
static constexpr const int kBorderSize = 1;
static constexpr const int kBorderSize = 2;
const bool isTop = (nativeLocalPos.y <= kBorderSize);
const bool isRight = (nativeLocalPos.x >= (clientWidth - kBorderSize));
if (isTop || isRight) {
Expand Down Expand Up @@ -1143,48 +1156,20 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
// Re-apply the custom window frame if recovered from the basic theme.
std::ignore = Utils::updateWindowFrameMargins(windowId, false);
} break;
case WM_ACTIVATE:
if (LOWORD(wParam) == WA_INACTIVE) {
clearWindowPartCache();
}
break;
case WM_INITMENU:
clearWindowPartCache();
break;
#if (QT_VERSION < QT_VERSION_CHECK(6, 5, 1))
case WM_ENTERSIZEMOVE: // Sent to a window when the user drags the title bar or the resize border.
case WM_EXITSIZEMOVE: // Sent to a window when the user releases the mouse button (from dragging the title bar or the resize border).
updateRestoreGeometry(false);
break;
case WM_ACTIVATE: {
auto filteredWParam = LOWORD(wParam);
if (filteredWParam == WA_INACTIVE) {
if (getHittedWindowPart(data.hitTestResult.second.value_or(HTNOWHERE)) == WindowPart::ChromeButton) {
emulateClientAreaMessage(WM_NCMOUSELEAVE);

// Clear window part cache
auto &hitTestResult = muData.hitTestResult;
hitTestResult.first.reset();
hitTestResult.second.reset();
}
}
break;
}
case WM_INITMENU:{
if (getHittedWindowPart(data.hitTestResult.second.value_or(HTNOWHERE)) == WindowPart::ChromeButton) {
emulateClientAreaMessage(WM_NCMOUSELEAVE);

// Clear window part cache
auto &hitTestResult = muData.hitTestResult;
hitTestResult.first.reset();
hitTestResult.second.reset();
}
break;
}
case WM_SIZE: {
if (wParam == SIZE_MAXIMIZED || wParam == SIZE_MINIMIZED) {
if (getHittedWindowPart(data.hitTestResult.second.value_or(HTNOWHERE)) == WindowPart::ChromeButton) {
emulateClientAreaMessage(WM_NCMOUSELEAVE);

// Clear window part cache
auto &hitTestResult = muData.hitTestResult;
hitTestResult.first.reset();
hitTestResult.second.reset();
}
break;
}
if (wParam != SIZE_MAXIMIZED) {
break;
}
Expand Down

0 comments on commit f584bd3

Please sign in to comment.