shithub: choc

Download patch

ref: ea90460a261fb602af273041f3b226f2b723ebd2
parent: 3bc4cfcf875fe4648e2d29e4b949a58a9a707fe7
author: Simon Howard <fraggle@gmail.com>
date: Tue Apr 29 21:00:28 EDT 2014

joystick: Mask out bits for button axis buttons.

When a "button" is actually used as part of a button axis, don't
include presses on the button as part of the buttons field posted
in joystick events. This avoids situations where button 1 or 2
are part of a D-pad, breaking menu navigation (related to #389).

--- a/src/i_joystick.c
+++ b/src/i_joystick.c
@@ -159,6 +159,29 @@
     I_AtExit(I_ShutdownJoystick, true);
 }
 
+static int ButtonAxisMask(void)
+{
+    int result = 0;
+
+    if (IS_BUTTON_AXIS(joystick_x_axis))
+    {
+        result |= 1 << BUTTON_AXIS_NEG(joystick_x_axis);
+        result |= 1 << BUTTON_AXIS_POS(joystick_x_axis);
+    }
+    if (IS_BUTTON_AXIS(joystick_y_axis))
+    {
+        result |= 1 << BUTTON_AXIS_NEG(joystick_y_axis);
+        result |= 1 << BUTTON_AXIS_POS(joystick_y_axis);
+    }
+    if (IS_BUTTON_AXIS(joystick_strafe_axis))
+    {
+        result |= 1 << BUTTON_AXIS_NEG(joystick_strafe_axis);
+        result |= 1 << BUTTON_AXIS_POS(joystick_strafe_axis);
+    }
+
+    return result;
+}
+
 // Get a bitmask of all currently-pressed buttons
 
 static int GetButtonState(void)
@@ -175,6 +198,9 @@
             result |= 1 << i;
         }
     }
+
+    // Mask out any buttons that are actually used in axes.
+    result &= ~ButtonAxisMask();
 
     return result;
 }