int libevdev_get_event_value(const struct libevdev *dev, unsigned int type, unsigned int code);
/**
+ * @ingroup kernel
+ *
+ * Set the value for a given event type and code. This only makes sense for
+ * some event types, e.g. setting the value for EV_REL is pointless.
+ *
+ * This is a local modification only affecting only this representation of
+ * this device. A future call to libevdev_get_event_value() will return this
+ * value, unless the value was overwritten by an event.
+ *
+ * @param dev The evdev device, already initialized with libevdev_set_fd()
+ * @param type The event type for the code to query (EV_SYN, EV_REL, etc.)
+ * @param code The event code to set the value for, one of ABS_X, LED_NUML, etc.
+ * @param value The new value to set
+ *
+ * @return 0 on success, or -1 on failure.
+ * @retval -1 the device does not have the event type or code enabled, or the code is outside the
+ * allowed limits for the given type, or the type cannot be set.
+ *
+ * @see libevdev_set_slot_value
+ * @see libevdev_get_event_value
+ */
+int libevdev_set_event_value(struct libevdev *dev, unsigned int type, unsigned int code, int value);
+
+/**
* @ingroup bits
*
* Fetch the current value of the event type. This is a shortcut for
int libevdev_get_slot_value(const struct libevdev *dev, unsigned int slot, unsigned int code);
/**
+ * @ingroup kernel
+ *
+ * Set the value for a given code for the given slot.
+ *
+ * This is a local modification only affecting only this representation of
+ * this device. A future call to libevdev_get_slot_value() will return this
+ * value, unless the value was overwritten by an event.
+ *
+ * This function does not set event values for axes outside the ABS_MT range,
+ * use libevdev_set_event_value() instead.
+ *
+ * @param dev The evdev device, already initialized with libevdev_set_fd()
+ * @param slot The numerical slot number, must be smaller than the total number
+ * of slots on this device
+ * @param code The event code to set the value for, one of ABS_MT_POSITION_X, etc.
+ * @param value The new value to set
+ *
+ * @return 0 on success, or -1 on failure.
+ * @retval -1 the device does not have the event code enabled, or the code is
+ * outside the allowed limits for multitouch events, or the slot number is outside
+ * the limits for this device, or the device does not support multitouch events.
+ *
+ * @see libevdev_set_event_value
+ * @see libevdev_get_slot_value
+ */
+int libevdev_set_slot_value(struct libevdev *dev, unsigned int slot, unsigned int code, int value);
+
+/**
* @ingroup mt
*
* Fetch the current value of the code for the given slot. This is a shortcut for
}
END_TEST
+START_TEST(test_event_value_setters)
+{
+ struct uinput_device* uidev;
+ struct libevdev *dev;
+ int rc;
+ struct input_absinfo abs[2];
+
+ memset(abs, 0, sizeof(abs));
+ abs[0].value = ABS_X;
+ abs[0].maximum = 1000;
+
+ abs[1].value = ABS_Y;
+ abs[1].maximum = 1000;
+
+ rc = test_create_abs_device(&uidev, &dev,
+ 2, abs,
+ EV_SYN, SYN_REPORT,
+ EV_REL, REL_X,
+ EV_REL, REL_Y,
+ EV_KEY, BTN_LEFT,
+ EV_KEY, BTN_MIDDLE,
+ EV_KEY, BTN_RIGHT,
+ -1);
+ ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
+
+ ck_assert_int_eq(libevdev_get_event_value(dev, EV_KEY, BTN_LEFT), 0);
+ ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_X), 0);
+ ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_Y), 0);
+ ck_assert_int_eq(libevdev_get_event_value(dev, EV_REL, REL_X), 0);
+ ck_assert_int_eq(libevdev_get_event_value(dev, EV_REL, REL_Y), 0);
+
+ ck_assert_int_eq(libevdev_set_event_value(dev, EV_KEY, BTN_LEFT, 1), 0);
+ ck_assert_int_eq(libevdev_set_event_value(dev, EV_KEY, BTN_RIGHT, 1), 0);
+
+ ck_assert_int_eq(libevdev_get_event_value(dev, EV_KEY, BTN_LEFT), 1);
+ ck_assert_int_eq(libevdev_get_event_value(dev, EV_KEY, BTN_RIGHT), 1);
+
+ ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_X, 10), 0);
+ ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_Y, 20), 0);
+
+ ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_X), 10);
+ ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_Y), 20);
+
+ uinput_device_free(uidev);
+ libevdev_free(dev);
+
+}
+END_TEST
+
+START_TEST(test_event_value_setters_invalid)
+{
+ struct uinput_device* uidev;
+ struct libevdev *dev;
+ int rc;
+ struct input_absinfo abs[2];
+
+ memset(abs, 0, sizeof(abs));
+ abs[0].value = ABS_X;
+ abs[0].maximum = 1000;
+
+ abs[1].value = ABS_Y;
+ abs[1].maximum = 1000;
+
+ rc = test_create_abs_device(&uidev, &dev,
+ 2, abs,
+ EV_SYN, SYN_REPORT,
+ EV_REL, REL_X,
+ EV_REL, REL_Y,
+ EV_KEY, BTN_LEFT,
+ EV_KEY, BTN_MIDDLE,
+ EV_KEY, BTN_RIGHT,
+ -1);
+ ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
+
+ ck_assert_int_eq(libevdev_set_event_value(dev, EV_REL, REL_X, 1), -1);
+ ck_assert_int_eq(libevdev_set_event_value(dev, EV_SW, SW_DOCK, 1), -1);
+ ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_Z, 1), -1);
+ ck_assert_int_eq(libevdev_set_event_value(dev, EV_MAX + 1, 0, 1), -1);
+ ck_assert_int_eq(libevdev_set_event_value(dev, EV_SYN, SYN_REPORT, 0), -1);
+
+ uinput_device_free(uidev);
+ libevdev_free(dev);
+
+}
+END_TEST
+
+START_TEST(test_event_mt_value_setters)
+{
+ struct uinput_device* uidev;
+ struct libevdev *dev;
+ int rc;
+ struct input_absinfo abs[5];
+
+ memset(abs, 0, sizeof(abs));
+ abs[0].value = ABS_X;
+ abs[0].maximum = 1000;
+ abs[1].value = ABS_MT_POSITION_X;
+ abs[1].maximum = 1000;
+
+ abs[2].value = ABS_Y;
+ abs[2].maximum = 1000;
+ abs[3].value = ABS_MT_POSITION_Y;
+ abs[3].maximum = 1000;
+
+ abs[4].value = ABS_MT_SLOT;
+ abs[4].maximum = 2;
+
+ rc = test_create_abs_device(&uidev, &dev,
+ 5, abs,
+ EV_SYN, SYN_REPORT,
+ -1);
+ ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
+
+ ck_assert_int_eq(libevdev_set_slot_value(dev, 1, ABS_MT_POSITION_X, 1), 0);
+ ck_assert_int_eq(libevdev_set_slot_value(dev, 1, ABS_MT_POSITION_Y, 2), 0);
+ ck_assert_int_eq(libevdev_set_slot_value(dev, 0, ABS_MT_POSITION_X, 3), 0);
+ ck_assert_int_eq(libevdev_set_slot_value(dev, 0, ABS_MT_POSITION_Y, 4), 0);
+
+ ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_X), 1);
+ ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_Y), 2);
+ ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_X), 3);
+ ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_Y), 4);
+
+ ck_assert_int_eq(libevdev_set_slot_value(dev, 1, ABS_MT_SLOT, 1), 0);
+ ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_SLOT), 1);
+ ck_assert_int_eq(libevdev_get_current_slot(dev), 1);
+
+ uinput_device_free(uidev);
+ libevdev_free(dev);
+}
+END_TEST
+
+START_TEST(test_event_mt_value_setters_invalid)
+{
+ struct uinput_device* uidev;
+ struct libevdev *dev;
+ int rc;
+ struct input_absinfo abs[5];
+
+ memset(abs, 0, sizeof(abs));
+ abs[0].value = ABS_X;
+ abs[0].maximum = 1000;
+ abs[1].value = ABS_MT_POSITION_X;
+ abs[1].maximum = 1000;
+
+ abs[2].value = ABS_Y;
+ abs[2].maximum = 1000;
+ abs[3].value = ABS_MT_POSITION_Y;
+ abs[3].maximum = 1000;
+
+ abs[4].value = ABS_MT_SLOT;
+ abs[4].maximum = 2;
+
+ rc = test_create_abs_device(&uidev, &dev,
+ 5, abs,
+ EV_SYN, SYN_REPORT,
+ -1);
+ ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
+
+ /* invalid axis */
+ ck_assert_int_eq(libevdev_set_slot_value(dev, 1, ABS_Z, 1), -1);
+ /* valid, but non-mt axis */
+ ck_assert_int_eq(libevdev_set_slot_value(dev, 1, ABS_X, 1), -1);
+ /* invalid mt axis */
+ ck_assert_int_eq(libevdev_set_slot_value(dev, 1, ABS_MT_PRESSURE, 1), -1);
+ /* invalid slot no */
+ ck_assert_int_eq(libevdev_set_slot_value(dev, 4, ABS_X, 1), -1);
+
+ uinput_device_free(uidev);
+ libevdev_free(dev);
+}
+END_TEST
+
Suite *
libevdev_events(void)
{
tcase_add_test(tc, test_mt_event_values_invalid);
suite_add_tcase(s, tc);
+ tc = tcase_create("event value setters");
+ tcase_add_test(tc, test_event_value_setters);
+ tcase_add_test(tc, test_event_value_setters_invalid);
+ tcase_add_test(tc, test_event_mt_value_setters);
+ tcase_add_test(tc, test_event_mt_value_setters_invalid);
+ suite_add_tcase(s, tc);
+
return s;
}