From 8de42b3199aa56bc0332e0e14a0fa2ec1b177495 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 9 Feb 2019 19:59:01 -0800 Subject: [PATCH] Fix gamepad menu focus and dismissal issues --- app/gui/AppView.qml | 12 +++++++++++- app/gui/NavigableMenu.qml | 8 ++++++++ app/gui/NavigableMenuItem.qml | 8 ++++++++ app/gui/PcView.qml | 14 ++++++++------ app/qml.qrc | 1 + 5 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 app/gui/NavigableMenu.qml diff --git a/app/gui/AppView.qml b/app/gui/AppView.qml index 9418c085..8c8ffa8e 100644 --- a/app/gui/AppView.qml +++ b/app/gui/AppView.qml @@ -162,15 +162,24 @@ GridView { } } + Keys.onMenuPressed: { + if (model.running) { + // This will primarily be keyboard/gamepad driven so use + // open() instead of popup() + appContextMenu.open() + } + } + function doQuitGame() { quitAppDialog.appName = appModel.getRunningAppName() quitAppDialog.segueToStream = false quitAppDialog.open() } - Menu { + NavigableMenu { id: appContextMenu NavigableMenuItem { + parentMenu: appContextMenu text: model.running ? "Resume Game" : "Launch Game" onTriggered: { appContextMenu.close() @@ -178,6 +187,7 @@ GridView { } } NavigableMenuItem { + parentMenu: appContextMenu text: "Quit Game" onTriggered: doQuitGame() visible: model.running diff --git a/app/gui/NavigableMenu.qml b/app/gui/NavigableMenu.qml new file mode 100644 index 00000000..301437de --- /dev/null +++ b/app/gui/NavigableMenu.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 +import QtQuick.Controls 2.2 + +Menu { + onOpened: { + itemAt(0).forceActiveFocus(Qt.TabFocusReason) + } +} diff --git a/app/gui/NavigableMenuItem.qml b/app/gui/NavigableMenuItem.qml index 1de35f8d..7d9d4960 100644 --- a/app/gui/NavigableMenuItem.qml +++ b/app/gui/NavigableMenuItem.qml @@ -2,6 +2,10 @@ import QtQuick 2.0 import QtQuick.Controls 2.2 MenuItem { + // Qt 5.10 has a menu property, but we need to support 5.9 + // so we must make our own. + property Menu parentMenu + // Ensure focus can't be given to an invisible item enabled: visible height: visible ? implicitHeight : 0 @@ -10,4 +14,8 @@ MenuItem { Keys.onReturnPressed: { triggered() } + + Keys.onEscapePressed: { + parentMenu.close() + } } diff --git a/app/gui/PcView.qml b/app/gui/PcView.qml index 02957ca5..81b6165c 100644 --- a/app/gui/PcView.qml +++ b/app/gui/PcView.qml @@ -135,14 +135,10 @@ GridView { wrapMode: Text.Wrap } - Menu { + NavigableMenu { id: pcContextMenu NavigableMenuItem { - text: "Wake PC" - onTriggered: computerModel.wakeComputer(index) - visible: !model.addPc && !model.online && model.wakeable - } - NavigableMenuItem { + parentMenu: pcContextMenu text: "Delete PC" onTriggered: { deletePcDialog.pcIndex = index @@ -150,6 +146,12 @@ GridView { deletePcDialog.open() } } + NavigableMenuItem { + parentMenu: pcContextMenu + text: "Wake PC" + onTriggered: computerModel.wakeComputer(index) + visible: !model.addPc && !model.online && model.wakeable + } } onClicked: { diff --git a/app/qml.qrc b/app/qml.qrc index f74f5d68..73d49baf 100644 --- a/app/qml.qrc +++ b/app/qml.qrc @@ -13,5 +13,6 @@ gui/CliQuitStreamSegue.qml gui/CliStartStreamSegue.qml gui/AutoResizingComboBox.qml + gui/NavigableMenu.qml