diff --git a/app/gui/CliPair.qml b/app/gui/CliPair.qml index 083c4dbd..33b91029 100644 --- a/app/gui/CliPair.qml +++ b/app/gui/CliPair.qml @@ -2,7 +2,6 @@ import QtQuick 2.0 import QtQuick.Controls 2.2 import ComputerManager 1.0 -import SdlGamepadKeyNavigation 1.0 Item { function onSearchingComputer() { @@ -39,10 +38,6 @@ Item { if (!launcher.isExecuted()) { toolBar.visible = false - // Normally this is enabled by PcView, but we will won't - // load PcView when streaming from the command-line. - SdlGamepadKeyNavigation.enable() - launcher.searchingComputer.connect(onSearchingComputer) launcher.pairing.connect(onPairing) launcher.failed.connect(onFailed) diff --git a/app/gui/CliStartStreamSegue.qml b/app/gui/CliStartStreamSegue.qml index 14b4b7d2..b383bc80 100644 --- a/app/gui/CliStartStreamSegue.qml +++ b/app/gui/CliStartStreamSegue.qml @@ -2,7 +2,6 @@ import QtQuick 2.0 import QtQuick.Controls 2.2 import ComputerManager 1.0 -import SdlGamepadKeyNavigation 1.0 Item { function onSearchingComputer() { @@ -38,10 +37,6 @@ Item { if (!launcher.isExecuted()) { toolBar.visible = false - // Normally this is enabled by PcView, but we will won't - // load PcView when streaming from the command-line. - SdlGamepadKeyNavigation.enable() - launcher.searchingComputer.connect(onSearchingComputer) launcher.searchingApp.connect(onSearchingApp) launcher.sessionCreated.connect(onSessionCreated) diff --git a/app/gui/PcView.qml b/app/gui/PcView.qml index cc41f724..9a367375 100644 --- a/app/gui/PcView.qml +++ b/app/gui/PcView.qml @@ -7,7 +7,6 @@ import ComputerModel 1.0 import ComputerManager 1.0 import StreamingPreferences 1.0 import SystemProperties 1.0 -import SdlGamepadKeyNavigation 1.0 CenteredGridView { property ComputerModel computerModel : createModel() @@ -34,11 +33,6 @@ CenteredGridView { // 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 diff --git a/app/gui/StreamSegue.qml b/app/gui/StreamSegue.qml index 16177926..b3b0fd42 100644 --- a/app/gui/StreamSegue.qml +++ b/app/gui/StreamSegue.qml @@ -76,8 +76,10 @@ Item { streamSegueErrorDialog.text += "\n\n" + qsTr("This PC's Internet connection is blocking Moonlight. Streaming over the Internet may not work while connected to this network.") } - // Enable GUI gamepad usage now - SdlGamepadKeyNavigation.enable() + if (window.gamepadInputActive) { + // Re-enable GUI gamepad usage now + SdlGamepadKeyNavigation.enable() + } if (quitAfter) { if (streamSegueErrorDialog.text) { @@ -119,8 +121,10 @@ Item { // Show the toolbar again when popped off the stack toolBar.visible = true - // Enable GUI gamepad usage now - SdlGamepadKeyNavigation.enable() + if (window.gamepadInputActive) { + // Re-enable GUI gamepad usage now + SdlGamepadKeyNavigation.enable() + } } StackView.onActivated: { diff --git a/app/gui/main.qml b/app/gui/main.qml index 508f67b3..97532bbf 100644 --- a/app/gui/main.qml +++ b/app/gui/main.qml @@ -12,6 +12,7 @@ import SdlGamepadKeyNavigation 1.0 ApplicationWindow { property bool pollingActive: false + property bool gamepadInputActive: false // Set by SettingsView to force the back operation to pop all // pages except the initial view. This is required when doing @@ -22,7 +23,7 @@ ApplicationWindow { width: 1280 height: 600 - Component.onCompleted: { + function doEarlyInit() { // Override the background color to Material 2 colors for Qt 6.5+ // in order to improve contrast between GFE's placeholder box art // and the background of the app grid. @@ -30,6 +31,11 @@ ApplicationWindow { Material.background = "#303030" } + SdlGamepadKeyNavigation.enable() + gamepadInputActive = true + } + + Component.onCompleted: { // Show the window according to the user's preferences if (SystemProperties.hasDesktopEnvironment) { if (StreamingPreferences.uiDisplayMode == StreamingPreferences.UI_MAXIMIZED) { @@ -85,6 +91,14 @@ ApplicationWindow { anchors.fill: parent focus: true + onEmptyChanged: { + // Hijack this callback to perform our very early init + // that runs before the first StackView item is pushed + if (!empty) { + doEarlyInit(); + } + } + onCurrentItemChanged: { // Ensure focus travels to the next view when going back if (currentItem) { @@ -147,6 +161,11 @@ ApplicationWindow { ComputerManager.stopPollingAsync() pollingActive = false } + + if (gamepadInputActive) { + SdlGamepadKeyNavigation.disable() + gamepadInputActive = false + } } else if (active) { // When we become visible and active again, start polling @@ -157,6 +176,10 @@ ApplicationWindow { ComputerManager.startPolling() pollingActive = true } + if (!gamepadInputActive) { + SdlGamepadKeyNavigation.enable() + gamepadInputActive = true + } } } @@ -170,11 +193,22 @@ ApplicationWindow { ComputerManager.startPolling() pollingActive = true } + if (!gamepadInputActive) { + SdlGamepadKeyNavigation.enable() + gamepadInputActive = true + } } else { // Start the inactivity timer to stop polling // if focus does not return within a few minutes. inactivityTimer.restart() + + // Immediately stop gamepad input since we aren't + // the active window anymore. + if (gamepadInputActive) { + SdlGamepadKeyNavigation.disable() + gamepadInputActive = false + } } }