From faa5f5ad3169c3a0f6bfe2048f4a0062e39ca153 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Mon, 11 Nov 2024 11:22:07 +0100 Subject: [PATCH] qwindowssystemtrayicon: Fix position of popup window The code in QMenu::popup relies on QGuiApplicationPrivate::lastCursorPosition being up to date to decide on the final position of the popup being shown. As cursor movements outside of Qt windows do not trigger an update of that position, we have to do a forced update of it in QWindowsSystemTrayIcon::winEvent. Fixes: QTBUG-130832 Pick-to: 6.5 Change-Id: I45523688e21e294819337c69ad5b48eba5178446 Reviewed-by: Wladimir Leuschner Reviewed-by: Richard Moe Gustavsen (cherry picked from commit 922369844fcb75386237bca3eef59edd5093f58d) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/windows/qwindowssystemtrayicon.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp index 6f0680ac23a..21d15d4e78b 100644 --- a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp +++ b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp @@ -17,6 +17,8 @@ #include #include +#include + #include #include #include @@ -388,6 +390,10 @@ bool QWindowsSystemTrayIcon::winEvent(const MSG &message, long *result) // since hi-res coordinates are delivered in this case (Windows issue). // Default to primary screen with check to prevent a crash. const QPoint globalPos = QPoint(GET_X_LPARAM(message.wParam), GET_Y_LPARAM(message.wParam)); + // QTBUG-130832: QMenu relies on lastCursorPosition being up to date. When this code + // is called it still holds the last known mouse position inside a Qt window. Do a + // forced update of this position. + QGuiApplicationPrivate::lastCursorPosition = QCursor::pos().toPointF(); const auto &screenManager = QWindowsContext::instance()->screenManager(); const QPlatformScreen *screen = screenManager.screenAtDp(globalPos); if (!screen)