xbmc/xbmc — pull request #5357 by zzattack (2014-09-10 22:16:16+00:00)
Title: SDL Joystick fixes

This set of patches
* improves trigger button handling (21f5eb7 .. 823f09d)
* corrects handling of mixing simultaneous inputs from multiple controllers (27d4f1f7)
* cleans up `SDL_Joystick.cpp`

The problem with malfunctioning triggers for many controllers has 3 primary causes:
* XBMC makes an (often incorrect) assumption about the value SDL reports for such trigger axes in resting state (0 vs -32768)
* SDL is inconsistent with the initial reading of trigger axes (always 0 initially, even when fully depressed, but once touched and depressed -32768 is reported)
* The default 360 controller keymap for Linux is broken

Trigger axes for controllers with the `xpad` or `xboxdrv` driver report -32768 when they are fully depressed (vs 0 for `sixad` controllers). Triggers should be considered 1-directional in either scenario, but XBMC cannot know this. The `limit="+1"` hack in the keymaps cannot fix this either. I introduced an attribute for the keymap lines to specify which axes should be considered triggers (21f5eb77), which is exposed through `CButtonTranslator`. I've also fixed the keymap for the 360 controllers family (4387ab26). This axis-to-trigger mapping is then used to scale trigger amounts in range 0.0-1.0 (761b0c5f, 823f09dd), resulting in correct trigger handling.

Since `SDL_Joystick.cpp` is not equipped for handling multiple joysticks, some erratic behavior can be seen when using 2 joysticks simultaneously. For example, when pressing button X on controller 1, and pushing axis Y of controller 2, both the keymap action associated with button X on controller 1 as well as the action associated with axis Y of controller **1** are executed. My suggested fixes (27d4f1f7) slightly change the exposed API so minor alterations to `Application.cpp` were needed as well.

Since I've touched most of SDL_Joystick.cpp in 27d4f1f7 anyway, I went ahead and fixed up the formatting for the remainder of the file as well.