Better fix for axis sorting with some Android controllers
authorSam Lantinga <slouken@libsdl.org>
Wed, 23 May 2018 17:15:35 -0700
changeset 11999f3fc4b3d54f6
parent 11998 76124cc14cbb
child 12000 bb2e9f36b7ff
Better fix for axis sorting with some Android controllers
android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java	Wed May 23 17:15:33 2018 -0700
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java	Wed May 23 17:15:35 2018 -0700
     1.3 @@ -144,7 +144,21 @@
     1.4      static class RangeComparator implements Comparator<InputDevice.MotionRange> {
     1.5          @Override
     1.6          public int compare(InputDevice.MotionRange arg0, InputDevice.MotionRange arg1) {
     1.7 -            return arg0.getAxis() - arg1.getAxis();
     1.8 +            // Some controllers, like the Moga Pro 2, return AXIS_GAS (22) for right trigger and AXIS_BRAKE (23) for left trigger - swap them so they're sorted in the right order for SDL
     1.9 +            int arg0Axis = arg0.getAxis();
    1.10 +            int arg1Axis = arg1.getAxis();
    1.11 +            if (arg0Axis == MotionEvent.AXIS_GAS) {
    1.12 +                arg0Axis = MotionEvent.AXIS_BRAKE;
    1.13 +            } else if (arg0Axis == MotionEvent.AXIS_BRAKE) {
    1.14 +                arg0Axis = MotionEvent.AXIS_GAS;
    1.15 +            }
    1.16 +            if (arg1Axis == MotionEvent.AXIS_GAS) {
    1.17 +                arg1Axis = MotionEvent.AXIS_BRAKE;
    1.18 +            } else if (arg1Axis == MotionEvent.AXIS_BRAKE) {
    1.19 +                arg1Axis = MotionEvent.AXIS_GAS;
    1.20 +            }
    1.21 +
    1.22 +            return arg0Axis - arg1Axis;
    1.23          }
    1.24      }
    1.25