aboutsummaryrefslogtreecommitdiffstats
path: root/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'common.h')
-rw-r--r--common.h21
1 files changed, 19 insertions, 2 deletions
diff --git a/common.h b/common.h
index 9889858..0458063 100644
--- a/common.h
+++ b/common.h
@@ -8,6 +8,7 @@
#include <fcntl.h>
#include <limits.h>
#include <math.h>
+#include <poll.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
@@ -17,7 +18,6 @@
#include <time.h>
#include <unistd.h>
-#include <libevdev/libevdev.h>
#include <libsha2.h>
#include <libudev.h>
@@ -34,8 +34,19 @@
#define ELEMSOF(A) (sizeof(A) / sizeof(*(A)))
#define BITSOF(T) (8 * sizeof(T))
+#define XORBIT(ARR, I) (READ_(ARR, I) ^= 1 << SHIFT_(ARR, I))
#define SETBIT(ARR, I) (READ_(ARR, I) |= 1 << SHIFT_(ARR, I))
#define GETBIT(ARR, I) ((READ_(ARR, I) >> SHIFT_(ARR, I)) & 1)
+#define ELEMS_REQUIRED(BITS, TYPE) ((BITS + BITSOF(TYPE) - 1) / BITSOF(TYPE))
+
+#define DEFER_EINTR_(DEVICE, ERROR_CONDITION, GOTO_ON_FAILURE)\
+ do {\
+ while (ERROR_CONDITION) {\
+ if (errno != EINTR)\
+ goto GOTO_ON_FAILURE;\
+ (DEVICE)->internals->deferred_error = EINTR;\
+ }\
+ } while (0)
struct libgamepad_attachment_monitor {
@@ -45,11 +56,14 @@ struct libgamepad_attachment_monitor {
struct libgamepad_device_internals {
+ int deferred_error;
int close_fd;
int require_sync;
- struct libevdev *dev;
struct input_absinfo *absinfo;
uint8_t *buttons;
+ struct input_event *evbuf;
+ size_t evbuf_size;
+ size_t ev_queued;
};
@@ -64,3 +78,6 @@ extern const char *libgamepad_absolute_axis_names__[
extern const char *libgamepad_relative_axis_names__[
#include "relative-axis.count"
];
+
+
+int libgamepad_drain__(struct libgamepad_device *device);