mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2025-07-03 08:15:37 +00:00
Don't poll gamepad input when the GUI is not focused/visible
This commit is contained in:
parent
9b3d4c1ad7
commit
2a63ad53d7
@ -2,7 +2,6 @@ import QtQuick 2.0
|
|||||||
import QtQuick.Controls 2.2
|
import QtQuick.Controls 2.2
|
||||||
|
|
||||||
import ComputerManager 1.0
|
import ComputerManager 1.0
|
||||||
import SdlGamepadKeyNavigation 1.0
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
function onSearchingComputer() {
|
function onSearchingComputer() {
|
||||||
@ -39,10 +38,6 @@ Item {
|
|||||||
if (!launcher.isExecuted()) {
|
if (!launcher.isExecuted()) {
|
||||||
toolBar.visible = false
|
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.searchingComputer.connect(onSearchingComputer)
|
||||||
launcher.pairing.connect(onPairing)
|
launcher.pairing.connect(onPairing)
|
||||||
launcher.failed.connect(onFailed)
|
launcher.failed.connect(onFailed)
|
||||||
|
@ -2,7 +2,6 @@ import QtQuick 2.0
|
|||||||
import QtQuick.Controls 2.2
|
import QtQuick.Controls 2.2
|
||||||
|
|
||||||
import ComputerManager 1.0
|
import ComputerManager 1.0
|
||||||
import SdlGamepadKeyNavigation 1.0
|
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
function onSearchingComputer() {
|
function onSearchingComputer() {
|
||||||
@ -38,10 +37,6 @@ Item {
|
|||||||
if (!launcher.isExecuted()) {
|
if (!launcher.isExecuted()) {
|
||||||
toolBar.visible = false
|
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.searchingComputer.connect(onSearchingComputer)
|
||||||
launcher.searchingApp.connect(onSearchingApp)
|
launcher.searchingApp.connect(onSearchingApp)
|
||||||
launcher.sessionCreated.connect(onSessionCreated)
|
launcher.sessionCreated.connect(onSessionCreated)
|
||||||
|
@ -7,7 +7,6 @@ import ComputerModel 1.0
|
|||||||
import ComputerManager 1.0
|
import ComputerManager 1.0
|
||||||
import StreamingPreferences 1.0
|
import StreamingPreferences 1.0
|
||||||
import SystemProperties 1.0
|
import SystemProperties 1.0
|
||||||
import SdlGamepadKeyNavigation 1.0
|
|
||||||
|
|
||||||
CenteredGridView {
|
CenteredGridView {
|
||||||
property ComputerModel computerModel : createModel()
|
property ComputerModel computerModel : createModel()
|
||||||
@ -34,11 +33,6 @@ CenteredGridView {
|
|||||||
// 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
|
// Highlight the first item if a gamepad is connected
|
||||||
if (currentIndex == -1 && SdlGamepadKeyNavigation.getConnectedGamepads() > 0) {
|
if (currentIndex == -1 && SdlGamepadKeyNavigation.getConnectedGamepads() > 0) {
|
||||||
currentIndex = 0
|
currentIndex = 0
|
||||||
|
@ -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.")
|
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
|
if (window.gamepadInputActive) {
|
||||||
|
// Re-enable GUI gamepad usage now
|
||||||
SdlGamepadKeyNavigation.enable()
|
SdlGamepadKeyNavigation.enable()
|
||||||
|
}
|
||||||
|
|
||||||
if (quitAfter) {
|
if (quitAfter) {
|
||||||
if (streamSegueErrorDialog.text) {
|
if (streamSegueErrorDialog.text) {
|
||||||
@ -119,9 +121,11 @@ Item {
|
|||||||
// Show the toolbar again when popped off the stack
|
// Show the toolbar again when popped off the stack
|
||||||
toolBar.visible = true
|
toolBar.visible = true
|
||||||
|
|
||||||
// Enable GUI gamepad usage now
|
if (window.gamepadInputActive) {
|
||||||
|
// Re-enable GUI gamepad usage now
|
||||||
SdlGamepadKeyNavigation.enable()
|
SdlGamepadKeyNavigation.enable()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StackView.onActivated: {
|
StackView.onActivated: {
|
||||||
// Hide the toolbar before we start loading
|
// Hide the toolbar before we start loading
|
||||||
|
@ -12,6 +12,7 @@ import SdlGamepadKeyNavigation 1.0
|
|||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
property bool pollingActive: false
|
property bool pollingActive: false
|
||||||
|
property bool gamepadInputActive: false
|
||||||
|
|
||||||
// Set by SettingsView to force the back operation to pop all
|
// Set by SettingsView to force the back operation to pop all
|
||||||
// pages except the initial view. This is required when doing
|
// pages except the initial view. This is required when doing
|
||||||
@ -22,7 +23,7 @@ ApplicationWindow {
|
|||||||
width: 1280
|
width: 1280
|
||||||
height: 600
|
height: 600
|
||||||
|
|
||||||
Component.onCompleted: {
|
function doEarlyInit() {
|
||||||
// Override the background color to Material 2 colors for Qt 6.5+
|
// Override the background color to Material 2 colors for Qt 6.5+
|
||||||
// in order to improve contrast between GFE's placeholder box art
|
// in order to improve contrast between GFE's placeholder box art
|
||||||
// and the background of the app grid.
|
// and the background of the app grid.
|
||||||
@ -30,6 +31,11 @@ ApplicationWindow {
|
|||||||
Material.background = "#303030"
|
Material.background = "#303030"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SdlGamepadKeyNavigation.enable()
|
||||||
|
gamepadInputActive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
// Show the window according to the user's preferences
|
// Show the window according to the user's preferences
|
||||||
if (SystemProperties.hasDesktopEnvironment) {
|
if (SystemProperties.hasDesktopEnvironment) {
|
||||||
if (StreamingPreferences.uiDisplayMode == StreamingPreferences.UI_MAXIMIZED) {
|
if (StreamingPreferences.uiDisplayMode == StreamingPreferences.UI_MAXIMIZED) {
|
||||||
@ -85,6 +91,14 @@ ApplicationWindow {
|
|||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
focus: true
|
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: {
|
onCurrentItemChanged: {
|
||||||
// Ensure focus travels to the next view when going back
|
// Ensure focus travels to the next view when going back
|
||||||
if (currentItem) {
|
if (currentItem) {
|
||||||
@ -147,6 +161,11 @@ ApplicationWindow {
|
|||||||
ComputerManager.stopPollingAsync()
|
ComputerManager.stopPollingAsync()
|
||||||
pollingActive = false
|
pollingActive = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gamepadInputActive) {
|
||||||
|
SdlGamepadKeyNavigation.disable()
|
||||||
|
gamepadInputActive = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (active) {
|
else if (active) {
|
||||||
// When we become visible and active again, start polling
|
// When we become visible and active again, start polling
|
||||||
@ -157,6 +176,10 @@ ApplicationWindow {
|
|||||||
ComputerManager.startPolling()
|
ComputerManager.startPolling()
|
||||||
pollingActive = true
|
pollingActive = true
|
||||||
}
|
}
|
||||||
|
if (!gamepadInputActive) {
|
||||||
|
SdlGamepadKeyNavigation.enable()
|
||||||
|
gamepadInputActive = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,11 +193,22 @@ ApplicationWindow {
|
|||||||
ComputerManager.startPolling()
|
ComputerManager.startPolling()
|
||||||
pollingActive = true
|
pollingActive = true
|
||||||
}
|
}
|
||||||
|
if (!gamepadInputActive) {
|
||||||
|
SdlGamepadKeyNavigation.enable()
|
||||||
|
gamepadInputActive = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Start the inactivity timer to stop polling
|
// Start the inactivity timer to stop polling
|
||||||
// if focus does not return within a few minutes.
|
// if focus does not return within a few minutes.
|
||||||
inactivityTimer.restart()
|
inactivityTimer.restart()
|
||||||
|
|
||||||
|
// Immediately stop gamepad input since we aren't
|
||||||
|
// the active window anymore.
|
||||||
|
if (gamepadInputActive) {
|
||||||
|
SdlGamepadKeyNavigation.disable()
|
||||||
|
gamepadInputActive = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user