Allow game controllers to be ignored during streaming only

STREAM_GAMECONTROLLER_IGNORE_DEVICES and STREAM_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT environment variables provide the same functionality as SDL_GAMECONTROLLER_IGNORE_DEVICES and SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT, with the difference being SDL_* variables take effect at all times (UI and streaming) while STREAM_* variables take place only while streaming.

Fixes #425
This commit is contained in:
Cameron Gutman 2020-08-22 12:02:26 -07:00
parent 5a7a49d1d5
commit eded86bc10
2 changed files with 23 additions and 0 deletions

View File

@ -63,6 +63,23 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, NvComputer*, int s
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
#endif #endif
m_OldIgnoreDevices = SDL_GetHint(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES);
m_OldIgnoreDevicesExcept = SDL_GetHint(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT);
QString streamIgnoreDevices = qgetenv("STREAM_GAMECONTROLLER_IGNORE_DEVICES");
QString streamIgnoreDevicesExcept = qgetenv("STREAM_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT");
if (!streamIgnoreDevices.isEmpty() && !streamIgnoreDevices.endsWith(',')) {
streamIgnoreDevices += ',';
}
streamIgnoreDevices += m_OldIgnoreDevices;
// For SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES, we use the union of SDL_GAMECONTROLLER_IGNORE_DEVICES
// and STREAM_GAMECONTROLLER_IGNORE_DEVICES while streaming. STREAM_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
// overrides SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT while streaming.
SDL_SetHint(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES, streamIgnoreDevices.toUtf8());
SDL_SetHint(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT, streamIgnoreDevicesExcept.toUtf8());
// We must initialize joystick explicitly before gamecontroller in order // We must initialize joystick explicitly before gamecontroller in order
// to ensure we receive gamecontroller attach events for gamepads where // to ensure we receive gamecontroller attach events for gamepads where
// SDL doesn't have a built-in mapping. By starting joystick first, we // SDL doesn't have a built-in mapping. By starting joystick first, we
@ -167,6 +184,10 @@ SdlInputHandler::~SdlInputHandler()
// Return background event handling to off // Return background event handling to off
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "0"); SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "0");
// Restore the ignored devices
SDL_SetHint(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES, m_OldIgnoreDevices.toUtf8());
SDL_SetHint(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT, m_OldIgnoreDevicesExcept.toUtf8());
#ifdef STEAM_LINK #ifdef STEAM_LINK
// Hide SDL's cursor on Steam Link after quitting the stream. // Hide SDL's cursor on Steam Link after quitting the stream.
// FIXME: We should also do this for other situations where SDL // FIXME: We should also do this for other situations where SDL

View File

@ -135,6 +135,8 @@ private:
GamepadState m_GamepadState[MAX_GAMEPADS]; GamepadState m_GamepadState[MAX_GAMEPADS];
QSet<short> m_KeysDown; QSet<short> m_KeysDown;
bool m_FakeCaptureActive; bool m_FakeCaptureActive;
QString m_OldIgnoreDevices;
QString m_OldIgnoreDevicesExcept;
SDL_TouchFingerEvent m_LastTouchDownEvent; SDL_TouchFingerEvent m_LastTouchDownEvent;
SDL_TouchFingerEvent m_LastTouchUpEvent; SDL_TouchFingerEvent m_LastTouchUpEvent;