From 6d40c61850ea7c69e63adf65949b629377204eb1 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 26 Jan 2026 23:46:57 -0600 Subject: [PATCH] Only set initial MenuItem focus if not activating via mouse Having an initially highlighted item when using mouse navigation doesn't adhere to UX norms and also can lead to a janky feeling when the focus flip-flops from the item under the user's cursor to the first item as the Menu opens. --- app/gui/AppView.qml | 1 + app/gui/NavigableMenu.qml | 17 +++++++++++------ app/gui/PcView.qml | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/gui/AppView.qml b/app/gui/AppView.qml index 8afa1f07..f0062fbe 100644 --- a/app/gui/AppView.qml +++ b/app/gui/AppView.qml @@ -288,6 +288,7 @@ CenteredGridView { asynchronous: true sourceComponent: NavigableMenu { id: appContextMenu + initiator: appContextMenuLoader.parent NavigableMenuItem { text: model.running ? qsTr("Resume Game") : qsTr("Launch Game") onTriggered: launchOrResumeSelectedApp(true) diff --git a/app/gui/NavigableMenu.qml b/app/gui/NavigableMenu.qml index 72ba3ef0..a7b20f0d 100644 --- a/app/gui/NavigableMenu.qml +++ b/app/gui/NavigableMenu.qml @@ -2,13 +2,18 @@ import QtQuick 2.0 import QtQuick.Controls 2.2 Menu { + property var initiator + onOpened: { - // Give focus to the first visible and enabled menu item - for (var i = 0; i < count; i++) { - var item = itemAt(i) - if (item.visible && item.enabled) { - item.forceActiveFocus(Qt.TabFocusReason) - break + // If the initiating object currently has keyboard focus, + // give focus to the first visible and enabled menu item + if (initiator.focus) { + for (var i = 0; i < count; i++) { + var item = itemAt(i) + if (item.visible && item.enabled) { + item.forceActiveFocus(Qt.TabFocusReason) + break + } } } } diff --git a/app/gui/PcView.qml b/app/gui/PcView.qml index baecbebd..e80135c1 100644 --- a/app/gui/PcView.qml +++ b/app/gui/PcView.qml @@ -165,6 +165,7 @@ CenteredGridView { asynchronous: true sourceComponent: NavigableMenu { id: pcContextMenu + initiator: pcContextMenuLoader.parent MenuItem { text: qsTr("PC Status: %1").arg(model.online ? qsTr("Online") : qsTr("Offline")) font.bold: true