mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-18 14:40:56 +00:00
Change quit tip based on whether gamepads are attached
This commit is contained in:
+17
-1
@@ -3,6 +3,7 @@ import QtQuick.Controls 2.2
|
|||||||
import QtQuick.Dialogs 1.2
|
import QtQuick.Dialogs 1.2
|
||||||
import QtQuick.Window 2.2
|
import QtQuick.Window 2.2
|
||||||
|
|
||||||
|
import SdlGamepadKeyNavigation 1.0
|
||||||
import Session 1.0
|
import Session 1.0
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
@@ -58,11 +59,26 @@ Item {
|
|||||||
toast.visible = true
|
toast.visible = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// It's important that we don't call enable() here
|
||||||
|
// or it may interfere with the Session instance
|
||||||
|
// getting notified of initial connected gamepads.
|
||||||
|
SdlGamepadKeyNavigation {
|
||||||
|
id: gamepadKeyNav
|
||||||
|
}
|
||||||
|
|
||||||
onVisibleChanged: {
|
onVisibleChanged: {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
// Hide the toolbar before we start loading
|
// Hide the toolbar before we start loading
|
||||||
toolBar.visible = false
|
toolBar.visible = false
|
||||||
|
|
||||||
|
// Set the hint text. We do this here rather than
|
||||||
|
// in the hintText control itself to synchronize
|
||||||
|
// with Session.exec() which requires no concurrent
|
||||||
|
// gamepad usage.
|
||||||
|
hintText.text = gamepadKeyNav.getConnectedGamepads() > 0 ?
|
||||||
|
"Tip: Press Start+Select+L1+R1 to disconnect your session" :
|
||||||
|
"Tip: Press Ctrl+Alt+Shift+Q to disconnect your session"
|
||||||
|
|
||||||
// Hook up our signals
|
// Hook up our signals
|
||||||
session.stageStarting.connect(stageStarting)
|
session.stageStarting.connect(stageStarting)
|
||||||
session.stageFailed.connect(stageFailed)
|
session.stageFailed.connect(stageFailed)
|
||||||
@@ -118,7 +134,7 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: "Tip: Press Ctrl+Alt+Shift+Q to disconnect your session"
|
id: hintText
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
anchors.bottomMargin: 50
|
anchors.bottomMargin: 50
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
|||||||
@@ -244,3 +244,23 @@ void SdlGamepadKeyNavigation::setSettingsMode(bool settingsMode)
|
|||||||
{
|
{
|
||||||
m_SettingsMode = settingsMode;
|
m_SettingsMode = settingsMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SdlGamepadKeyNavigation::getConnectedGamepads()
|
||||||
|
{
|
||||||
|
if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) != 0) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) failed: %s",
|
||||||
|
SDL_GetError());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < SDL_NumJoysticks(); i++) {
|
||||||
|
if (SDL_IsGameController(i)) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE void setSettingsMode(bool settingsMode);
|
Q_INVOKABLE void setSettingsMode(bool settingsMode);
|
||||||
|
|
||||||
|
Q_INVOKABLE int getConnectedGamepads();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void sendKey(QEvent::Type type, Qt::Key key, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
|
void sendKey(QEvent::Type type, Qt::Key key, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user