From 42a565a0eb71b2ea9a70a156fef4fefc3a979329 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 4 Jun 2014 16:03:02 -0300 Subject: [PATCH] Fixed love.joystick.loadGamepadMappings to properly enable currently connected Joysticks as Gamepads when necessary. --- src/modules/joystick/JoystickModule.h | 7 +++++-- src/modules/joystick/sdl/JoystickModule.cpp | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/modules/joystick/JoystickModule.h b/src/modules/joystick/JoystickModule.h index 6478e4c48..aca2819f3 100644 --- a/src/modules/joystick/JoystickModule.h +++ b/src/modules/joystick/JoystickModule.h @@ -86,12 +86,15 @@ public: virtual Joystick::JoystickInput getGamepadMapping(const std::string &pguid, Joystick::GamepadInput gpinput) = 0; /** - * + * Loads a newline-separated list of virtual Gamepad mapping strings for + * multiple joysticks at a time. The mapping strings must have been + * generated with saveGamepadMapping, via Steam, or some other tool which + * generates SDL GameController mappings. **/ virtual void loadGamepadMappings(const std::string &mappings) = 0; /** - * + * Gets the virtual Gamepad mapping string for the specified joystick GUID. **/ virtual std::string saveGamepadMapping(const std::string &pguid) = 0; diff --git a/src/modules/joystick/sdl/JoystickModule.cpp b/src/modules/joystick/sdl/JoystickModule.cpp index 9c156fced..e634c9b5e 100644 --- a/src/modules/joystick/sdl/JoystickModule.cpp +++ b/src/modules/joystick/sdl/JoystickModule.cpp @@ -496,6 +496,14 @@ void JoystickModule::loadGamepadMappings(const std::string &mappings) } success = success || (SDL_GameControllerAddMapping(mapping.c_str()) != -1); + + if (success) + { + // FIXME: massive hack until missing APIs are added to SDL 2: + // https://bugzilla.libsdl.org/show_bug.cgi?id=1975 + std::string guid = mapping.substr(0, mapping.find_first_of(',')); + checkGamepads(guid); + } } if (!success)