Focus on first item when a gamepad is connected
This commit is contained in:
parent
65c21f3392
commit
4e4f04c174
4 changed files with 22 additions and 4 deletions
|
|
@ -3,6 +3,7 @@ import QtQuick.Controls 2.2
|
||||||
|
|
||||||
import AppModel 1.0
|
import AppModel 1.0
|
||||||
import ComputerManager 1.0
|
import ComputerManager 1.0
|
||||||
|
import SdlGamepadKeyNavigation 1.0
|
||||||
|
|
||||||
CenteredGridView {
|
CenteredGridView {
|
||||||
property int computerIndex
|
property int computerIndex
|
||||||
|
|
@ -32,6 +33,11 @@ CenteredGridView {
|
||||||
StackView.onActivated: {
|
StackView.onActivated: {
|
||||||
appModel.computerLost.connect(computerLost)
|
appModel.computerLost.connect(computerLost)
|
||||||
activated = true
|
activated = true
|
||||||
|
|
||||||
|
// Highlight the first item if a gamepad is connected
|
||||||
|
if (currentIndex == -1 && SdlGamepadKeyNavigation.getConnectedGamepads() > 0) {
|
||||||
|
currentIndex = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StackView.onDeactivating: {
|
StackView.onDeactivating: {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import ComputerModel 1.0
|
||||||
|
|
||||||
import ComputerManager 1.0
|
import ComputerManager 1.0
|
||||||
import StreamingPreferences 1.0
|
import StreamingPreferences 1.0
|
||||||
|
import SdlGamepadKeyNavigation 1.0
|
||||||
|
|
||||||
CenteredGridView {
|
CenteredGridView {
|
||||||
property ComputerModel computerModel : createModel()
|
property ComputerModel computerModel : createModel()
|
||||||
|
|
@ -27,6 +28,16 @@ CenteredGridView {
|
||||||
StackView.onActivated: {
|
StackView.onActivated: {
|
||||||
// Setup signals on CM
|
// Setup signals on CM
|
||||||
ComputerManager.computerAddCompleted.connect(addComplete)
|
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: {
|
StackView.onDeactivating: {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,11 @@ Flickable {
|
||||||
// This enables Tab and BackTab based navigation rather than arrow keys.
|
// This enables Tab and BackTab based navigation rather than arrow keys.
|
||||||
// It is required to shift focus between controls on the settings page.
|
// It is required to shift focus between controls on the settings page.
|
||||||
SdlGamepadKeyNavigation.setUiNavMode(true)
|
SdlGamepadKeyNavigation.setUiNavMode(true)
|
||||||
|
|
||||||
|
// Highlight the first item if a gamepad is connected
|
||||||
|
if (SdlGamepadKeyNavigation.getConnectedGamepads() > 0) {
|
||||||
|
resolutionComboBox.forceActiveFocus(Qt.TabFocus)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StackView.onDeactivating: {
|
StackView.onDeactivating: {
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,6 @@ ApplicationWindow {
|
||||||
|
|
||||||
visibility: StreamingPreferences.startWindowed ? "Windowed" : "Maximized"
|
visibility: StreamingPreferences.startWindowed ? "Windowed" : "Maximized"
|
||||||
|
|
||||||
Component.onCompleted: {
|
|
||||||
SdlGamepadKeyNavigation.enable()
|
|
||||||
}
|
|
||||||
|
|
||||||
StackView {
|
StackView {
|
||||||
id: stackView
|
id: stackView
|
||||||
initialItem: initialView
|
initialItem: initialView
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue