| Index: content/public/android/java/src/org/chromium/content/browser/input/GamepadMappings.java
|
| diff --git a/content/public/android/java/src/org/chromium/content/browser/input/GamepadMappings.java b/content/public/android/java/src/org/chromium/content/browser/input/GamepadMappings.java
|
| index 1ded67f0bddd1465d72c7892f92614398ec34f68..f924b7841e95235fc8c283aaa097716c8467cefb 100644
|
| --- a/content/public/android/java/src/org/chromium/content/browser/input/GamepadMappings.java
|
| +++ b/content/public/android/java/src/org/chromium/content/browser/input/GamepadMappings.java
|
| @@ -77,7 +77,14 @@ class GamepadMappings {
|
| mappedButtons[CanonicalButtonIndex.RIGHT_THUMBSTICK] = thumbR;
|
| }
|
|
|
| - private static void mapCommonTriggerButtons(float[] mappedButtons, float[] rawButtons) {
|
| + /**
|
| + * Method for mapping the L1/R1 buttons to lower shoulder buttons, rather than
|
| + * upper shoulder as the user would normally expect. Please think twice before
|
| + * using this, as it can easily confuse the user. It is only really useful if
|
| + * the controller completely lacks a second set of shoulder buttons
|
| + */
|
| + private static void mapUpperTriggerButtonsToBottomShoulder(float[] mappedButtons,
|
| + float[] rawButtons) {
|
| float l1 = rawButtons[KeyEvent.KEYCODE_BUTTON_L1];
|
| float r1 = rawButtons[KeyEvent.KEYCODE_BUTTON_R1];
|
| mappedButtons[CanonicalButtonIndex.LEFT_TRIGGER] = l1;
|
| @@ -117,13 +124,6 @@ class GamepadMappings {
|
| mappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y] = rawAxes[MotionEvent.AXIS_RZ];
|
| }
|
|
|
| - private static void mapTriggerAxexToShoulderButtons(float[] mappedButtons, float[] rawAxes) {
|
| - float lTrigger = rawAxes[MotionEvent.AXIS_LTRIGGER];
|
| - float rTrigger = rawAxes[MotionEvent.AXIS_RTRIGGER];
|
| - mappedButtons[CanonicalButtonIndex.LEFT_SHOULDER] = lTrigger;
|
| - mappedButtons[CanonicalButtonIndex.RIGHT_SHOULDER] = rTrigger;
|
| - }
|
| -
|
| private static void mapPedalAxesToBottomShoulder(float[] mappedButtons, float[] rawAxes) {
|
| float lTrigger = rawAxes[MotionEvent.AXIS_BRAKE];
|
| float rTrigger = rawAxes[MotionEvent.AXIS_GAS];
|
| @@ -131,6 +131,13 @@ class GamepadMappings {
|
| mappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER] = rTrigger;
|
| }
|
|
|
| + private static void mapAltPedalAxesToBottomShoulder(float[] mappedButtons, float[] rawAxes) {
|
| + float lTrigger = rawAxes[MotionEvent.AXIS_BRAKE];
|
| + float rTrigger = rawAxes[MotionEvent.AXIS_THROTTLE];
|
| + mappedButtons[CanonicalButtonIndex.LEFT_TRIGGER] = lTrigger;
|
| + mappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER] = rTrigger;
|
| + }
|
| +
|
| private static void mapTriggerAxesToBottomShoulder(float[] mappedButtons, float[] rawAxes) {
|
| float lTrigger = rawAxes[MotionEvent.AXIS_LTRIGGER];
|
| float rTrigger = rawAxes[MotionEvent.AXIS_RTRIGGER];
|
| @@ -138,6 +145,31 @@ class GamepadMappings {
|
| mappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER] = rTrigger;
|
| }
|
|
|
| + private static void mapLowerTriggerButtonsToBottomShoulder(float[] mappedButtons,
|
| + float[] rawButtons) {
|
| + float l2 = rawButtons[KeyEvent.KEYCODE_BUTTON_L2];
|
| + float r2 = rawButtons[KeyEvent.KEYCODE_BUTTON_R2];
|
| + mappedButtons[CanonicalButtonIndex.LEFT_TRIGGER] = l2;
|
| + mappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER] = r2;
|
| + }
|
| +
|
| + private static boolean triggersPopulated(float[] mappedButtons) {
|
| + return mappedButtons[CanonicalButtonIndex.LEFT_TRIGGER] != 0
|
| + || mappedButtons[CanonicalButtonIndex.RIGHT_TRIGGER] != 0;
|
| + }
|
| +
|
| + private static boolean dpadPopulated(float[] mappedButtons) {
|
| + return mappedButtons[CanonicalButtonIndex.DPAD_DOWN] != 0
|
| + || mappedButtons[CanonicalButtonIndex.DPAD_UP] != 0
|
| + || mappedButtons[CanonicalButtonIndex.DPAD_LEFT] != 0
|
| + || mappedButtons[CanonicalButtonIndex.DPAD_RIGHT] != 0;
|
| + }
|
| +
|
| + private static boolean rightStickPopulated(float[] mappedAxes) {
|
| + return mappedAxes[CanonicalAxisIndex.RIGHT_STICK_X] != 0
|
| + || mappedAxes[CanonicalAxisIndex.RIGHT_STICK_Y] != 0;
|
| + }
|
| +
|
| @VisibleForTesting
|
| static float negativeAxisValueAsButton(float input) {
|
| return (input < -0.5f) ? 1.f : 0.f;
|
| @@ -213,11 +245,11 @@ class GamepadMappings {
|
| mappedButtons[CanonicalButtonIndex.TERTIARY] = a;
|
| mappedButtons[CanonicalButtonIndex.QUATERNARY] = b;
|
|
|
| - mapCommonTriggerButtons(mappedButtons, rawButtons);
|
| + mapTriggerButtonsToTopShoulder(mappedButtons, rawButtons);
|
| mapCommonThumbstickButtons(mappedButtons, rawButtons);
|
| mapCommonDpadButtons(mappedButtons, rawButtons);
|
| mapCommonStartSelectMetaButtons(mappedButtons, rawButtons);
|
| - mapTriggerAxexToShoulderButtons(mappedButtons, rawAxes);
|
| + mapTriggerAxesToBottomShoulder(mappedButtons, rawAxes);
|
|
|
| mapXYAxes(mappedAxes, rawAxes);
|
| mapZAndRZAxesToRightStick(mappedAxes, rawAxes);
|
| @@ -226,7 +258,7 @@ class GamepadMappings {
|
| private static void mapSamsungEIGP20Gamepad(float[] mappedButtons, float[] rawButtons,
|
| float[] mappedAxes, float[] rawAxes) {
|
| mapCommonXYABButtons(mappedButtons, rawButtons);
|
| - mapCommonTriggerButtons(mappedButtons, rawButtons);
|
| + mapUpperTriggerButtonsToBottomShoulder(mappedButtons, rawButtons);
|
| mapCommonThumbstickButtons(mappedButtons, rawButtons);
|
| mapCommonStartSelectMetaButtons(mappedButtons, rawButtons);
|
| mapHatAxisToDpadButtons(mappedButtons, rawAxes);
|
| @@ -241,14 +273,40 @@ class GamepadMappings {
|
| */
|
| private static void mapUnknownGamepad(float[] mappedButtons, float[] rawButtons,
|
| float[] mappedAxes, float[] rawAxes) {
|
| + // These are correct on all standard Android gamepads
|
| mapCommonXYABButtons(mappedButtons, rawButtons);
|
| - mapCommonTriggerButtons(mappedButtons, rawButtons);
|
| + mapTriggerButtonsToTopShoulder(mappedButtons, rawButtons);
|
| mapCommonThumbstickButtons(mappedButtons, rawButtons);
|
| mapCommonStartSelectMetaButtons(mappedButtons, rawButtons);
|
| - mapTriggerAxexToShoulderButtons(mappedButtons, rawAxes);
|
| - mapCommonDpadButtons(mappedButtons, rawButtons);
|
| -
|
| mapXYAxes(mappedAxes, rawAxes);
|
| - mapRXAndRYAxesToRightStick(mappedAxes, rawAxes);
|
| +
|
| + // Some gamepads (like Shield) use AXIS_LTRIGGER and AXIS_RTRIGGER
|
| + mapTriggerAxesToBottomShoulder(mappedButtons, rawAxes);
|
| + if (!triggersPopulated(mappedButtons)) {
|
| + // Moga gamepads use AXIS_BRAKE and AXIS_GAS
|
| + mapPedalAxesToBottomShoulder(mappedButtons, rawAxes);
|
| + if (!triggersPopulated(mappedButtons)) {
|
| + // Xiaomi gamepads use AXIS_BRAKE and AXIS_THROTTLE
|
| + mapAltPedalAxesToBottomShoulder(mappedButtons, rawAxes);
|
| + if (!triggersPopulated(mappedButtons)) {
|
| + // Devices without analog triggers use digital buttons
|
| + mapLowerTriggerButtonsToBottomShoulder(mappedButtons, rawButtons);
|
| + }
|
| + }
|
| + }
|
| +
|
| + // Some gamepads expose a hat axis for the dpad
|
| + mapHatAxisToDpadButtons(mappedButtons, rawAxes);
|
| + if (!dpadPopulated(mappedButtons)) {
|
| + // Others only generate KEYCODE_DPAD events
|
| + mapCommonDpadButtons(mappedButtons, rawButtons);
|
| + }
|
| +
|
| + // Most gamepads use Z and RZ for right stick
|
| + mapZAndRZAxesToRightStick(mappedAxes, rawAxes);
|
| + if (!rightStickPopulated(mappedAxes)) {
|
| + // Others use RX and RY
|
| + mapRXAndRYAxesToRightStick(mappedAxes, rawAxes);
|
| + }
|
| }
|
| }
|
|
|