mirror of https://github.com/mgba-emu/mgba.git
Qt: Automatically load controller profile when plugged in
This commit is contained in:
parent
2da3d3e6ba
commit
d2bf16b872
1
CHANGES
1
CHANGES
|
@ -54,6 +54,7 @@ Misc:
|
|||
- CMake: Add ability to just print version string
|
||||
- Qt: Merge "Save" and "OK" buttons in shader options
|
||||
- SDL: Automatically map controllers when plugged in
|
||||
- Qt: Automatically load controller profile when plugged in
|
||||
|
||||
0.5.2: (2016-12-31)
|
||||
Bugfixes:
|
||||
|
|
|
@ -286,7 +286,12 @@ void InputController::bindKey(uint32_t type, int key, GBAKey gbaKey) {
|
|||
|
||||
void InputController::updateJoysticks() {
|
||||
#ifdef BUILD_SDL
|
||||
mSDLUpdateJoysticks(&s_sdlEvents);
|
||||
QString profile = profileForType(SDL_BINDING_BUTTON);
|
||||
mSDLUpdateJoysticks(&s_sdlEvents, m_config->input());
|
||||
QString newProfile = profileForType(SDL_BINDING_BUTTON);
|
||||
if (profile != newProfile) {
|
||||
loadProfile(SDL_BINDING_BUTTON, newProfile);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
void bindAxis(uint32_t type, int axis, GamepadAxisEvent::Direction, GBAKey);
|
||||
void unbindAllAxes(uint32_t type);
|
||||
|
||||
void bindHat(uint32_t type, int hat, GamepadHatEvent::Direction, GBAKey);
|
||||
void bindHat(uint32_t type, int hat, GamepadHatEvent::Direction, GBAKey);
|
||||
|
||||
QStringList connectedGamepads(uint32_t type) const;
|
||||
int gamepad(uint32_t type) const;
|
||||
|
|
|
@ -59,7 +59,7 @@ bool mSDLInitEvents(struct mSDLEvents* context) {
|
|||
int nJoysticks = SDL_NumJoysticks();
|
||||
SDL_JoystickListInit(&context->joysticks, nJoysticks);
|
||||
if (nJoysticks > 0) {
|
||||
mSDLUpdateJoysticks(context);
|
||||
mSDLUpdateJoysticks(context, NULL);
|
||||
// Some OSes don't do hotplug detection
|
||||
if (!SDL_JoystickListSize(&context->joysticks)) {
|
||||
int i;
|
||||
|
@ -325,7 +325,7 @@ void mSDLPlayerChangeJoystick(struct mSDLEvents* events, struct mSDLPlayer* play
|
|||
player->joystick = SDL_JoystickListGetPointer(&events->joysticks, index);
|
||||
}
|
||||
|
||||
void mSDLUpdateJoysticks(struct mSDLEvents* events) {
|
||||
void mSDLUpdateJoysticks(struct mSDLEvents* events, const struct Configuration* config) {
|
||||
// Pump SDL joystick events without eating the rest of the events
|
||||
SDL_JoystickUpdate();
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|
@ -339,20 +339,23 @@ void mSDLUpdateJoysticks(struct mSDLEvents* events) {
|
|||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
joystick->haptic = SDL_HapticOpenFromJoystick(joystick->joystick);
|
||||
#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;
|
||||
for (i = 0; (int) i < events->playersAttached; ++i) {
|
||||
if (events->players[i]->joystick) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const char* joystickName;
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
joystickName = SDL_JoystickName(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick);
|
||||
#else
|
||||
joystickName = SDL_JoystickName(SDL_JoystickIndex(SDL_JoystickListGetPointer(&events->joysticks, i)->joystick));
|
||||
#endif
|
||||
if (events->preferredJoysticks[i] && strcmp(events->preferredJoysticks[i], joystickName) == 0) {
|
||||
events->players[i]->joystick = joystick;
|
||||
if (config) {
|
||||
mInputProfileLoad(events->players[i]->bindings, SDL_BINDING_BUTTON, config, joystickName);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -361,6 +364,9 @@ void mSDLUpdateJoysticks(struct mSDLEvents* events) {
|
|||
continue;
|
||||
}
|
||||
events->players[i]->joystick = joystick;
|
||||
if (config) {
|
||||
mInputProfileLoad(events->players[i]->bindings, SDL_BINDING_BUTTON, config, joystickName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (event.type == SDL_JOYDEVICEREMOVED) {
|
||||
|
|
|
@ -96,7 +96,7 @@ bool mSDLAttachPlayer(struct mSDLEvents*, struct mSDLPlayer*);
|
|||
void mSDLDetachPlayer(struct mSDLEvents*, struct mSDLPlayer*);
|
||||
void mSDLEventsLoadConfig(struct mSDLEvents*, const struct Configuration*);
|
||||
void mSDLPlayerChangeJoystick(struct mSDLEvents*, struct mSDLPlayer*, size_t index);
|
||||
void mSDLUpdateJoysticks(struct mSDLEvents* events);
|
||||
void mSDLUpdateJoysticks(struct mSDLEvents* events, const struct Configuration*);
|
||||
|
||||
void mSDLPlayerLoadConfig(struct mSDLPlayer*, const struct Configuration*);
|
||||
void mSDLPlayerSaveConfig(const struct mSDLPlayer*, struct Configuration*);
|
||||
|
|
Loading…
Reference in New Issue