summaryrefslogtreecommitdiff
path: root/libevdev/libevdev-int.h
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2013-05-30 12:20:21 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2013-05-30 13:37:44 +1000
commitec093aa39840e79892b409749ac006c9aaa23026 (patch)
tree1834f0b2ec2307b4d1671938aae969c8730811b9 /libevdev/libevdev-int.h
parent549f0f0bcd3ceec21393e953e13a86a716fc9580 (diff)
downloadlibevdev-ec093aa39840e79892b409749ac006c9aaa23026.tar.gz
After a SYN_DROPPED, drop all events in the queue
Ideally, we could sync by pre-pending all the sync events and then pretend nothing happened but our queue is too small and likely too full for any extra events. So drop all events, then add the sync events to the queue. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'libevdev/libevdev-int.h')
-rw-r--r--libevdev/libevdev-int.h61
1 files changed, 51 insertions, 10 deletions
diff --git a/libevdev/libevdev-int.h b/libevdev/libevdev-int.h
index 848c1a5..4e394d0 100644
--- a/libevdev/libevdev-int.h
+++ b/libevdev/libevdev-int.h
@@ -35,6 +35,19 @@
#define ABS_MT_MAX ABS_MT_TOOL_Y
#define ABS_MT_CNT (ABS_MT_MAX - ABS_MT_MIN + 1)
+#undef min
+#undef max
+#define min(a,b) \
+ ({ __typeof__ (a) _a = (a); \
+ __typeof__ (b) _b = (b); \
+ _a > _b ? _b : _a; \
+ })
+#define max(a,b) \
+ ({ __typeof__ (a) _a = (a); \
+ __typeof__ (b) _b = (b); \
+ _a > _b ? _a : _b; \
+ })
+
struct libevdev {
int fd;
libevdev_log_func_t log;
@@ -90,28 +103,56 @@ queue_pop(struct libevdev *dev, struct input_event *ev)
return 0;
}
+static inline int
+queue_peek(struct libevdev *dev, size_t idx, struct input_event *ev)
+{
+ if (idx > dev->queue_next)
+ return 1;
+ *ev = dev->queue[idx];
+ return 0;
+}
+
+
/**
- * Set ev to the first element in the queue, shifting everything else
- * forward by one.
+ * Shift the first n elements into ev and return the number of elements
+ * shifted.
+ * ev must be large enough to store n elements.
*
- * @return 0 on success, 1 if the queue is empty.
+ * @param ev The buffer to copy into, or NULL
+ * @return The number of elements in ev.
*/
static inline int
-queue_shift(struct libevdev *dev, struct input_event *ev)
+queue_shift_multiple(struct libevdev *dev, int n, struct input_event *ev)
{
int i;
if (dev->queue_next == 0)
- return 1;
+ return 0;
- *ev = dev->queue[0];
+ n = min(n, dev->queue_next);
- for (i = 0; i < dev->queue_next - 1; i++)
- dev->queue[i] = dev->queue[i + 1];
+ if (ev) {
+ for (i = 0; i < n; i++)
+ ev[i] = dev->queue[i];
+ }
- dev->queue_next--;
+ for (i = 0; i < dev->queue_next - n; i++)
+ dev->queue[i] = dev->queue[n + i];
- return 0;
+ dev->queue_next -= n;
+ return n;
+}
+
+/**
+ * Set ev to the first element in the queue, shifting everything else
+ * forward by one.
+ *
+ * @return 0 on success, 1 if the queue is empty.
+ */
+static inline int
+queue_shift(struct libevdev *dev, struct input_event *ev)
+{
+ return queue_shift_multiple(dev, 1, ev) == 1 ? 0 : 1;
}
static inline int