mirror of https://github.com/mgba-emu/mgba.git
SDL: Use controller GUID instead of name
This commit is contained in:
parent
2583c5cae8
commit
0707cc2cc0
|
@ -232,7 +232,7 @@ void GBAKeyEditor::save() {
|
||||||
|
|
||||||
#ifdef BUILD_SDL
|
#ifdef BUILD_SDL
|
||||||
if (m_profileSelect) {
|
if (m_profileSelect) {
|
||||||
m_controller->setPreferredGamepad(m_type, m_profileSelect->currentText());
|
m_controller->setPreferredGamepad(m_type, m_profileSelect->currentIndex());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -267,11 +267,13 @@ void InputController::setGamepad(uint32_t type, int index) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputController::setPreferredGamepad(uint32_t type, const QString& device) {
|
void InputController::setPreferredGamepad(uint32_t type, int index) {
|
||||||
if (!m_config) {
|
if (!m_config) {
|
||||||
return;
|
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() {
|
mRumble* InputController::rumble() {
|
||||||
|
|
|
@ -83,7 +83,7 @@ public:
|
||||||
QStringList connectedGamepads(uint32_t type) const;
|
QStringList connectedGamepads(uint32_t type) const;
|
||||||
int gamepad(uint32_t type) const;
|
int gamepad(uint32_t type) const;
|
||||||
void setGamepad(uint32_t type, int index);
|
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 registerTiltAxisX(int axis);
|
||||||
void registerTiltAxisY(int axis);
|
void registerTiltAxisY(int axis);
|
||||||
|
|
|
@ -201,15 +201,15 @@ bool mSDLAttachPlayer(struct mSDLEvents* events, struct mSDLPlayer* player) {
|
||||||
firstUnclaimed = i;
|
firstUnclaimed = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* joystickName;
|
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
#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
|
#else
|
||||||
joystickName = SDL_JoystickName(SDL_JoystickIndex(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick));
|
const char* joystickName = SDL_JoystickName(SDL_JoystickIndex(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick));
|
||||||
#endif
|
|
||||||
if (!joystickName) {
|
if (!joystickName) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (events->preferredJoysticks[player->playerId] && strcmp(events->preferredJoysticks[player->playerId], joystickName) == 0) {
|
if (events->preferredJoysticks[player->playerId] && strcmp(events->preferredJoysticks[player->playerId], joystickName) == 0) {
|
||||||
index = i;
|
index = i;
|
||||||
break;
|
break;
|
||||||
|
@ -256,13 +256,14 @@ void mSDLPlayerLoadConfig(struct mSDLPlayer* context, const struct Configuration
|
||||||
if (context->joystick) {
|
if (context->joystick) {
|
||||||
mInputMapLoad(context->bindings, SDL_BINDING_BUTTON, config);
|
mInputMapLoad(context->bindings, SDL_BINDING_BUTTON, config);
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
#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
|
#else
|
||||||
const char* name = SDL_JoystickName(SDL_JoystickIndex(context->joystick->joystick));
|
const char* name = SDL_JoystickName(SDL_JoystickIndex(context->joystick->joystick));
|
||||||
#endif
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
mInputProfileLoad(context->bindings, SDL_BINDING_BUTTON, config, name);
|
mInputProfileLoad(context->bindings, SDL_BINDING_BUTTON, config, name);
|
||||||
|
|
||||||
const char* value;
|
const char* value;
|
||||||
|
@ -310,13 +311,14 @@ void mSDLPlayerLoadConfig(struct mSDLPlayer* context, const struct Configuration
|
||||||
void mSDLPlayerSaveConfig(const struct mSDLPlayer* context, struct Configuration* config) {
|
void mSDLPlayerSaveConfig(const struct mSDLPlayer* context, struct Configuration* config) {
|
||||||
if (context->joystick) {
|
if (context->joystick) {
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
#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
|
#else
|
||||||
const char* name = SDL_JoystickName(SDL_JoystickIndex(context->joystick->joystick));
|
const char* name = SDL_JoystickName(SDL_JoystickIndex(context->joystick->joystick));
|
||||||
#endif
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
char value[16];
|
char value[16];
|
||||||
snprintf(value, sizeof(value), "%i", context->rotation.axisX);
|
snprintf(value, sizeof(value), "%i", context->rotation.axisX);
|
||||||
mInputSetCustomValue(config, "gba", SDL_BINDING_BUTTON, "tiltAxisX", value, name);
|
mInputSetCustomValue(config, "gba", SDL_BINDING_BUTTON, "tiltAxisX", value, name);
|
||||||
|
@ -357,14 +359,15 @@ void mSDLUpdateJoysticks(struct mSDLEvents* events, const struct Configuration*
|
||||||
joystick->haptic = SDL_HapticOpenFromJoystick(joystick->joystick);
|
joystick->haptic = SDL_HapticOpenFromJoystick(joystick->joystick);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char* joystickName;
|
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
||||||
joystickName = SDL_JoystickName(joystick->joystick);
|
|
||||||
#else
|
|
||||||
joystickName = SDL_JoystickName(SDL_JoystickIndex(joystick->joystick));
|
|
||||||
#endif
|
|
||||||
size_t i;
|
size_t i;
|
||||||
if (joystickName) {
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
|
char joystickName[34] = {0};
|
||||||
|
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick->joystick), joystickName, sizeof(joystickName));
|
||||||
|
#else
|
||||||
|
const char* joystickName = SDL_JoystickName(SDL_JoystickIndex(joystick->joystick));
|
||||||
|
if (joystickName)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
for (i = 0; (int) i < events->playersAttached; ++i) {
|
for (i = 0; (int) i < events->playersAttached; ++i) {
|
||||||
if (events->players[i]->joystick) {
|
if (events->players[i]->joystick) {
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue