From 2812f0861c99d9e82a3615a25e272def845b2090 Mon Sep 17 00:00:00 2001 From: Andre de la Rocha Date: Fri, 20 Sep 2019 18:12:42 +0200 Subject: [PATCH] Windows QPA: Fix close button not working on Windows 7 A previous change modified hit testing in the non-client area of fixed-size windows, in order to prevent showing a resize cursor when the windows are not resizable (QTBUG-77220). The change assigned HTCAPTION for any point over the entire title bar, including the top bar buttons, which on Windows 7 classic or basic desktop caused these buttons to become unresponsive. The present fix changes this behavior to redefine only the outer sizing frame, while letting the rest of the title bar be handled by DefWindowProc(). Fixes: QTBUG-78262 Change-Id: Id6e821a805c8333a67988f87c3727bed0c93290e Reviewed-by: Volker Hilsheimer Reviewed-by: Friedemann Kleint (cherry picked from commit a8ec52d5e76bc769ed63be1ad543be8f687e5dac) --- src/plugins/platforms/windows/qwindowswindow.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 7d511bf0d7e..febc30c325e 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -2642,10 +2642,16 @@ bool QWindowsWindow::handleNonClientHitTest(const QPoint &globalPos, LRESULT *re return true; } if (localPos.y() < 0) { - const int topResizeBarPos = -frameMargins().top(); - if (localPos.y() >= topResizeBarPos) + // We want to return HTCAPTION/true only over the outer sizing frame, not the entire title bar, + // otherwise the title bar buttons (close, etc.) become unresponsive on Windows 7 (QTBUG-78262). + // However, neither frameMargins() nor GetSystemMetrics(SM_CYSIZEFRAME), etc., give the correct + // sizing frame height in all Windows versions/scales. This empirical constant seems to work, though. + const int sizingHeight = 9; + const int topResizeBarPos = sizingHeight - frameMargins().top(); + if (localPos.y() < topResizeBarPos) { *result = HTCAPTION; // Extend caption over top resize bar, let's user move the window. - return true; + return true; + } } } if (fixedWidth && (localPos.x() < 0 || localPos.x() >= size.width())) {