snap layout: improve

This commit is contained in:
Yuhang Zhao 2023-08-25 18:19:32 +08:00
parent f7368d0a08
commit bdb1b5d68f
2 changed files with 23 additions and 9 deletions

View File

@ -58,6 +58,8 @@ FRAMELESSHELPER_BEGIN_NAMESPACE
using namespace Global;
static constexpr const auto kMessageTag = WPARAM(2546789017);
FRAMELESSHELPER_STRING_CONSTANT(MonitorFromWindow)
FRAMELESSHELPER_STRING_CONSTANT(GetMonitorInfoW)
FRAMELESSHELPER_STRING_CONSTANT(ScreenToClient)
@ -173,6 +175,11 @@ Q_GLOBAL_STATIC(FramelessWin32HelperInternal, g_framelessWin32HelperData)
return WindowPart::NotInterested;
}
[[nodiscard]] static inline constexpr bool isTaggedMessage(const WPARAM wParam)
{
return (wParam == kMessageTag);
}
[[nodiscard]] static inline bool listenForMouseLeave(const HWND hWnd, const bool nonClient)
{
Q_ASSERT(hWnd);
@ -340,7 +347,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
const auto emulateClientAreaMessage = [hWnd, uMsg, wParam, lParam](const std::optional<int> overrideMessage = std::nullopt) -> void {
const auto wparam = [uMsg, wParam]() -> WPARAM {
if (uMsg == WM_NCMOUSELEAVE) {
return 0;
return kMessageTag;
}
const quint64 keyState = Utils::getKeyState();
if ((uMsg >= WM_NCXBUTTONDOWN) && (uMsg <= WM_NCXBUTTONDBLCLK)) {
@ -424,7 +431,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
}
};
if (uMsg == WM_MOUSELEAVE) {
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
// to WM_MOUSEMOVE message and send it back to the window to be able to hover our
@ -998,9 +1005,13 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
if (nowWindowPart == WindowPart::NotInterested) {
std::ignore = listenForMouseLeave(hWnd, false);
}
if ((previousWindowPart == WindowPart::ChromeButton) && (nowWindowPart == WindowPart::ClientArea)) {
*result = FALSE;
return true;
if (previousWindowPart == WindowPart::ChromeButton) {
if (nowWindowPart == WindowPart::ClientArea) {
*result = FALSE;
return true;
} else if (nowWindowPart == WindowPart::NotInterested) {
emulateClientAreaMessage(WM_NCMOUSELEAVE);
}
}
} else {
if (uMsg == WM_NCMOUSEMOVE) {

View File

@ -323,8 +323,6 @@ void StandardTitleBarPrivate::initialize()
this, &StandardTitleBarPrivate::updateTitleBarColor);
connect(chromePalette, &ChromePalette::chromeButtonColorChanged,
this, &StandardTitleBarPrivate::updateChromeButtonColor);
q->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
q->setFixedHeight(kDefaultTitleBarHeight);
connect(window, &QWidget::windowIconChanged, this, [q](const QIcon &icon){
Q_UNUSED(icon);
q->update();
@ -337,7 +335,6 @@ void StandardTitleBarPrivate::initialize()
const auto titleBarLayout = new QHBoxLayout(q);
titleBarLayout->setSpacing(0);
titleBarLayout->setContentsMargins(0, 0, 0, 0);
q->setTitleLabelAlignment(Qt::AlignCenter);
#else // !Q_OS_MACOS
minimizeButton = new StandardSystemButton(SystemButtonType::Minimize, q);
connect(minimizeButton, &StandardSystemButton::clicked, window, &QWidget::showMinimized);
@ -377,7 +374,6 @@ void StandardTitleBarPrivate::initialize()
titleBarLayout->setContentsMargins(0, 0, 0, 0);
titleBarLayout->addStretch();
titleBarLayout->addLayout(systemButtonsOuterLayout);
q->setTitleLabelAlignment(Qt::AlignLeft | Qt::AlignVCenter);
#endif // Q_OS_MACOS
retranslateUi();
updateTitleBarColor();
@ -388,6 +384,13 @@ void StandardTitleBarPrivate::initialize()
StandardTitleBar::StandardTitleBar(QWidget *parent)
: QWidget(parent), d_ptr(new StandardTitleBarPrivate(this))
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setFixedHeight(kDefaultTitleBarHeight);
#ifdef Q_OS_MACOS
setTitleLabelAlignment(Qt::AlignCenter);
#else
setTitleLabelAlignment(Qt::AlignLeft | Qt::AlignVCenter);
#endif
}
StandardTitleBar::~StandardTitleBar() = default;