From 4e4f04c174cd217b77396948e04b05acb8702d69 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 19 May 2019 11:08:23 -0700 Subject: [PATCH] Focus on first item when a gamepad is connected --- app/gui/AppView.qml | 6 ++++++ app/gui/PcView.qml | 11 +++++++++++ app/gui/SettingsView.qml | 5 +++++ app/gui/main.qml | 4 ---- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/gui/AppView.qml b/app/gui/AppView.qml index 50b535ed..ecd501d7 100644 --- a/app/gui/AppView.qml +++ b/app/gui/AppView.qml @@ -3,6 +3,7 @@ import QtQuick.Controls 2.2 import AppModel 1.0 import ComputerManager 1.0 +import SdlGamepadKeyNavigation 1.0 CenteredGridView { property int computerIndex @@ -32,6 +33,11 @@ CenteredGridView { StackView.onActivated: { appModel.computerLost.connect(computerLost) activated = true + + // Highlight the first item if a gamepad is connected + if (currentIndex == -1 && SdlGamepadKeyNavigation.getConnectedGamepads() > 0) { + currentIndex = 0 + } } StackView.onDeactivating: { diff --git a/app/gui/PcView.qml b/app/gui/PcView.qml index a6d3db58..e743ea2c 100644 --- a/app/gui/PcView.qml +++ b/app/gui/PcView.qml @@ -5,6 +5,7 @@ import ComputerModel 1.0 import ComputerManager 1.0 import StreamingPreferences 1.0 +import SdlGamepadKeyNavigation 1.0 CenteredGridView { property ComputerModel computerModel : createModel() @@ -27,6 +28,16 @@ CenteredGridView { StackView.onActivated: { // Setup signals on CM ComputerManager.computerAddCompleted.connect(addComplete) + + // This is a bit of a hack to do this here as opposed to main.qml, but + // we need it enabled before calling getConnectedGamepads() and PcView + // is never destroyed, so it should be okay. + SdlGamepadKeyNavigation.enable() + + // Highlight the first item if a gamepad is connected + if (currentIndex == -1 && SdlGamepadKeyNavigation.getConnectedGamepads() > 0) { + currentIndex = 0 + } } StackView.onDeactivating: { diff --git a/app/gui/SettingsView.qml b/app/gui/SettingsView.qml index e9b331e4..05ac41c9 100644 --- a/app/gui/SettingsView.qml +++ b/app/gui/SettingsView.qml @@ -28,6 +28,11 @@ Flickable { // This enables Tab and BackTab based navigation rather than arrow keys. // It is required to shift focus between controls on the settings page. SdlGamepadKeyNavigation.setUiNavMode(true) + + // Highlight the first item if a gamepad is connected + if (SdlGamepadKeyNavigation.getConnectedGamepads() > 0) { + resolutionComboBox.forceActiveFocus(Qt.TabFocus) + } } StackView.onDeactivating: { diff --git a/app/gui/main.qml b/app/gui/main.qml index 72fc5f95..cc353b31 100644 --- a/app/gui/main.qml +++ b/app/gui/main.qml @@ -19,10 +19,6 @@ ApplicationWindow { visibility: StreamingPreferences.startWindowed ? "Windowed" : "Maximized" - Component.onCompleted: { - SdlGamepadKeyNavigation.enable() - } - StackView { id: stackView initialItem: initialView