diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-11-05 10:18:50 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-11-09 08:06:18 +0000 |
commit | 9137691e745039f8ad9cdee2594a958e244ba341 (patch) | |
tree | 478ce1fc576176799e431ddc0642e04f52aeab79 | |
parent | eglfs_kms: initialize m_deviceListener (diff) | |
download | qtbase-9137691e745039f8ad9cdee2594a958e244ba341.tar.xz qtbase-9137691e745039f8ad9cdee2594a958e244ba341.zip |
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>
-rw-r--r-- | src/plugins/platforms/windows/qwindowssystemtrayicon.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp index 901d132ea5..3c27f2914d 100644 --- a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp +++ b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp @@ -382,12 +382,20 @@ 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); - emit contextMenuRequested(globalPos, screen); - emit activated(Context); - if (m_menu) - m_menu->trackPopupMenu(message.hwnd, globalPos.x(), globalPos.y()); + 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: |