static enum touchpad_model
get_touchpad_model(struct evdev_device *device)
{
- struct input_id id;
+ int vendor, product;
unsigned int i;
- if (ioctl(device->fd, EVIOCGID, &id) < 0)
- return TOUCHPAD_MODEL_UNKNOWN;
+ vendor = libevdev_get_id_vendor(device->evdev);
+ product = libevdev_get_id_product(device->evdev);
for (i = 0; i < ARRAY_LENGTH(touchpad_spec_table); i++)
- if (touchpad_spec_table[i].vendor == id.vendor &&
+ if (touchpad_spec_table[i].vendor == vendor &&
(!touchpad_spec_table[i].product ||
- touchpad_spec_table[i].product == id.product))
+ touchpad_spec_table[i].product == product))
return touchpad_spec_table[i].model;
return TOUCHPAD_MODEL_UNKNOWN;
{
struct motion_filter *accel;
- unsigned long prop_bits[INPUT_PROP_MAX];
- struct input_absinfo absinfo;
- unsigned long abs_bits[NBITS(ABS_MAX)];
+ const struct input_absinfo *absinfo;
bool has_buttonpad;
/* Detect model */
touchpad->model = get_touchpad_model(device);
- ioctl(device->fd, EVIOCGPROP(sizeof(prop_bits)), prop_bits);
- has_buttonpad = TEST_BIT(prop_bits, INPUT_PROP_BUTTONPAD);
+ has_buttonpad = libevdev_has_property(device->evdev, INPUT_PROP_BUTTONPAD);
/* Configure pressure */
- ioctl(device->fd, EVIOCGBIT(EV_ABS, sizeof(abs_bits)), abs_bits);
- if (TEST_BIT(abs_bits, ABS_PRESSURE)) {
- ioctl(device->fd, EVIOCGABS(ABS_PRESSURE), &absinfo);
+ if ((absinfo = libevdev_get_abs_info(device->evdev, ABS_PRESSURE))) {
configure_touchpad_pressure(touchpad,
- absinfo.minimum,
- absinfo.maximum);
+ absinfo->minimum,
+ absinfo->maximum);
}
/* Configure acceleration factor */
static int
evdev_configure_device(struct evdev_device *device)
{
- struct input_absinfo absinfo;
- unsigned long ev_bits[NBITS(EV_MAX)];
- unsigned long abs_bits[NBITS(ABS_MAX)];
- unsigned long rel_bits[NBITS(REL_MAX)];
- unsigned long key_bits[NBITS(KEY_MAX)];
+ const struct input_absinfo *absinfo;
int has_abs, has_rel, has_mt;
int has_button, has_keyboard, has_touch;
unsigned int i;
has_keyboard = 0;
has_touch = 0;
- ioctl(device->fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits);
- if (TEST_BIT(ev_bits, EV_ABS)) {
- ioctl(device->fd, EVIOCGBIT(EV_ABS, sizeof(abs_bits)),
- abs_bits);
+ if (libevdev_has_event_type(device->evdev, EV_ABS)) {
- if (TEST_BIT(abs_bits, ABS_X)) {
- ioctl(device->fd, EVIOCGABS(ABS_X), &absinfo);
- device->abs.min_x = absinfo.minimum;
- device->abs.max_x = absinfo.maximum;
+ if ((absinfo = libevdev_get_abs_info(device->evdev, ABS_X))) {
+ device->abs.min_x = absinfo->minimum;
+ device->abs.max_x = absinfo->maximum;
has_abs = 1;
}
- if (TEST_BIT(abs_bits, ABS_Y)) {
- ioctl(device->fd, EVIOCGABS(ABS_Y), &absinfo);
- device->abs.min_y = absinfo.minimum;
- device->abs.max_y = absinfo.maximum;
+ if ((absinfo = libevdev_get_abs_info(device->evdev, ABS_Y))) {
+ device->abs.min_y = absinfo->minimum;
+ device->abs.max_y = absinfo->maximum;
has_abs = 1;
}
/* We only handle the slotted Protocol B in weston.
Devices with ABS_MT_POSITION_* but not ABS_MT_SLOT
require mtdev for conversion. */
- if (TEST_BIT(abs_bits, ABS_MT_POSITION_X) &&
- TEST_BIT(abs_bits, ABS_MT_POSITION_Y)) {
- ioctl(device->fd, EVIOCGABS(ABS_MT_POSITION_X),
- &absinfo);
- device->abs.min_x = absinfo.minimum;
- device->abs.max_x = absinfo.maximum;
- ioctl(device->fd, EVIOCGABS(ABS_MT_POSITION_Y),
- &absinfo);
- device->abs.min_y = absinfo.minimum;
- device->abs.max_y = absinfo.maximum;
+ if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_POSITION_X) &&
+ libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_POSITION_Y)) {
+ absinfo = libevdev_get_abs_info(device->evdev, ABS_MT_POSITION_X);
+ device->abs.min_x = absinfo->minimum;
+ device->abs.max_x = absinfo->maximum;
+ absinfo = libevdev_get_abs_info(device->evdev, ABS_MT_POSITION_Y);
+ device->abs.min_y = absinfo->minimum;
+ device->abs.max_y = absinfo->maximum;
device->is_mt = 1;
has_touch = 1;
has_mt = 1;
- if (!TEST_BIT(abs_bits, ABS_MT_SLOT)) {
+ if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_SLOT)) {
device->mtdev = mtdev_new_open(device->fd);
if (!device->mtdev)
return -1;
device->mt.slot = device->mtdev->caps.slot.value;
} else {
- ioctl(device->fd, EVIOCGABS(ABS_MT_SLOT),
- &absinfo);
- device->mt.slot = absinfo.value;
+ device->mt.slot = libevdev_get_current_slot(device->evdev);
}
}
}
- if (TEST_BIT(ev_bits, EV_REL)) {
- ioctl(device->fd, EVIOCGBIT(EV_REL, sizeof(rel_bits)),
- rel_bits);
- if (TEST_BIT(rel_bits, REL_X) || TEST_BIT(rel_bits, REL_Y))
+ if (libevdev_has_event_code(device->evdev, EV_REL, REL_X) ||
+ libevdev_has_event_code(device->evdev, EV_REL, REL_Y))
has_rel = 1;
- }
- if (TEST_BIT(ev_bits, EV_KEY)) {
- ioctl(device->fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)),
- key_bits);
- if (TEST_BIT(key_bits, BTN_TOOL_FINGER) &&
- !TEST_BIT(key_bits, BTN_TOOL_PEN) &&
+
+ if (libevdev_has_event_type(device->evdev, EV_KEY)) {
+ if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_TOOL_FINGER) &&
+ !libevdev_has_event_code(device->evdev, EV_KEY, BTN_TOOL_PEN) &&
(has_abs || has_mt)) {
device->dispatch = evdev_touchpad_create(device);
}
for (i = KEY_ESC; i < KEY_MAX; i++) {
if (i >= BTN_MISC && i < KEY_OK)
continue;
- if (TEST_BIT(key_bits, i)) {
+ if (libevdev_has_event_code(device->evdev, EV_KEY, i)) {
has_keyboard = 1;
break;
}
}
- if (TEST_BIT(key_bits, BTN_TOUCH))
+ if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_TOUCH))
has_touch = 1;
for (i = BTN_MISC; i < BTN_JOYSTICK; i++) {
- if (TEST_BIT(key_bits, i)) {
+ if (libevdev_has_event_code(device->evdev, EV_KEY, i)) {
has_button = 1;
break;
}
}
}
- if (TEST_BIT(ev_bits, EV_LED))
+ if (libevdev_has_event_type(device->evdev, EV_LED))
has_keyboard = 1;
if ((has_abs || has_rel) && has_button)
{
struct libinput *libinput = seat->libinput;
struct evdev_device *device;
- char devname[256] = "unknown";
+ int rc;
int fd;
int unhandled_device = 0;
libinput_device_init(&device->base, seat);
+ rc = libevdev_new_from_fd(fd, &device->evdev);
+ if (rc != 0)
+ return NULL;
+
device->seat_caps = 0;
device->is_mt = 0;
device->mtdev = NULL;
device->dispatch = NULL;
device->fd = fd;
device->pending_event = EVDEV_NONE;
-
- ioctl(device->fd, EVIOCGNAME(sizeof(devname)), devname);
- devname[sizeof(devname) - 1] = '\0';
- device->devname = strdup(devname);
+ device->devname = libevdev_get_name(device->evdev);
libinput_seat_ref(seat);
dispatch->interface->destroy(dispatch);
libinput_seat_unref(device->base.seat);
-
- free(device->devname);
+ libevdev_free(device->evdev);
free(device->devnode);
free(device->sysname);
free(device);