Qt: Fix some controllers with multiple players (e.g. Mayflash GC adapter) getting duplicated

This commit is contained in:
Vicki Pfau 2024-07-01 20:52:04 -07:00
parent 0a57aca1a5
commit f394c51a75
2 changed files with 4 additions and 3 deletions

View File

@ -249,6 +249,7 @@ SDLGamepad::SDLGamepad(SDLInputDriver* driver, int index, QObject* parent)
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Joystick* joystick = SDL_JoystickListGetPointer(&s_sdlEvents.joysticks, m_index)->joystick; SDL_Joystick* joystick = SDL_JoystickListGetPointer(&s_sdlEvents.joysticks, m_index)->joystick;
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), m_guid, sizeof(m_guid)); SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), m_guid, sizeof(m_guid));
m_id = SDL_JoystickInstanceID(joystick);
#endif #endif
} }
@ -395,11 +396,10 @@ QString SDLGamepad::visibleName() const {
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
bool SDLGamepad::updateIndex() { bool SDLGamepad::updateIndex() {
char guid[34];
for (size_t i = 0; i < SDL_JoystickListSize(&s_sdlEvents.joysticks); ++i) { for (size_t i = 0; i < SDL_JoystickListSize(&s_sdlEvents.joysticks); ++i) {
SDL_Joystick* joystick = SDL_JoystickListGetPointer(&s_sdlEvents.joysticks, i)->joystick; SDL_Joystick* joystick = SDL_JoystickListGetPointer(&s_sdlEvents.joysticks, i)->joystick;
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), guid, sizeof(guid)); SDL_JoystickID id = SDL_JoystickInstanceID(joystick);
if (memcmp(guid, m_guid, 33) == 0) { if (id == m_id) {
m_index = i; m_index = i;
return true; return true;
} }

View File

@ -109,6 +109,7 @@ private:
size_t m_index; size_t m_index;
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
char m_guid[34]{}; char m_guid[34]{};
SDL_JoystickID m_id;
#endif #endif
bool verify() const; bool verify() const;