Windows QPA: Don't highlight the first entry of the system menu if not appropriate

Only menu brought up by keyboard should highlight the first entry,
if the system menu is triggered by right clicking the title bar, there
should be no highlighted menu items.

What we do in QWindowsKeyMapper is not temporary changes, the first entry
will always be highlighted unless we unhighlight it manually.

Amends commit 64d65a645c3f64c6b317aed571366bc049c1cd25

Pick-to: 6.4
Change-Id: I22c887478fd928264bfa35b9b3a8b67e16a6c649
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
Yuhang Zhao 2022-08-29 10:43:45 +08:00
parent af4f7fe471
commit d6a36c521e

View File

@ -817,6 +817,12 @@ static void showSystemMenu(QWindow* w)
pos.x(), pos.y() + titleBarOffset,
topLevelHwnd,
nullptr);
// Remove the highlight of the restore menu item, otherwise when the user right-clicks
// on the title bar, the popuped system menu will also highlight the restore item, which
// is not appropriate, it should only be highlighted if the menu is brought up by keyboard.
HiliteMenuItem(topLevelHwnd, menu, SC_RESTORE, MF_BYCOMMAND | MFS_UNHILITE);
if (ret)
qWindowsWndProc(topLevelHwnd, WM_SYSCOMMAND, WPARAM(ret), 0);
}