Qt: Automatically load controller profile when plugged in
Vicki Pfau vi@endrift.com
Mon, 23 Jan 2017 23:38:13 -0800
5 files changed,
24 insertions(+),
12 deletions(-)
M
CHANGES
→
CHANGES
@@ -54,6 +54,7 @@ - All: Move time.h include to common.h
- 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:
M
src/platform/qt/InputController.cpp
→
src/platform/qt/InputController.cpp
@@ -286,7 +286,12 @@ }
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 }
M
src/platform/qt/InputController.h
→
src/platform/qt/InputController.h
@@ -64,7 +64,7 @@
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;
M
src/platform/sdl/sdl-events.c
→
src/platform/sdl/sdl-events.c
@@ -59,7 +59,7 @@ SDL_JoystickEventState(SDL_ENABLE);
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 @@ }
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 @@ joystick->index = SDL_JoystickListSize(&events->joysticks) - 1;
#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 @@ if (events->players[i]->joystick) {
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) {
M
src/platform/sdl/sdl-events.h
→
src/platform/sdl/sdl-events.h
@@ -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*);