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 <wladimir.leuschner@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit 922369844fcb75386237bca3eef59edd5093f58d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Oliver Wolff 2024-11-11 11:22:07 +01:00 committed by Qt Cherry-pick Bot
parent 1e7a6451f8
commit faa5f5ad31

View File

@ -17,6 +17,8 @@
#include <QtCore/qsettings.h>
#include <qpa/qwindowsysteminterface.h>
#include <QtGui/private/qguiapplication_p.h>
#include <commctrl.h>
#include <shellapi.h>
#include <shlobj.h>
@ -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)