diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2013-12-04 20:21:09 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2013-12-09 09:49:15 +1000 |
commit | a2f842bb8a7b40f6858b977f5beb950dd6d6208d (patch) | |
tree | bd11917d57b213b60e4cab29a481fb5067fb0c62 | |
parent | 0aae85122db5a65a05490322c5b8e5021a044fae (diff) | |
download | libevdev-a2f842bb8a7b40f6858b977f5beb950dd6d6208d.tar.gz |
Support EV_REP values through libevdev_get_event_value
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@who-t.net>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
-rw-r--r-- | libevdev/libevdev.c | 13 | ||||
-rw-r--r-- | libevdev/libevdev.h | 8 | ||||
-rw-r--r-- | 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"); |