From 6bc6ed63cc53678a37a3f6337804741a10b55275 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Thu, 18 Mar 2021 09:48:55 +0800 Subject: [PATCH] Minor tweaks Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- framelesshelper.cpp | 8 ++++---- framelesshelper_win32.cpp | 16 ++++++++-------- utilities_win32.cpp | 10 ++++++---- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/framelesshelper.cpp b/framelesshelper.cpp index d693e78..1925527 100644 --- a/framelesshelper.cpp +++ b/framelesshelper.cpp @@ -226,7 +226,7 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event) } } } else { - if (window->windowStates().testFlag(Qt::WindowState::WindowNoState) + if ((window->windowState() == Qt::WindowState::WindowNoState) && !isInSpecificObjects(globalPoint, getIgnoreObjects(window)) && getResizable(window)) { if (!window->startSystemResize(edges)) { @@ -254,10 +254,10 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event) if (isInTitlebarArea(getMousePos(mouseEvent, true), getMousePos(mouseEvent, false), currentWindow)) { - if (currentWindow->windowStates().testFlag(Qt::WindowState::WindowFullScreen)) { + if (currentWindow->windowState() == Qt::WindowState::WindowFullScreen) { break; } - if (currentWindow->windowStates().testFlag(Qt::WindowState::WindowMaximized)) { + if (currentWindow->windowState() == Qt::WindowState::WindowMaximized) { currentWindow->showNormal(); } else { currentWindow->showMaximized(); @@ -282,7 +282,7 @@ bool FramelessHelper::eventFilter(QObject *object, QEvent *event) case QEvent::MouseMove: { const auto mouseEvent = static_cast(event); if (mouseEvent) { - if (currentWindow->windowStates().testFlag(Qt::WindowState::WindowNoState) + if ((currentWindow->windowState() == Qt::WindowState::WindowNoState) && getResizable(currentWindow)) { currentWindow->setCursor( getCursorShape(getWindowEdges(getMousePos(mouseEvent, false), diff --git a/framelesshelper_win32.cpp b/framelesshelper_win32.cpp index 7e787a0..0ce060f 100644 --- a/framelesshelper_win32.cpp +++ b/framelesshelper_win32.cpp @@ -289,7 +289,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me *result = 0; return true; } - bool nonclient = false; + bool nonClientAreaExists = false; const auto clientRect = &(reinterpret_cast(msg->lParam)->rgrc[0]); if (shouldHaveWindowFrame()) { // Store the original top before the default window proc @@ -308,7 +308,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me // We don't need this correction when we're fullscreen. We will // have the WS_POPUP size, so we don't have to worry about // borders, and the default frame will be fine. - if (IsMaximized(msg->hwnd) && !(window->windowState() & Qt::WindowFullScreen)) { + if (IsMaximized(msg->hwnd) && !(window->windowState() == Qt::WindowFullScreen)) { // Windows automatically adds a standard width border to all // sides when a window is maximized. We have to remove it // otherwise the content of our window will be cut-off from @@ -324,7 +324,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me clientRect->left += bw; clientRect->right -= bw; } - nonclient = true; + nonClientAreaExists = true; } // Attempt to detect if there's an autohide taskbar, and if // there is, reduce our size a bit on the side with the taskbar, @@ -399,16 +399,16 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me if (top) { // Peculiarly, when we're fullscreen, clientRect->top += kAutoHideTaskbarThicknessPy; - nonclient = true; + nonClientAreaExists = true; } else if (bottom) { clientRect->bottom -= kAutoHideTaskbarThicknessPy; - nonclient = true; + nonClientAreaExists = true; } else if (left) { clientRect->left += kAutoHideTaskbarThicknessPx; - nonclient = true; + nonClientAreaExists = true; } else if (right) { clientRect->right -= kAutoHideTaskbarThicknessPx; - nonclient = true; + nonClientAreaExists = true; } } } @@ -422,7 +422,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me // Windows exhibits bugs where client pixels and child HWNDs are // mispositioned by the width/height of the upper-left nonclient // area. - *result = nonclient ? 0 : WVR_REDRAW; + *result = nonClientAreaExists ? 0 : WVR_REDRAW; return true; } // These undocumented messages are sent to draw themed window diff --git a/utilities_win32.cpp b/utilities_win32.cpp index 2c70a29..54a0cda 100644 --- a/utilities_win32.cpp +++ b/utilities_win32.cpp @@ -742,16 +742,18 @@ void Utilities::displaySystemMenu(const QWindow *window, const QPoint &pos) SetMenuItemInfoW(hMenu, SC_MAXIMIZE, FALSE, &mii); SetMenuItemInfoW(hMenu, SC_MINIMIZE, FALSE, &mii); mii.fState = MF_GRAYED; - const auto isMin = [window]{ + const bool isMin = [window]{ return (window->windowState() == Qt::WindowMinimized); }(); - const auto isMax = [window]{ + const bool isMax = [window]{ return (window->windowState() == Qt::WindowMaximized); }(); - const auto isFull = [window]{ + const bool isFull = [window]{ return (window->windowState() == Qt::WindowFullScreen); }(); - const bool isNormal = !isMin && !isMax && !isFull; + const bool isNormal = [window]{ + return (window->windowState() == Qt::WindowNoState); + }(); const bool isFix = isWindowFixedSize(window); if (isFix || isMax || isFull) { SetMenuItemInfoW(hMenu, SC_SIZE, FALSE, &mii);