[gnome-games] gamepad: Make LinuxRawGamepad send standard axis events



commit f548297d4f81d35605122b5ff39c232e6b597705
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sat Aug 27 09:00:19 2016 +0200

    gamepad: Make LinuxRawGamepad send standard axis events
    
    This allow gamepads with not mapping but sending proper gamepad events
    to work as intended.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=770468

 src/gamepad/linux/linux-raw-gamepad.vala |   32 +++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/src/gamepad/linux/linux-raw-gamepad.vala b/src/gamepad/linux/linux-raw-gamepad.vala
index ec078c6..f759b89 100644
--- a/src/gamepad/linux/linux-raw-gamepad.vala
+++ b/src/gamepad/linux/linux-raw-gamepad.vala
@@ -153,15 +153,26 @@ private class Games.LinuxRawGamepad : Object, RawGamepad {
                                code -= Linux.Input.ABS_HAT0X;
                                dpad_event (code / 2, code % 2, event.value);
 
-                               break;
-                       default:
+                               // We don't want to send an axis event as dpad events
+                               // are handled differently by the gamepad objects, hence
+                               // we return here.
+                               return;
+                       case Linux.Input.ABS_X:
+                       case Linux.Input.ABS_Y:
+                       case Linux.Input.ABS_RX:
+                       case Linux.Input.ABS_RY:
+                               var standard_axis = axis_to_standard_axis (code);
                                var axis = abs_map[code];
                                var value = centered_axis_value (abs_info[axis], event.value);
-                               axis_event (axis, value);
+                               standard_axis_event (standard_axis, value);
 
                                break;
                        }
 
+                       var axis = abs_map[code];
+                       var value = centered_axis_value (abs_info[axis], event.value);
+                       axis_event (axis, value);
+
                        break;
                }
        }
@@ -226,6 +237,21 @@ private class Games.LinuxRawGamepad : Object, RawGamepad {
                }
        }
 
+       private StandardGamepadAxis axis_to_standard_axis (int code) {
+               switch (code) {
+               case Linux.Input.ABS_X:
+                       return StandardGamepadAxis.LEFT_X;
+               case Linux.Input.ABS_Y:
+                       return StandardGamepadAxis.LEFT_Y;
+               case Linux.Input.ABS_RX:
+                       return StandardGamepadAxis.RIGHT_X;
+               case Linux.Input.ABS_RY:
+                       return StandardGamepadAxis.RIGHT_Y;
+               default:
+                       return StandardGamepadAxis.UNKNOWN;
+               }
+       }
+
        private static double centered_axis_value (Linux.Input.AbsInfo abs_info, int32 value) {
                var min_absolute = ((int64) abs_info.minimum).abs ();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]