Windows QPA: Fix crash showing QSystemTrayIcon's context menu with PROCESS_DPI_UNAWARE

The coordinates of the WM_CONTEXT message may be out of any screen in
PROCESS_DPI_UNAWARE mode since hi-res coordinates are delivered in this case
(Windows issue). Default to primary screen with check to prevent a crash.

Fixes: QTBUG-67966
Change-Id: I1950360520e93cbf3509611b3057635769f6543a
Reviewed-by: Andre de la Rocha <andre.rocha@qt.io>
This commit is contained in:
Friedemann Kleint 2018-11-05 10:18:50 +01:00
parent c9d18d4a9c
commit 9137691e74

View File

@ -382,13 +382,21 @@ bool QWindowsSystemTrayIcon::winEvent(const MSG &message, long *result)
emit activated(DoubleClick); // release we must ignore it
break;
case WM_CONTEXTMENU: {
// QTBUG-67966: Coordinates may be out of any screen in PROCESS_DPI_UNAWARE mode
// 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));
const QPlatformScreen *screen = QWindowsContext::instance()->screenManager().screenAtDp(globalPos);
const auto &screenManager = QWindowsContext::instance()->screenManager();
const QPlatformScreen *screen = screenManager.screenAtDp(globalPos);
if (!screen)
screen = screenManager.screens().value(0);
if (screen) {
emit contextMenuRequested(globalPos, screen);
emit activated(Context);
if (m_menu)
m_menu->trackPopupMenu(message.hwnd, globalPos.x(), globalPos.y());
}
}
break;
case NIN_BALLOONUSERCLICK:
emit messageClicked();