summaryrefslogtreecommitdiff
path: root/src/waypad.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/waypad.h')
-rw-r--r--src/waypad.h132
1 files changed, 132 insertions, 0 deletions
diff --git a/src/waypad.h b/src/waypad.h
new file mode 100644
index 0000000..1137f9b
--- /dev/null
+++ b/src/waypad.h
@@ -0,0 +1,132 @@
+#ifndef _WAYPAD_H_
+#define _WAYPAD_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <libevdev/libevdev.h>
+
+enum gamepad_button {
+ GAMEPAD_BUTTON_INVALID = -1,
+ GAMEPAD_BUTTON_A,
+ GAMEPAD_BUTTON_B,
+ GAMEPAD_BUTTON_X,
+ GAMEPAD_BUTTON_Y,
+ GAMEPAD_BUTTON_BACK,
+ GAMEPAD_BUTTON_GUIDE,
+ GAMEPAD_BUTTON_START,
+ GAMEPAD_BUTTON_LEFTSTICK,
+ GAMEPAD_BUTTON_RIGHTSTICK,
+ GAMEPAD_BUTTON_LEFTSHOULDER,
+ GAMEPAD_BUTTON_RIGHTSHOULDER,
+ GAMEPAD_BUTTON_DPAD_UP,
+ GAMEPAD_BUTTON_DPAD_DOWN,
+ GAMEPAD_BUTTON_DPAD_LEFT,
+ GAMEPAD_BUTTON_DPAD_RIGHT,
+ GAMEPAD_BUTTON_MISC1,
+ GAMEPAD_BUTTON_PADDLE1,
+ GAMEPAD_BUTTON_PADDLE2,
+ GAMEPAD_BUTTON_PADDLE3,
+ GAMEPAD_BUTTON_PADDLE4,
+ GAMEPAD_BUTTON_TOUCHPAD,
+ GAMEPAD_BUTTON_MAX
+};
+
+enum gamepad_axis {
+ GAMEPAD_AXIS_INVALID = -1,
+ GAMEPAD_AXIS_LEFTX,
+ GAMEPAD_AXIS_LEFTY,
+ GAMEPAD_AXIS_RIGHTX,
+ GAMEPAD_AXIS_RIGHTY,
+ GAMEPAD_AXIS_TRIGGERLEFT,
+ GAMEPAD_AXIS_TRIGGERRIGHT,
+ GAMEPAD_AXIS_MAX
+};
+
+enum keyboard_modifier {
+ KEYMOD_LSHIFT = 1 << 0,
+ KEYMOD_RSHIFT = 1 << 1,
+ KEYMOD_LCTRL = 1 << 2,
+ KEYMOD_RCTRL = 1 << 3,
+ KEYMOD_LALT = 1 << 4,
+ KEYMOD_RALT = 1 << 5,
+ KEYMOD_LMETA = 1 << 6,
+ KEYMOD_RMETA = 1 << 7,
+};
+
+struct guid { uint16_t guid[8]; };
+
+struct mapping {
+ char *name;
+ struct guid guid;
+ uint8_t buttons[GAMEPAD_BUTTON_MAX];
+ uint8_t axis[GAMEPAD_AXIS_MAX];
+};
+
+struct action {
+ enum {
+ ACTION_NONE,
+ ACTION_EXEC,
+ ACTION_KEY,
+ ACTION_MOUSE,
+ ACTION_CLICK,
+ ACTION_MODE,
+ } type;
+ int old_value; /* for relative axis binds */
+ union {
+ char **exec;
+ struct {
+ enum keyboard_modifier mod;
+ int code;
+ } key;
+ int click;
+ enum {
+ MOUSE_X,
+ MOUSE_Y
+ } mouse;
+ struct mode *mode;
+ };
+};
+
+struct gamepad {
+ struct mapping *mapping;
+ struct libevdev *dev;
+ /* maps libevdev event ids to indexes in gamepad.actions */
+ struct {
+ uint8_t button[KEY_MAX - BTN_MISC];
+ uint8_t axis[ABS_MAX];
+ } map;
+ size_t nbuttons, naxis;
+ struct {
+ size_t len, cap;
+ struct mode {
+ char *name;
+ struct action *buttons, *axis;
+ } *all, *current, base;
+ } modes;
+};
+
+extern struct gamepads {
+ size_t len, cap;
+ struct gamepad *loaded;
+} gamepads;
+
+bool load_config(const char *path);
+bool load_gamepads();
+void free_gamepads();
+struct gamepad *find_gamepad(const char *name);
+struct mode *get_make_mode(struct gamepad *pad, const char *name);
+enum gamepad_axis str_to_axis(const char *str);
+enum gamepad_button str_to_button(const char *str);
+
+bool wayland_init();
+
+bool uinput_mouse_init();
+void uinput_mouse_press(int button);
+void uinput_mouse_release(int button);
+void uinput_mouse_rel_move(int x, int y);
+
+bool uinput_keyboard_init();
+void uinput_keyboard_press(enum keyboard_modifier mod, int key);
+void uinput_keyboard_release(enum keyboard_modifier mod, int key);
+#endif