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
|
- CMake: Add ability to just print version string
|
||||||
- Qt: Merge "Save" and "OK" buttons in shader options
|
- Qt: Merge "Save" and "OK" buttons in shader options
|
||||||
- SDL: Automatically map controllers when plugged in
|
- SDL: Automatically map controllers when plugged in
|
||||||
|
- Qt: Automatically load controller profile when plugged in
|
||||||
|
|
||||||
0.5.2: (2016-12-31)
|
0.5.2: (2016-12-31)
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
|
|
@ -286,7 +286,12 @@ void InputController::bindKey(uint32_t type, int key, GBAKey gbaKey) {
|
||||||
|
|
||||||
void InputController::updateJoysticks() {
|
void InputController::updateJoysticks() {
|
||||||
#ifdef BUILD_SDL
|
#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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ bool mSDLInitEvents(struct mSDLEvents* context) {
|
||||||
int nJoysticks = SDL_NumJoysticks();
|
int nJoysticks = SDL_NumJoysticks();
|
||||||
SDL_JoystickListInit(&context->joysticks, nJoysticks);
|
SDL_JoystickListInit(&context->joysticks, nJoysticks);
|
||||||
if (nJoysticks > 0) {
|
if (nJoysticks > 0) {
|
||||||
mSDLUpdateJoysticks(context);
|
mSDLUpdateJoysticks(context, NULL);
|
||||||
// Some OSes don't do hotplug detection
|
// Some OSes don't do hotplug detection
|
||||||
if (!SDL_JoystickListSize(&context->joysticks)) {
|
if (!SDL_JoystickListSize(&context->joysticks)) {
|
||||||
int i;
|
int i;
|
||||||
|
@ -325,7 +325,7 @@ void mSDLPlayerChangeJoystick(struct mSDLEvents* events, struct mSDLPlayer* play
|
||||||
player->joystick = SDL_JoystickListGetPointer(&events->joysticks, index);
|
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
|
// Pump SDL joystick events without eating the rest of the events
|
||||||
SDL_JoystickUpdate();
|
SDL_JoystickUpdate();
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
|
@ -339,20 +339,23 @@ void mSDLUpdateJoysticks(struct mSDLEvents* events) {
|
||||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||||
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;
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
if (events->preferredJoysticks[i] && strcmp(events->preferredJoysticks[i], joystickName) == 0) {
|
||||||
events->players[i]->joystick = joystick;
|
events->players[i]->joystick = joystick;
|
||||||
|
if (config) {
|
||||||
|
mInputProfileLoad(events->players[i]->bindings, SDL_BINDING_BUTTON, config, joystickName);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -361,6 +364,9 @@ void mSDLUpdateJoysticks(struct mSDLEvents* events) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
events->players[i]->joystick = joystick;
|
events->players[i]->joystick = joystick;
|
||||||
|
if (config) {
|
||||||
|
mInputProfileLoad(events->players[i]->bindings, SDL_BINDING_BUTTON, config, joystickName);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if (event.type == SDL_JOYDEVICEREMOVED) {
|
} else if (event.type == SDL_JOYDEVICEREMOVED) {
|
||||||
|
|
|
@ -96,7 +96,7 @@ bool mSDLAttachPlayer(struct mSDLEvents*, struct mSDLPlayer*);
|
||||||
void mSDLDetachPlayer(struct mSDLEvents*, struct mSDLPlayer*);
|
void mSDLDetachPlayer(struct mSDLEvents*, struct mSDLPlayer*);
|
||||||
void mSDLEventsLoadConfig(struct mSDLEvents*, const struct Configuration*);
|
void mSDLEventsLoadConfig(struct mSDLEvents*, const struct Configuration*);
|
||||||
void mSDLPlayerChangeJoystick(struct mSDLEvents*, struct mSDLPlayer*, size_t index);
|
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 mSDLPlayerLoadConfig(struct mSDLPlayer*, const struct Configuration*);
|
||||||
void mSDLPlayerSaveConfig(const struct mSDLPlayer*, struct Configuration*);
|
void mSDLPlayerSaveConfig(const struct mSDLPlayer*, struct Configuration*);
|
||||||
|
|
Loading…
Reference in New Issue