SDL: Use controller GUID instead of name
Vicki Pfau vi@endrift.com
Sat, 14 Dec 2019 16:43:50 -0800
4 files changed,
22 insertions(+),
17 deletions(-)
M
src/platform/qt/GBAKeyEditor.cpp
→
src/platform/qt/GBAKeyEditor.cpp
@@ -232,7 +232,7 @@ m_controller->saveConfiguration(m_type);
#ifdef BUILD_SDL if (m_profileSelect) { - m_controller->setPreferredGamepad(m_type, m_profileSelect->currentText()); + m_controller->setPreferredGamepad(m_type, m_profileSelect->currentIndex()); } #endif
M
src/platform/qt/InputController.cpp
→
src/platform/qt/InputController.cpp
@@ -267,11 +267,13 @@ }
#endif } -void InputController::setPreferredGamepad(uint32_t type, const QString& device) { +void InputController::setPreferredGamepad(uint32_t type, int index) { if (!m_config) { return; } - mInputSetPreferredDevice(m_config->input(), "gba", type, m_playerId, device.toUtf8().constData()); + char name[34] = {0}; + SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(SDL_JoystickListGetPointer(&s_sdlEvents.joysticks, index)->joystick), name, sizeof(name)); + mInputSetPreferredDevice(m_config->input(), "gba", type, m_playerId, name); } mRumble* InputController::rumble() {
M
src/platform/qt/InputController.h
→
src/platform/qt/InputController.h
@@ -83,7 +83,7 @@
QStringList connectedGamepads(uint32_t type) const; int gamepad(uint32_t type) const; void setGamepad(uint32_t type, int index); - void setPreferredGamepad(uint32_t type, const QString& device); + void setPreferredGamepad(uint32_t type, int index); void registerTiltAxisX(int axis); void registerTiltAxisY(int axis);
M
src/platform/sdl/sdl-events.c
→
src/platform/sdl/sdl-events.c
@@ -201,15 +201,15 @@ if (firstUnclaimed == SIZE_MAX) {
firstUnclaimed = i; } - const char* joystickName; #if SDL_VERSION_ATLEAST(2, 0, 0) - joystickName = SDL_JoystickName(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick); + char joystickName[34] = {0}; + SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick), joystickName, sizeof(joystickName)); #else - joystickName = SDL_JoystickName(SDL_JoystickIndex(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick)); -#endif + const char* joystickName = SDL_JoystickName(SDL_JoystickIndex(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick)); if (!joystickName) { continue; } +#endif if (events->preferredJoysticks[player->playerId] && strcmp(events->preferredJoysticks[player->playerId], joystickName) == 0) { index = i; break;@@ -256,13 +256,14 @@ mInputMapLoad(context->bindings, SDL_BINDING_KEY, config);
if (context->joystick) { mInputMapLoad(context->bindings, SDL_BINDING_BUTTON, config); #if SDL_VERSION_ATLEAST(2, 0, 0) - const char* name = SDL_JoystickName(context->joystick->joystick); + char name[34] = {0}; + SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(context->joystick->joystick), name, sizeof(name)); #else const char* name = SDL_JoystickName(SDL_JoystickIndex(context->joystick->joystick)); -#endif if (!name) { return; } +#endif mInputProfileLoad(context->bindings, SDL_BINDING_BUTTON, config, name); const char* value;@@ -310,13 +311,14 @@
void mSDLPlayerSaveConfig(const struct mSDLPlayer* context, struct Configuration* config) { if (context->joystick) { #if SDL_VERSION_ATLEAST(2, 0, 0) - const char* name = SDL_JoystickName(context->joystick->joystick); + char name[34] = {0}; + SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(context->joystick->joystick), name, sizeof(name)); #else const char* name = SDL_JoystickName(SDL_JoystickIndex(context->joystick->joystick)); -#endif if (!name) { return; } +#endif char value[16]; snprintf(value, sizeof(value), "%i", context->rotation.axisX); mInputSetCustomValue(config, "gba", SDL_BINDING_BUTTON, "tiltAxisX", value, name);@@ -357,14 +359,15 @@ #if SDL_VERSION_ATLEAST(2, 0, 0)
joystick->haptic = SDL_HapticOpenFromJoystick(joystick->joystick); #endif - const char* joystickName; + size_t i; #if SDL_VERSION_ATLEAST(2, 0, 0) - joystickName = SDL_JoystickName(joystick->joystick); + char joystickName[34] = {0}; + SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick->joystick), joystickName, sizeof(joystickName)); #else - joystickName = SDL_JoystickName(SDL_JoystickIndex(joystick->joystick)); + const char* joystickName = SDL_JoystickName(SDL_JoystickIndex(joystick->joystick)); + if (joystickName) #endif - size_t i; - if (joystickName) { + { for (i = 0; (int) i < events->playersAttached; ++i) { if (events->players[i]->joystick) { continue;