int
uinput_device_create(struct uinput_device* d)
{
- int type, code;
+ int type, code, prop;
struct uinput_user_dev dev;
int rc;
int fd;
}
+ for (prop = 0; prop < INPUT_PROP_MAX; prop++) {
+ if (!bit_is_set(d->d.props, prop))
+ continue;
+
+ rc = ioctl(fd, UI_SET_PROPBIT, prop);
+ if (rc == -1)
+ goto error;
+ }
+
rc = write(fd, &dev, sizeof(dev));
if (rc < 0)
goto error;
}
int
+uinput_device_set_prop(struct uinput_device *dev, unsigned int prop)
+{
+ if (!dev)
+ return -EINVAL;
+
+ if (prop > INPUT_PROP_MAX)
+ return -EINVAL;
+
+ set_bit(dev->d.props, prop);
+ return 0;
+}
+
+int
uinput_device_set_event_bit(struct uinput_device* dev, unsigned int type, unsigned int code)
{
int max;
int uinput_device_set_name(struct uinput_device* dev, const char *name);
int uinput_device_set_ids(struct uinput_device* dev, const struct input_id *ids);
int uinput_device_set_bit(struct uinput_device* dev, unsigned int bit);
+int uinput_device_set_prop(struct uinput_device *dev, unsigned int prop);
int uinput_device_set_event_bit(struct uinput_device* dev, unsigned int type, unsigned int code);
int uinput_device_set_event_bits(struct uinput_device* dev, ...);
int uinput_device_set_event_bits_v(struct uinput_device* dev, va_list args);
{
struct uinput_device* uidev;
struct libevdev *dev;
- int rc;
+ int rc, i;
- rc = test_create_device(&uidev, &dev,
- EV_ABS, ABS_X,
- -1);
+ uidev = uinput_device_new(TEST_DEVICE_NAME);
+ rc = uinput_device_set_event_bits(uidev,
+ EV_ABS, ABS_X,
+ -1);
+ ck_assert_int_eq(rc, 0);
+ uinput_device_set_prop(uidev, INPUT_PROP_DIRECT);
+ uinput_device_set_prop(uidev, INPUT_PROP_BUTTONPAD);
+ rc = uinput_device_create(uidev);
+ ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
+
+ rc = libevdev_new_from_fd(uinput_device_get_fd(uidev), &dev);
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
+
+ for (i = 0; i < INPUT_PROP_MAX; i++) {
+ if (i == INPUT_PROP_DIRECT || i == INPUT_PROP_BUTTONPAD)
+ ck_assert_int_eq(libevdev_has_property(dev, i), 1);
+ else
+ ck_assert_int_eq(libevdev_has_property(dev, i), 0);
+ }
+
ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_MAX + 1), 0);
ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_MAX), 0);
- ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_BUTTONPAD), 0);
- /* FIXME: no idea how to set props on uinput devices */
uinput_device_free(uidev);
libevdev_free(dev);