Skip to content

Commit

Permalink
Windows: Fix title bar size calculation
Browse files Browse the repository at this point in the history
The title bar calculation is terribly wrong and was
missed during review.

Pick-to: 6.9
Change-Id: I0c7a860e747465e6a5e4d8aa5415a9701cf170fd
Reviewed-by: Oliver Wolff <[email protected]>
  • Loading branch information
wangwenx190 committed Dec 17, 2024
1 parent f76c9bf commit f6af3a5
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/plugins/platforms/windows/qwindowswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,13 @@ static inline bool shouldApplyDarkFrame(const QWindow *w)
> windowPal.color(QPalette::Window).lightness();
}

static inline int getTitleBarHeight_sys(const UINT dpi)
{
// According to MS design manual, it should be 32px when DPI is 96.
return getResizeBorderThickness(dpi) +
::GetSystemMetricsForDpi(SM_CYCAPTION, dpi);
}

QWindowsWindowData
WindowCreationData::create(const QWindow *w, const WindowData &data, QString title) const
{
Expand Down Expand Up @@ -952,10 +959,12 @@ QWindowsWindowData
parentHandle, nullptr, appinst, nullptr);

if (w->flags().testFlags(Qt::ExpandedClientAreaHint)) {
const UINT dpi = ::GetDpiForWindow(result.hwnd);
const int titleBarHeight = getTitleBarHeight_sys(dpi);
result.hwndTitlebar = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT,
classTitleBarNameUtf16, classTitleBarNameUtf16,
WS_POPUP, 0, 0,
context->frameWidth, 32,
context->frameWidth, titleBarHeight,
result.hwnd, nullptr, appinst, nullptr);
}

Expand Down Expand Up @@ -2190,7 +2199,7 @@ QRect QWindowsWindow::normalGeometry() const
QMargins QWindowsWindow::safeAreaMargins() const
{
if (m_data.flags.testFlags(Qt::ExpandedClientAreaHint)) {
const int titleBarHeight = SM_CYSIZEFRAME + SM_CYCAPTION;
const int titleBarHeight = getTitleBarHeight_sys(savedDpi());

return QMargins(0, titleBarHeight, 0, 0);
}
Expand Down Expand Up @@ -2407,7 +2416,8 @@ void QWindowsWindow::handleGeometryChange()
transitionAnimatedCustomTitleBar();
}

MoveWindow(m_data.hwndTitlebar, m_data.geometry.x(), m_data.geometry.y(), m_data.geometry.width(), 32, true);
const int titleBarHeight = getTitleBarHeight_sys(savedDpi());
MoveWindow(m_data.hwndTitlebar, m_data.geometry.x(), m_data.geometry.y(), m_data.geometry.width(), titleBarHeight, true);
m_windowWasArranged = arranged;
}

Expand Down Expand Up @@ -3295,8 +3305,8 @@ bool QWindowsWindow::handleNonClientHitTest(const QPoint &globalPos, LRESULT *re
const int border = (IsZoomed(m_data.hwnd) || isFullScreen_sys()) ? 0 : getResizeBorderThickness(savedDpi());
if (isCustomized || isDefaultTitleBar) {
*result = HTCLIENT;
const int titleBarHeight = SM_CYSIZEFRAME + SM_CYCAPTION;;
const int titleButtonWidth = 46;
const int titleBarHeight = getTitleBarHeight_sys(savedDpi());
const int titleButtonWidth = titleBarHeight * 1.5;
int buttons = 1;
if (globalPos.y() < geom.top() + titleBarHeight) {
if (m_data.flags.testFlags(Qt::WindowCloseButtonHint) || isDefaultTitleBar) {
Expand Down Expand Up @@ -3452,8 +3462,8 @@ void QWindowsWindow::updateCustomTitlebar()
RECT windowRect;
GetWindowRect(hwnd, &windowRect);

const int titleBarHeight = SM_CYSIZEFRAME + SM_CYCAPTION;;
const int titleButtonWidth = 46;
const int titleBarHeight = getTitleBarHeight_sys(savedDpi());
const int titleButtonWidth = titleBarHeight * 1.5;
const int windowWidth = windowRect.right - windowRect.left;

POINT localPos;
Expand Down

0 comments on commit f6af3a5

Please sign in to comment.