Allow to specify gamepad GUIDs to be ignored when streaming

This commit is contained in:
FrogTheFrog 2023-09-02 16:00:05 +03:00 committed by Cameron Gutman
parent d165bf7498
commit 85d4037a89
3 changed files with 36 additions and 4 deletions

View File

@ -474,6 +474,17 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
return;
}
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(SDL_GameControllerGetJoystick(controller)),
guidStr, sizeof(guidStr));
if (m_IgnoreDeviceGuids.contains(guidStr, Qt::CaseInsensitive))
{
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Skipping ignored device with GUID: %s",
guidStr);
SDL_GameControllerClose(controller);
return;
}
state = &m_GamepadState[i];
if (m_MultiController) {
state->index = i;
@ -534,15 +545,18 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
}
#endif
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(SDL_GameControllerGetJoystick(state->controller)),
guidStr, sizeof(guidStr));
mapping = SDL_GameControllerMapping(state->controller);
name = SDL_GameControllerName(state->controller);
uint16_t vendorId = SDL_GameControllerGetVendor(state->controller);
uint16_t productId = SDL_GameControllerGetProduct(state->controller);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Gamepad %d (player %d) is: %s (haptic capabilities: 0x%x) (mapping: %s -> %s)",
"Gamepad %d (player %d) is: %s (VID/PID: 0x%.4x/0x%.4x) (haptic capabilities: 0x%x) (mapping: %s -> %s)",
i,
state->index,
name != nullptr ? name : "<null>",
vendorId,
productId,
hapticCaps,
guidStr,
mapping != nullptr ? mapping : "<null>");
@ -888,7 +902,14 @@ int SdlInputHandler::getAttachedGamepadMask()
count = mask = 0;
for (int i = 0; i < SDL_NumJoysticks(); i++) {
if (SDL_IsGameController(i)) {
mask |= (1 << count++);
char guidStr[33];
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i),
guidStr, sizeof(guidStr));
if (!m_IgnoreDeviceGuids.contains(guidStr, Qt::CaseInsensitive))
{
mask |= (1 << count++);
}
}
}

View File

@ -130,6 +130,16 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, int streamWidth, i
}
streamIgnoreDevices += m_OldIgnoreDevices;
// STREAM_IGNORE_DEVICE_GUIDS allows to specify additional devices to be ignored when starting
// the stream in case the scope of STREAM_GAMECONTROLLER_IGNORE_DEVICES is too broad. One such
// case is "Steam Virtual Gamepad" where everything is under the same VID/PID, but different GUIDs.
// Multiple GUIDs can be provided, but need to be separated by commas:
//
// <GUID>,<GUID>,<GUID>,...
//
QString streamIgnoreDeviceGuids = qgetenv("STREAM_IGNORE_DEVICE_GUIDS");
m_IgnoreDeviceGuids = streamIgnoreDeviceGuids.split(',', Qt::SkipEmptyParts);
// 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.

View File

@ -179,6 +179,7 @@ private:
bool m_FakeCaptureActive;
QString m_OldIgnoreDevices;
QString m_OldIgnoreDevicesExcept;
QStringList m_IgnoreDeviceGuids;
StreamingPreferences::CaptureSysKeysMode m_CaptureSystemKeysMode;
int m_MouseCursorCapturedVisibilityState;