diff --git a/app/gui/StreamSegue.qml b/app/gui/StreamSegue.qml index 013a6832..09a40a5f 100644 --- a/app/gui/StreamSegue.qml +++ b/app/gui/StreamSegue.qml @@ -3,6 +3,7 @@ import QtQuick.Controls 2.2 import QtQuick.Dialogs 1.2 import QtQuick.Window 2.2 +import SdlGamepadKeyNavigation 1.0 import Session 1.0 Item { @@ -58,11 +59,26 @@ Item { 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: { if (visible) { // Hide the toolbar before we start loading 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 session.stageStarting.connect(stageStarting) session.stageFailed.connect(stageFailed) @@ -118,7 +134,7 @@ Item { } Label { - text: "Tip: Press Ctrl+Alt+Shift+Q to disconnect your session" + id: hintText anchors.bottom: parent.bottom anchors.bottomMargin: 50 anchors.horizontalCenter: parent.horizontalCenter diff --git a/app/gui/sdlgamepadkeynavigation.cpp b/app/gui/sdlgamepadkeynavigation.cpp index 65d45dd2..3f1f7047 100644 --- a/app/gui/sdlgamepadkeynavigation.cpp +++ b/app/gui/sdlgamepadkeynavigation.cpp @@ -244,3 +244,23 @@ void SdlGamepadKeyNavigation::setSettingsMode(bool 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; +} diff --git a/app/gui/sdlgamepadkeynavigation.h b/app/gui/sdlgamepadkeynavigation.h index b516a901..900b7edf 100644 --- a/app/gui/sdlgamepadkeynavigation.h +++ b/app/gui/sdlgamepadkeynavigation.h @@ -20,6 +20,8 @@ public: Q_INVOKABLE void setSettingsMode(bool settingsMode); + Q_INVOKABLE int getConnectedGamepads(); + private: void sendKey(QEvent::Type type, Qt::Key key, Qt::KeyboardModifiers modifiers = Qt::NoModifier);