[gnome-games/wip/aplazas/gamepad-event: 4/7] gamepad: Map the input types to Linux event codes



commit 7fc0d0846e2e1c3b2ca69ad2e897824f56742a89
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sat May 13 09:23:50 2017 +0200

    gamepad: Map the input types to Linux event codes
    
    This will help transitionning from the custom input types to Linux event
    codes.

 src/gamepad/gamepad-input-type.h      |   10 ++++----
 src/gamepad/standard-gamepad-axis.h   |   14 +++++-----
 src/gamepad/standard-gamepad-button.h |   40 ++++++++++++++++----------------
 src/retro/retro-gamepad.vala          |    4 +-
 4 files changed, 34 insertions(+), 34 deletions(-)
---
diff --git a/src/gamepad/gamepad-input-type.h b/src/gamepad/gamepad-input-type.h
index d9c802f..a3e7229 100644
--- a/src/gamepad/gamepad-input-type.h
+++ b/src/gamepad/gamepad-input-type.h
@@ -4,6 +4,7 @@
 #define GAMES_GAMEPAD_INPUT_TYPE_H
 
 #include <glib-object.h>
+#include <linux/input-event-codes.h>
 
 G_BEGIN_DECLS
 
@@ -17,11 +18,10 @@ G_BEGIN_DECLS
  *
  * The input types of a standard gamepad.
  **/
-typedef enum {
-  GAMES_GAMEPAD_INPUT_TYPE_INVALID,
-  GAMES_GAMEPAD_INPUT_TYPE_AXIS,
-  GAMES_GAMEPAD_INPUT_TYPE_BUTTON,
-} GamesGamepadInputType;
+typedef guint16 GamesGamepadInputType;
+#define GAMES_GAMEPAD_INPUT_TYPE_INVALID EV_MAX
+#define GAMES_GAMEPAD_INPUT_TYPE_AXIS EV_ABS
+#define GAMES_GAMEPAD_INPUT_TYPE_BUTTON EV_KEY
 
 GType games_gamepad_input_type_get_type (void) G_GNUC_CONST;
 
diff --git a/src/gamepad/standard-gamepad-axis.h b/src/gamepad/standard-gamepad-axis.h
index 457868e..4dcbd7a 100644
--- a/src/gamepad/standard-gamepad-axis.h
+++ b/src/gamepad/standard-gamepad-axis.h
@@ -4,6 +4,7 @@
 #define GAMES_STANDARD_GAMEPAD_AXIS_H
 
 #include <glib-object.h>
+#include <linux/input-event-codes.h>
 
 G_BEGIN_DECLS
 
@@ -22,13 +23,12 @@ G_BEGIN_DECLS
  * For horizontal axes, left is -1 and right is 1; for vertical axes,
  * top is -1 and bottom is 1.
  **/
-typedef enum {
-  GAMES_STANDARD_GAMEPAD_AXIS_UNKNOWN,
-  GAMES_STANDARD_GAMEPAD_AXIS_LEFT_X,
-  GAMES_STANDARD_GAMEPAD_AXIS_LEFT_Y,
-  GAMES_STANDARD_GAMEPAD_AXIS_RIGHT_X,
-  GAMES_STANDARD_GAMEPAD_AXIS_RIGHT_Y,
-} GamesStandardGamepadAxis;
+typedef guint16 GamesStandardGamepadAxis;
+#define GAMES_STANDARD_GAMEPAD_AXIS_UNKNOWN ABS_MAX
+#define GAMES_STANDARD_GAMEPAD_AXIS_LEFT_X ABS_X
+#define GAMES_STANDARD_GAMEPAD_AXIS_LEFT_Y ABS_Y
+#define GAMES_STANDARD_GAMEPAD_AXIS_RIGHT_X ABS_RX
+#define GAMES_STANDARD_GAMEPAD_AXIS_RIGHT_Y ABS_RY
 
 GType games_standard_gamepad_axis_get_type (void) G_GNUC_CONST;
 
diff --git a/src/gamepad/standard-gamepad-button.h b/src/gamepad/standard-gamepad-button.h
index cd5e7bd..852b9ed 100644
--- a/src/gamepad/standard-gamepad-button.h
+++ b/src/gamepad/standard-gamepad-button.h
@@ -4,6 +4,7 @@
 #define GAMES_STANDARD_GAMEPAD_BUTTON_H
 
 #include <glib-object.h>
