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
title: qsTr("FramelessHelper demo application - Qt Quick [") + objectName + ']'
color: {
if (FramelessHelper.blurBehindWindowEnabled) {
if (FramelessHelper.blurBehindWindowEnabled && FramelessUtils.blurBehindWindowSupported) {
return "transparent";
}
if (FramelessUtils.systemTheme === FramelessHelperConstants.Dark) {

View File

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

View File

@ -34,6 +34,7 @@
#include <QtWidgets/qboxlayout.h>
#include <QtWidgets/qfileiconprovider.h>
#include <FramelessHelper/Core/framelessmanager.h>
#include <FramelessHelper/Core/utils.h>
#include <FramelessHelper/Widgets/framelesswidgetshelper.h>
#include <FramelessHelper/Widgets/standardtitlebar.h>
#include <FramelessHelper/Widgets/standardsystembutton.h>
@ -187,7 +188,7 @@ void Widget::updateStyleSheet()
m_clockLabel->setStyleSheet(labelStyleSheet);
m_compilerInfoLabel->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;"));
} else {
const QColor windowBackgroundColor = (dark ? kDefaultSystemDarkColor : kDefaultSystemLightColor);

View File

@ -843,15 +843,42 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
const auto clientHeight = RECT_HEIGHT(clientRect);
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;
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
// 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/
// fullscreened/minimized, of course).
if (Utils::isWindowNoState(windowId)) {
static constexpr const int kBorderSize = 2;
const bool isTop = (nativeLocalPos.y <= kBorderSize);
const bool isRight = (nativeLocalPos.x >= (clientWidth - kBorderSize));
if (isTop || isRight) {
if (dontOverrideCursor) {
// The user doesn't want the window to be resized, so we tell Windows we are
// in the client area so that the controls beneath the mouse cursor can still
// be hovered or clicked.
*result = (isTitleBar ? HTCAPTION : HTCLIENT);
} else {
if (isTop && isRight) {
*result = HTTOPRIGHT;
} else if (isTop) {
@ -859,7 +886,10 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
} 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.
// The Snap Layout feature introduced in Windows 11 won't work without this.
switch (sysButtonType) {
@ -880,10 +910,14 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
*result = HTCLOSE;
break;
case SystemButtonType::Unknown:
*result = HTCLIENT; // Normally we'd never enter this branch.
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;
}
// 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 int frameSizeY = Utils::getResizeBorderThickness(windowId, false, true);
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) {
// This will handle the left, right and bottom parts of the frame
// because we didn't change them.
const LRESULT originalHitTestResult = ::DefWindowProcW(hWnd, WM_NCHITTEST, 0, lParam);
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);
return true;
}
@ -933,7 +957,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
// Return HTCLIENT instead of HTBORDER here, because the mouse is
// inside our homemade title bar now, return HTCLIENT to let our
// title bar can still capture mouse events.
*result = ((isFixedSize || dontOverrideCursor) ? HTCLIENT : HTTOP);
*result = ((isFixedSize || dontOverrideCursor) ? (isTitleBar ? HTCAPTION : HTCLIENT) : HTTOP);
return true;
}
if (isTitleBar) {
@ -962,7 +986,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
// Return HTCLIENT instead of HTBORDER here, because the mouse is
// inside the window now, return HTCLIENT to let the controls
// inside our window can still capture mouse events.
*result = HTCLIENT;
*result = (isTitleBar ? HTCAPTION : HTCLIENT);
return true;
}
if (isTop) {

View File

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

View File

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