summaryrefslogtreecommitdiff
path: root/src/evdev.h
diff options
context:
space:
mode:
authorMatt Helsley <matt.helsley@gmail.com>2009-01-11 18:36:59 -0800
committerPeter Hutterer <peter.hutterer@who-t.net>2009-01-12 13:17:40 +1000
commit4dfd86b2201b2b19761a1abb3c580cecf0060224 (patch)
tree17caf2b7a3a716aa58dcda6a66157507aa6c5345 /src/evdev.h
parentd3fd42d8644310abcae23bbf534f8c445296bcb7 (diff)
Fix FOO_MAX off-by-one
In linux/input.h each section's (e.g. ABS) FOO_MAX is the maximum FOO value. Recent kernels define FOO_CNT as the maximum number of FOO there will ever be. Hence using FOO_MAX to size the bit vectors representing the capabilities of an evdev device is off by one. Define FOO_CNT values for use with Linux kernels which lack them. Use FOO_CNT whenever we need to know the number of bits needed -- usually to calculate the number of longs needed. When iterating over the values FOO_MAX still seems appropriate however the loop test should include FOO_MAX rather than skip it. Signed-off-by: Matt Helsley <matt.helsley@gmail.com> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src/evdev.h')
-rw-r--r--src/evdev.h28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/evdev.h b/src/evdev.h
index 2f58ae8..2698b30 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -40,6 +40,22 @@
#include <xkbstr.h>
#endif
+#ifndef EV_CNT /* linux 2.4 kernels and earlier lack _CNT defines */
+#define EV_CNT (EV_MAX+1)
+#endif
+#ifndef KEY_CNT
+#define KEY_CNT (KEY_MAX+1)
+#endif
+#ifndef REL_CNT
+#define REL_CNT (REL_MAX+1)
+#endif
+#ifndef ABS_CNT
+#define ABS_CNT (ABS_MAX+1)
+#endif
+#ifndef LED_CNT
+#define LED_CNT (LED_MAX+1)
+#endif
+
#define EVDEV_MAXBUTTONS 32
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
@@ -123,12 +139,12 @@ typedef struct {
/* Cached info from device. */
char name[1024];
- long bitmask[NLONGS(EV_MAX)];
- long key_bitmask[NLONGS(KEY_MAX)];
- long rel_bitmask[NLONGS(REL_MAX)];
- long abs_bitmask[NLONGS(ABS_MAX)];
- long led_bitmask[NLONGS(LED_MAX)];
- struct input_absinfo absinfo[ABS_MAX];
+ long bitmask[NLONGS(EV_CNT)];
+ long key_bitmask[NLONGS(KEY_CNT)];
+ long rel_bitmask[NLONGS(REL_CNT)];
+ long abs_bitmask[NLONGS(ABS_CNT)];
+ long led_bitmask[NLONGS(LED_CNT)];
+ struct input_absinfo absinfo[ABS_CNT];
/* minor/major number */
dev_t min_maj;