From eded86bc10060dcbe37684796f15f9c340460cf5 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 22 Aug 2020 12:02:26 -0700 Subject: [PATCH] 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 --- app/streaming/input/input.cpp | 21 +++++++++++++++++++++ app/streaming/input/input.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/app/streaming/input/input.cpp b/app/streaming/input/input.cpp index cdff4b0b..154ba144 100644 --- a/app/streaming/input/input.cpp +++ b/app/streaming/input/input.cpp @@ -63,6 +63,23 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, NvComputer*, int s SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1"); #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 // to ensure we receive gamecontroller attach events for gamepads where // 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 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 // Hide SDL's cursor on Steam Link after quitting the stream. // FIXME: We should also do this for other situations where SDL diff --git a/app/streaming/input/input.h b/app/streaming/input/input.h index f882e81b..b6c467a4 100644 --- a/app/streaming/input/input.h +++ b/app/streaming/input/input.h @@ -135,6 +135,8 @@ private: GamepadState m_GamepadState[MAX_GAMEPADS]; QSet m_KeysDown; bool m_FakeCaptureActive; + QString m_OldIgnoreDevices; + QString m_OldIgnoreDevicesExcept; SDL_TouchFingerEvent m_LastTouchDownEvent; SDL_TouchFingerEvent m_LastTouchUpEvent;