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

Commit

Permalink
snap layout: improve
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenx190 committed Aug 25, 2023
1 parent f7368d0 commit bdb1b5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
21 changes: 16 additions & 5 deletions src/core/framelesshelper_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 7 additions & 4 deletions src/widgets/standardtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit bdb1b5d

Please sign in to comment.