[PATCH libevdev 6/6] Add setter for property bits
Peter Hutterer
peter.hutterer at who-t.net
Sun Jul 28 22:34:37 PDT 2013
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
libevdev/libevdev.c | 10 ++++++++++
libevdev/libevdev.h | 13 +++++++++++++
test/test-libevdev-has-event.c | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+)
diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
index c366dcf..9391f15 100644
--- a/libevdev/libevdev.c
+++ b/libevdev/libevdev.c
@@ -721,6 +721,16 @@ libevdev_has_property(const struct libevdev *dev, unsigned int prop)
}
int
+libevdev_enable_property(struct libevdev *dev, unsigned int prop)
+{
+ if (prop > INPUT_PROP_MAX)
+ return -1;
+
+ set_bit(dev->props, prop);
+ return 0;
+}
+
+int
libevdev_has_event_type(const struct libevdev *dev, unsigned int type)
{
return (type <= EV_MAX) && bit_is_set(dev->bits, type);
diff --git a/libevdev/libevdev.h b/libevdev/libevdev.h
index e64cc2b..ee8248f 100644
--- a/libevdev/libevdev.h
+++ b/libevdev/libevdev.h
@@ -687,6 +687,19 @@ int libevdev_get_driver_version(const struct libevdev *dev);
int libevdev_has_property(const struct libevdev *dev, unsigned int prop);
/**
+ * @ingroup kernel
+ *
+ * @param dev The evdev device
+ * @param prop The input property to enable, one of INPUT_PROP_...
+ *
+ * @return 0 on success or -1 on failure
+ *
+ * @note This function may be called before libevdev_set_fd(). A call to
+ * libevdev_set_fd() will overwrite any previously set value.
+ */
+int libevdev_enable_property(struct libevdev *dev, unsigned int prop);
+
+/**
* @ingroup bits
*
* @param dev The evdev device, already initialized with libevdev_set_fd()
diff --git a/test/test-libevdev-has-event.c b/test/test-libevdev-has-event.c
index 35b1fd5..a14f99e 100644
--- a/test/test-libevdev-has-event.c
+++ b/test/test-libevdev-has-event.c
@@ -243,6 +243,40 @@ START_TEST(test_input_props)
}
END_TEST
+START_TEST(test_set_input_props)
+{
+ struct uinput_device* uidev;
+ struct libevdev *dev;
+ int rc, fd;
+
+ dev = libevdev_new();
+ ck_assert_int_eq(libevdev_enable_property(dev, INPUT_PROP_MAX + 1), -1);
+ ck_assert_int_eq(libevdev_enable_property(dev, INPUT_PROP_DIRECT), 0);
+ ck_assert_int_eq(libevdev_enable_property(dev, INPUT_PROP_BUTTONPAD), 0);
+ ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_DIRECT), 1);
+ ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_BUTTONPAD), 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_BUTTONPAD);
+ rc = uinput_device_create(uidev);
+ ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
+
+ fd = uinput_device_get_fd(uidev);
+ rc = libevdev_set_fd(dev, fd);
+ ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
+
+ ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_DIRECT), 0);
+ ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_BUTTONPAD), 1);
+
+ uinput_device_free(uidev);
+ libevdev_free(dev);
+}
+END_TEST
+
START_TEST(test_slot_init_value)
{
struct uinput_device *uidev;
@@ -912,6 +946,7 @@ libevdev_has_event_test(void)
tc = tcase_create("input properties");
tcase_add_test(tc, test_input_props);
+ tcase_add_test(tc, test_set_input_props);
suite_add_tcase(s, tc);
tc = tcase_create("multitouch info");
--
1.8.2.1
More information about the Input-tools
mailing list