mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2025-12-27 11:30:07 +01:00
Add setter for property bits
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
parent
13bf9615d9
commit
7ee722ac6f
3 changed files with 58 additions and 0 deletions
|
|
@ -691,6 +691,16 @@ libevdev_has_property(const struct libevdev *dev, unsigned int prop)
|
|||
return (prop <= INPUT_PROP_MAX) && bit_is_set(dev->props, 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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -609,6 +609,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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -767,6 +801,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");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue