win: fix some minor bugs

This commit is contained in:
Zhao Yuhang 2023-11-03 21:25:24 +08:00
parent a6c7b44b5d
commit 85a3fe1b2f
6 changed files with 65 additions and 34 deletions

View File

@ -35,7 +35,7 @@ FramelessApplicationWindow {
height: 600 height: 600
title: qsTr("FramelessHelper demo application - Qt Quick [") + objectName + ']' title: qsTr("FramelessHelper demo application - Qt Quick [") + objectName + ']'
color: { color: {
if (FramelessHelper.blurBehindWindowEnabled) { if (FramelessHelper.blurBehindWindowEnabled && FramelessUtils.blurBehindWindowSupported) {
return "transparent"; return "transparent";
} }
if (FramelessUtils.systemTheme === FramelessHelperConstants.Dark) { if (FramelessUtils.systemTheme === FramelessHelperConstants.Dark) {

View File

@ -35,7 +35,7 @@ FramelessWindow {
height: 600 height: 600
title: qsTr("FramelessHelper demo application - Qt Quick [") + objectName +']' title: qsTr("FramelessHelper demo application - Qt Quick [") + objectName +']'
color: { color: {
if (FramelessHelper.blurBehindWindowEnabled) { if (FramelessHelper.blurBehindWindowEnabled && FramelessUtils.blurBehindWindowSupported) {
return "transparent"; return "transparent";
} }
if (FramelessUtils.systemTheme === FramelessHelperConstants.Dark) { if (FramelessUtils.systemTheme === FramelessHelperConstants.Dark) {

View File

@ -34,6 +34,7 @@
#include <QtWidgets/qboxlayout.h> #include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qfileiconprovider.h> #include <QtWidgets/qfileiconprovider.h>
#include <FramelessHelper/Core/framelessmanager.h> #include <FramelessHelper/Core/framelessmanager.h>
#include <FramelessHelper/Core/utils.h>
#include <FramelessHelper/Widgets/framelesswidgetshelper.h> #include <FramelessHelper/Widgets/framelesswidgetshelper.h>
#include <FramelessHelper/Widgets/standardtitlebar.h> #include <FramelessHelper/Widgets/standardtitlebar.h>
#include <FramelessHelper/Widgets/standardsystembutton.h> #include <FramelessHelper/Widgets/standardsystembutton.h>
@ -187,7 +188,7 @@ void Widget::updateStyleSheet()
m_clockLabel->setStyleSheet(labelStyleSheet); m_clockLabel->setStyleSheet(labelStyleSheet);
m_compilerInfoLabel->setStyleSheet(labelStyleSheet); m_compilerInfoLabel->setStyleSheet(labelStyleSheet);
m_commitInfoLabel->setStyleSheet(labelStyleSheet); m_commitInfoLabel->setStyleSheet(labelStyleSheet);
if (FramelessWidgetsHelper::get(this)->isBlurBehindWindowEnabled()) { if (FramelessWidgetsHelper::get(this)->isBlurBehindWindowEnabled() && Utils::isBlurBehindWindowSupported()) {
setStyleSheet(FRAMELESSHELPER_STRING_LITERAL("background-color: transparent;")); setStyleSheet(FRAMELESSHELPER_STRING_LITERAL("background-color: transparent;"));
} else { } else {
const QColor windowBackgroundColor = (dark ? kDefaultSystemDarkColor : kDefaultSystemLightColor); const QColor windowBackgroundColor = (dark ? kDefaultSystemDarkColor : kDefaultSystemLightColor);

View File

@ -843,23 +843,53 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
const auto clientHeight = RECT_HEIGHT(clientRect); const auto clientHeight = RECT_HEIGHT(clientRect);
const QPoint qtScenePos = Utils::fromNativeLocalPosition(qWindow, QPoint(nativeLocalPos.x, nativeLocalPos.y)); const QPoint qtScenePos = Utils::fromNativeLocalPosition(qWindow, QPoint(nativeLocalPos.x, nativeLocalPos.y));
const bool isFixedSize = data->callbacks->isWindowFixedSize();
const bool isTitleBar = data->callbacks->isInsideTitleBarDraggableArea(qtScenePos);
const bool dontOverrideCursor = data->callbacks->getProperty(kDontOverrideCursorVar, false).toBool();
const bool dontToggleMaximize = data->callbacks->getProperty(kDontToggleMaximizeVar, false).toBool();
if (dontToggleMaximize) {
static bool warnedOnce = false;
if (!warnedOnce) {
warnedOnce = true;
DEBUG << "To disable window maximization, you should remove the "
"WS_MAXIMIZEBOX style from the window instead. FramelessHelper "
"won't do that for you, so you'll have to do it manually yourself.";
}
}
SystemButtonType sysButtonType = SystemButtonType::Unknown; SystemButtonType sysButtonType = SystemButtonType::Unknown;
if (data->callbacks->isInsideSystemButtons(qtScenePos, &sysButtonType)) { if (!isFixedSize && data->callbacks->isInsideSystemButtons(qtScenePos, &sysButtonType)) {
// Firstly, we set the hit test result to a default value to be able to detect whether we
// have changed it or not afterwards.
*result = HTNOWHERE;
// Even if the mouse is inside the chrome button area now, we should still allow the user // 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 // 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. // normal behavior of a native Win32 window (but only when the window is not maximized/
static constexpr const int kBorderSize = 2; // fullscreened/minimized, of course).
const bool isTop = (nativeLocalPos.y <= kBorderSize); if (Utils::isWindowNoState(windowId)) {
const bool isRight = (nativeLocalPos.x >= (clientWidth - kBorderSize)); static constexpr const int kBorderSize = 2;
if (isTop || isRight) { const bool isTop = (nativeLocalPos.y <= kBorderSize);
if (isTop && isRight) { const bool isRight = (nativeLocalPos.x >= (clientWidth - kBorderSize));
*result = HTTOPRIGHT; if (isTop || isRight) {
} else if (isTop) { if (dontOverrideCursor) {
*result = HTTOP; // The user doesn't want the window to be resized, so we tell Windows we are
} else { // in the client area so that the controls beneath the mouse cursor can still
*result = HTRIGHT; // be hovered or clicked.
*result = (isTitleBar ? HTCAPTION : HTCLIENT);
} else {
if (isTop && isRight) {
*result = HTTOPRIGHT;
} else if (isTop) {
*result = HTTOP;
} else {
*result = HTRIGHT;
}
}
} }
} else { }
if (*result == HTNOWHERE) {
// OK, we are now really inside one of the chrome buttons, tell Windows the exact role of our button. // OK, we are now really inside one of the chrome buttons, tell Windows the exact role of our button.
// The Snap Layout feature introduced in Windows 11 won't work without this. // The Snap Layout feature introduced in Windows 11 won't work without this.
switch (sysButtonType) { switch (sysButtonType) {
@ -880,10 +910,14 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
*result = HTCLOSE; *result = HTCLOSE;
break; break;
case SystemButtonType::Unknown: case SystemButtonType::Unknown:
*result = HTCLIENT; // Normally we'd never enter this branch.
break; break;
} }
} }
if (*result == HTNOWHERE) {
// OK, it seems we are not inside the window resize area, nor inside the chrome buttons,
// tell Windows we are in the client area to let Qt handle this event.
*result = HTCLIENT;
}
return true; return true;
} }
// OK, we are not inside of any chrome buttons, try to find out which part of the window // OK, we are not inside of any chrome buttons, try to find out which part of the window
@ -893,26 +927,16 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
const bool full = Utils::isFullScreen(windowId); const bool full = Utils::isFullScreen(windowId);
const int frameSizeY = Utils::getResizeBorderThickness(windowId, false, true); const int frameSizeY = Utils::getResizeBorderThickness(windowId, false, true);
const bool isTop = (nativeLocalPos.y < frameSizeY); const bool isTop = (nativeLocalPos.y < frameSizeY);
const bool isTitleBar = data->callbacks->isInsideTitleBarDraggableArea(qtScenePos);
const bool isFixedSize = data->callbacks->isWindowFixedSize();
const bool dontOverrideCursor = data->callbacks->getProperty(kDontOverrideCursorVar, false).toBool();
const bool dontToggleMaximize = data->callbacks->getProperty(kDontToggleMaximizeVar, false).toBool();
if (dontToggleMaximize) {
static bool once = false;
if (!once) {
once = true;
DEBUG << "To disable window maximization, you should remove the "
"WS_MAXIMIZEBOX style from the window instead. FramelessHelper "
"won't do that for you, so you'll have to do it manually yourself.";
}
}
if (frameBorderVisible) { if (frameBorderVisible) {
// This will handle the left, right and bottom parts of the frame // This will handle the left, right and bottom parts of the frame
// because we didn't change them. // because we didn't change them.
const LRESULT originalHitTestResult = ::DefWindowProcW(hWnd, WM_NCHITTEST, 0, lParam); const LRESULT originalHitTestResult = ::DefWindowProcW(hWnd, WM_NCHITTEST, 0, lParam);
if (originalHitTestResult != HTCLIENT) { if (originalHitTestResult != HTCLIENT) {
// Even if the window is not resizable, we still can't return HTCLIENT here because
// when we enters this code path, it means the mouse cursor is outside of the window,
// that is, the three transparent window resize area. Returning HTCLIENT will confuse
// Windows and we can't put our controls there anyway.
*result = ((isFixedSize || dontOverrideCursor) ? HTBORDER : originalHitTestResult); *result = ((isFixedSize || dontOverrideCursor) ? HTBORDER : originalHitTestResult);
return true; return true;
} }
@ -933,7 +957,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
// Return HTCLIENT instead of HTBORDER here, because the mouse is // Return HTCLIENT instead of HTBORDER here, because the mouse is
// inside our homemade title bar now, return HTCLIENT to let our // inside our homemade title bar now, return HTCLIENT to let our
// title bar can still capture mouse events. // title bar can still capture mouse events.
*result = ((isFixedSize || dontOverrideCursor) ? HTCLIENT : HTTOP); *result = ((isFixedSize || dontOverrideCursor) ? (isTitleBar ? HTCAPTION : HTCLIENT) : HTTOP);
return true; return true;
} }
if (isTitleBar) { if (isTitleBar) {
@ -962,7 +986,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
// Return HTCLIENT instead of HTBORDER here, because the mouse is // Return HTCLIENT instead of HTBORDER here, because the mouse is
// inside the window now, return HTCLIENT to let the controls // inside the window now, return HTCLIENT to let the controls
// inside our window can still capture mouse events. // inside our window can still capture mouse events.
*result = HTCLIENT; *result = (isTitleBar ? HTCAPTION : HTCLIENT);
return true; return true;
} }
if (isTop) { if (isTop) {

View File

@ -594,7 +594,10 @@ bool FramelessQuickHelperPrivate::shouldIgnoreMouseEvents(const QPoint &pos) con
if (!window) { if (!window) {
return false; return false;
} }
const auto withinFrameBorder = [&pos, window]() -> bool { const auto withinFrameBorder = [q, &pos, window]() -> bool {
if (q->isWindowFixedSize()) {
return false;
}
if (pos.y() < kDefaultResizeBorderThickness) { if (pos.y() < kDefaultResizeBorderThickness) {
return true; return true;
} }

View File

@ -655,6 +655,9 @@ bool FramelessWidgetsHelperPrivate::shouldIgnoreMouseEvents(const QPoint &pos) c
return false; return false;
} }
const auto withinFrameBorder = [this, &pos]() -> bool { const auto withinFrameBorder = [this, &pos]() -> bool {
if (isWidgetFixedSize(window)) {
return false;
}
if (pos.y() < kDefaultResizeBorderThickness) { if (pos.y() < kDefaultResizeBorderThickness) {
return true; return true;
} }