+#include <linux/input-event-codes.h>
 
 G_BEGIN_DECLS
 
@@ -32,26 +33,25 @@ G_BEGIN_DECLS
  *
  * The buttons of a standard gamepad.
  **/
-typedef enum {
-  GAMES_STANDARD_GAMEPAD_BUTTON_UNKNOWN,
-  GAMES_STANDARD_GAMEPAD_BUTTON_A,
-  GAMES_STANDARD_GAMEPAD_BUTTON_B,
-  GAMES_STANDARD_GAMEPAD_BUTTON_X,
-  GAMES_STANDARD_GAMEPAD_BUTTON_Y,
-  GAMES_STANDARD_GAMEPAD_BUTTON_SHOULDER_L,
-  GAMES_STANDARD_GAMEPAD_BUTTON_SHOULDER_R,
-  GAMES_STANDARD_GAMEPAD_BUTTON_TRIGGER_L,
-  GAMES_STANDARD_GAMEPAD_BUTTON_TRIGGER_R,
-  GAMES_STANDARD_GAMEPAD_BUTTON_SELECT,
-  GAMES_STANDARD_GAMEPAD_BUTTON_START,
-  GAMES_STANDARD_GAMEPAD_BUTTON_STICK_L,
-  GAMES_STANDARD_GAMEPAD_BUTTON_STICK_R,
-  GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_UP,
-  GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_DOWN,
-  GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_LEFT,
-  GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_RIGHT,
-  GAMES_STANDARD_GAMEPAD_BUTTON_HOME,
-} GamesStandardGamepadButton;
+typedef guint16 GamesStandardGamepadButton;
+#define GAMES_STANDARD_GAMEPAD_BUTTON_UNKNOWN KEY_MAX
+#define GAMES_STANDARD_GAMEPAD_BUTTON_A BTN_A
+#define GAMES_STANDARD_GAMEPAD_BUTTON_B BTN_B
+#define GAMES_STANDARD_GAMEPAD_BUTTON_X BTN_Y
+#define GAMES_STANDARD_GAMEPAD_BUTTON_Y BTN_X
+#define GAMES_STANDARD_GAMEPAD_BUTTON_SHOULDER_L BTN_TL
+#define GAMES_STANDARD_GAMEPAD_BUTTON_SHOULDER_R BTN_TR
+#define GAMES_STANDARD_GAMEPAD_BUTTON_TRIGGER_L BTN_TL2
+#define GAMES_STANDARD_GAMEPAD_BUTTON_TRIGGER_R BTN_TR2
+#define GAMES_STANDARD_GAMEPAD_BUTTON_SELECT BTN_SELECT
+#define GAMES_STANDARD_GAMEPAD_BUTTON_START BTN_START
+#define GAMES_STANDARD_GAMEPAD_BUTTON_STICK_L BTN_THUMBL
+#define GAMES_STANDARD_GAMEPAD_BUTTON_STICK_R BTN_THUMBR
+#define GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_UP BTN_DPAD_UP
+#define GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_DOWN BTN_DPAD_DOWN
+#define GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_LEFT BTN_DPAD_LEFT
+#define GAMES_STANDARD_GAMEPAD_BUTTON_DPAD_RIGHT BTN_DPAD_RIGHT
+#define GAMES_STANDARD_GAMEPAD_BUTTON_HOME BTN_MODE
 
 GType games_standard_gamepad_button_get_type (void) G_GNUC_CONST;
 
diff --git a/src/retro/retro-gamepad.vala b/src/retro/retro-gamepad.vala
index aba7f44..97f87d3 100644
--- a/src/retro/retro-gamepad.vala
+++ b/src/retro/retro-gamepad.vala
@@ -12,8 +12,8 @@ private class Games.RetroGamepad: Object, Retro.InputDevice {
        }
 
        construct {
-               buttons = new bool[StandardGamepadButton.HOME + 1];
-               axes = new int16[4];
+               buttons = new bool[EventCode.KEY_MAX + 1];
+               axes = new int16[EventCode.ABS_MAX + 1];
 
                gamepad.button_event.connect ((button, value) => buttons[button] = value);
                gamepad.axis_event.connect ((axis, value) => axes[axis] = (int16) (value * int16.MAX));


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