update_mt_state(struct libevdev *dev, const struct input_event *e)
{
if (e->code == ABS_MT_SLOT) {
+ int i;
dev->current_slot = e->value;
+ /* sync abs_info with the current slot values */
+ for (i = ABS_MT_SLOT + 1; i <= ABS_MT_MAX; i++) {
+ if (libevdev_has_event_code(dev, EV_ABS, i))
+ dev->abs_info[i].value = dev->mt_slot_vals[dev->current_slot][i - ABS_MT_MIN];
+ }
+
return 0;
} else if (dev->current_slot == -1)
return 1;
return 1;
if (e->code >= ABS_MT_MIN && e->code <= ABS_MT_MAX)
- return update_mt_state(dev, e);
+ update_mt_state(dev, e);
dev->abs_info[e->code].value = e->value;
* Behaviour of this function is undefined if the device does not provide
* the event.
*
+ * If the device supports ABS_MT_SLOT, the value returned for any ABS_MT_*
+ * event code is the value of the currently active slot. You should use
+ * libevdev_get_slot_value() instead.
+ *
* @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 query for, one of ABS_X, REL_X, etc.
* this device. A future call to libevdev_get_event_value() will return this
* value, unless the value was overwritten by an event.
*
+ * If the device supports ABS_MT_SLOT, the value set for any ABS_MT_*
+ * event code is the value of the currently active slot. You should use
+ * libevdev_set_slot_value() instead.
+ *
* @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.
}
END_TEST
+START_TEST(test_event_mt_value_setters_current_slot)
+{
+ 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));
+
+ /* set_event_value/get_event_value works on the current slot */
+
+ ck_assert_int_eq(libevdev_get_current_slot(dev), 0);
+ ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_MT_POSITION_X, 1), 0);
+ ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_MT_POSITION_X), 1);
+ ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_X), 1);
+
+ ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_MT_SLOT, 1), 0);
+ ck_assert_int_eq(libevdev_get_current_slot(dev), 1);
+ ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_MT_POSITION_X, 2), 0);
+ ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_MT_POSITION_X), 2);
+ ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_X), 2);
+
+ /* set slot 0, but current is still slot 1 */
+ ck_assert_int_eq(libevdev_set_slot_value(dev, 0, ABS_MT_POSITION_X, 3), 0);
+ ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_MT_POSITION_X), 2);
+
+ ck_assert_int_eq(libevdev_set_event_value(dev, EV_ABS, ABS_MT_SLOT, 0), 0);
+ ck_assert_int_eq(libevdev_get_current_slot(dev), 0);
+ ck_assert_int_eq(libevdev_get_event_value(dev, EV_ABS, ABS_MT_POSITION_X), 3);
+
+ uinput_device_free(uidev);
+ libevdev_free(dev);
+}
+END_TEST
+
Suite *
libevdev_events(void)
{
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);
+ tcase_add_test(tc, test_event_mt_value_setters_current_slot);
suite_add_tcase(s, tc);
return s;