foxygit / doom Log in
commit ea90460a261fb602af273041f3b226f2b723ebd2
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Wed Apr 30 01:00:28 2014 -0400
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Wed Apr 30 01:00:28 2014 -0400

    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).
---
 src/i_joystick.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/src/i_joystick.c b/src/i_joystick.c
index 8822f288..de10fa08 100644
--- a/src/i_joystick.c
+++ b/src/i_joystick.c
@@ -159,6 +159,29 @@ void I_InitJoystick(void)
     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)
@@ -176,6 +199,9 @@ static int GetButtonState(void)
         }
     }

+    // Mask out any buttons that are actually used in axes.
+    result &= ~ButtonAxisMask();
+
     return result;
 }