summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Ådahl <jadahl@gmail.com>2014-04-22 23:02:14 +0200
committerJonas Ådahl <jadahl@gmail.com>2014-04-22 23:44:24 +0200
commit086c5916758f078c54a12f330a418dd85295247e (patch)
tree0fd77cc90fbc97015cc501da4dc79b3659c44273
parent6ef6968631939bdeca359a3354164907fd1a09e0 (diff)
evdev: Dynamically allocate slot array
Don't have a hard coded slot array size; instead allocate the array needed according to the abs info reported by either libmtdev or libevdev. Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
-rw-r--r--src/evdev.c29
-rw-r--r--src/evdev.h13
2 files changed, 33 insertions, 9 deletions
diff --git a/src/evdev.c b/src/evdev.c
index 34c6798..8d11e7f 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -547,6 +547,10 @@ evdev_configure_device(struct evdev_device *device)
const struct input_absinfo *absinfo;
int has_abs, has_rel, has_mt;
int has_button, has_keyboard, has_touch;
+ struct mt_slot *slots;
+ int num_slots;
+ int active_slot;
+ int slot;
unsigned int i;
has_rel = 0;
@@ -588,10 +592,29 @@ evdev_configure_device(struct evdev_device *device)
device->mtdev = mtdev_new_open(device->fd);
if (!device->mtdev)
return -1;
- device->mt.slot = device->mtdev->caps.slot.value;
+
+ num_slots = device->mtdev->caps.slot.maximum;
+ if (device->mtdev->caps.slot.minimum < 0 ||
+ num_slots <= 0)
+ return -1;
+ active_slot = device->mtdev->caps.slot.value;
} else {
- device->mt.slot = libevdev_get_current_slot(device->evdev);
+ num_slots = libevdev_get_num_slots(device->evdev);
+ active_slot = libevdev_get_current_slot(evdev);
+ }
+
+ slots = calloc(num_slots, sizeof(struct mt_slot));
+ if (!slots)
+ return -1;
+
+ for (slot = 0; slot < num_slots; ++slot) {
+ slots[slot].seat_slot = -1;
+ slots[slot].x = 0;
+ slots[slot].y = 0;
}
+ device->mt.slots = slots;
+ device->mt.slots_len = num_slots;
+ device->mt.slot = active_slot;
}
}
if (libevdev_has_event_code(evdev, EV_REL, REL_X) ||
@@ -686,7 +709,6 @@ evdev_device_create(struct libinput_seat *seat,
device->mtdev = NULL;
device->devnode = strdup(devnode);
device->sysname = strdup(sysname);
- device->mt.slot = -1;
device->rel.dx = 0;
device->rel.dy = 0;
device->dispatch = NULL;
@@ -802,6 +824,7 @@ evdev_device_destroy(struct evdev_device *device)
libinput_seat_unref(device->base.seat);
libevdev_free(device->evdev);
+ free(device->mt.slots);
free(device->devnode);
free(device->sysname);
free(device);
diff --git a/src/evdev.h b/src/evdev.h
index 0ab9572..36daf3c 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -31,8 +31,6 @@
#include "libinput-private.h"
-#define MAX_SLOTS 16
-
enum evdev_event_type {
EVDEV_NONE,
EVDEV_ABSOLUTE_TOUCH_DOWN,
@@ -50,6 +48,11 @@ enum evdev_device_seat_capability {
EVDEV_DEVICE_TOUCH = (1 << 2)
};
+struct mt_slot {
+ int32_t seat_slot;
+ int32_t x, y;
+};
+
struct evdev_device {
struct libinput_device base;
@@ -74,10 +77,8 @@ struct evdev_device {
struct {
int slot;
- struct {
- int32_t seat_slot;
- int32_t x, y;
- } slots[MAX_SLOTS];
+ struct mt_slot *slots;
+ size_t slots_len;
} mt;
struct mtdev *mtdev;