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>
This commit is contained in:
Jonas Ådahl 2014-04-22 23:02:14 +02:00
parent 6ef6968631
commit 086c591675
2 changed files with 33 additions and 9 deletions

View file

@ -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);

View file

@ -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;