[PATCH libevdev 4/4] Support EV_REP values through libevdev_get_event_value

Peter Hutterer peter.hutterer at who-t.net
Wed Dec 4 13:56:12 PST 2013


We shouldn't have a separate API for that, the whole point of libevdev is to
abstract the quirkyness of the ioctls into a common interface. So let's
export the two EV_REP values through libevdev_get_event_value.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 libevdev/libevdev.c         | 13 +++++++++++++
 libevdev/libevdev.h         |  8 ++++++--
 test/test-libevdev-events.c | 26 ++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c
index d543dad..60bbbfc 100644
--- a/libevdev/libevdev.c
+++ b/libevdev/libevdev.c
@@ -967,6 +967,19 @@ libevdev_get_event_value(const struct libevdev *dev, unsigned int type, unsigned
 		case EV_KEY: value = bit_is_set(dev->key_values, code); break;
 		case EV_LED: value = bit_is_set(dev->led_values, code); break;
 		case EV_SW: value = bit_is_set(dev->sw_values, code); break;
+		case EV_REP:
+			    switch(code) {
+				    case REP_DELAY:
+					    libevdev_get_repeat(dev, &value, NULL);
+					    break;
+				    case REP_PERIOD:
+					    libevdev_get_repeat(dev, NULL, &value);
+					    break;
+				    default:
+					    value = 0;
+					    break;
+			    }
+			    break;
 		default:
 			value = 0;
 			break;
diff --git a/libevdev/libevdev.h b/libevdev/libevdev.h
index afcf366..1dd3a4b 100644
--- a/libevdev/libevdev.h
+++ b/libevdev/libevdev.h
@@ -259,7 +259,7 @@ extern "C" {
  * <dd>supported, see libevdev_get_id_product(), libevdev_get_id_vendor(),
  * libevdev_get_id_bustype(), * * libevdev_get_id_version()</dd>
  * <dt>EVIOCGREP:</dt>
- * <dd>supported, see libevdev_get_repeat()</dd>
+ * <dd>supported, see libevdev_get_event_value())</dd>
  * <dt>EVIOCSREP:</dt>
  * <dd>supported, see libevdev_enable_event_code()</dd>
  * <dt>EVIOCGKEYCODE:</dt>
@@ -1604,7 +1604,9 @@ int libevdev_event_code_from_name_n(unsigned int type, const char *name,
 /**
  * @ingroup bits
  *
- * Get the repeat delay and repeat period values for this device.
+ * Get the repeat delay and repeat period values for this device. This
+ * function is a convenience function only, EV_REP is supported by
+ * libevdev_get_event_value().
  *
  * @param dev The evdev device, already initialized with libevdev_set_fd()
  * @param delay If not null, set to the repeat delay value
@@ -1613,6 +1615,8 @@ int libevdev_event_code_from_name_n(unsigned int type, const char *name,
  * @return 0 on success, -1 if this device does not have repeat settings.
  *
  * @note This function is signal-safe
+ *
+ * @see libevdev_get_event_value
  */
 int libevdev_get_repeat(const struct libevdev *dev, int *delay, int *period);
 
diff --git a/test/test-libevdev-events.c b/test/test-libevdev-events.c
index 7903043..5197cfc 100644
--- a/test/test-libevdev-events.c
+++ b/test/test-libevdev-events.c
@@ -929,6 +929,31 @@ START_TEST(test_mt_event_values_invalid)
 }
 END_TEST
 
+START_TEST(test_ev_rep_values)
+{
+	struct uinput_device* uidev;
+	struct libevdev *dev;
+	int rc;
+	int delay = 500, period = 200;
+	rc = test_create_device(&uidev, &dev,
+				EV_KEY, BTN_LEFT,
+				EV_REL, REL_X,
+				EV_REL, REL_Y,
+				EV_SYN, SYN_REPORT,
+				-1);
+	ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
+
+	libevdev_enable_event_code(dev, EV_REP, REP_DELAY, &delay);
+	libevdev_enable_event_code(dev, EV_REP, REP_PERIOD, &period);
+
+	ck_assert_int_eq(libevdev_has_event_type(dev, EV_REP), 1);
+	ck_assert_int_eq(libevdev_has_event_code(dev, EV_REP, REP_DELAY), 1);
+	ck_assert_int_eq(libevdev_has_event_code(dev, EV_REP, REP_PERIOD), 1);
+	ck_assert_int_eq(libevdev_get_event_value(dev, EV_REP, REP_DELAY), 500);
+	ck_assert_int_eq(libevdev_get_event_value(dev, EV_REP, REP_PERIOD), 200);
+}
+END_TEST
+
 START_TEST(test_event_value_setters)
 {
 	struct uinput_device* uidev;
@@ -1203,6 +1228,7 @@ libevdev_events(void)
 	tcase_add_test(tc, test_event_values_invalid);
 	tcase_add_test(tc, test_mt_event_values);
 	tcase_add_test(tc, test_mt_event_values_invalid);
+	tcase_add_test(tc, test_ev_rep_values);
 	suite_add_tcase(s, tc);
 
 	tc = tcase_create("event value setters");
-- 
1.8.3.1



More information about the Input-tools mailing list