Commit 8af72d70 authored by Adrien Plazas's avatar Adrien Plazas
Browse files

gamepad: Map the input types to Linux event codes

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

https://bugzilla.gnome.org/show_bug.cgi?id=782611
parent 7f7c0dfa
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment