From 61995348d911d763960454725a91043989844e8f Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 21 Jul 2014 12:30:40 +1000 Subject: [PATCH] test: auto-update for BTN_TOOL_* when using litest_touch_ functions Set BTN_TOUCH, BTN_TOOL_DOUBLETAP automatically depending on the number of fingers down. This emulates real event sequences a bit better than the current approach, though it's not a 100% correct emulation: 1) On real devices, BTN_* are usually sent last before the SYN_REPORT - here they are sent first to slot in with the custom, device-specific event sequence. We should only ever look at the complete sequence anyway, so this shouldn't matter. 2) On real devices, the switch from BTN_TOOL_DOUBLETAP to TRIPLETAP and vice versa is not always toggled within the same SYN_REPORT 3) On synaptics devices, BTN_TOUCH is released in the frame where BTN_TOOL_DOUBLETAP is set. It is then immediately set again in the next frame. With the current litest framework this is hard to integrate, so we just leave BTN_TOUCH set the whole time, which is what MT devices do if they don't have BTN_TOOL_DOUBLETAP. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- test/litest-bcm5974.c | 4 ---- test/litest-synaptics-st.c | 3 --- test/litest-synaptics-t440.c | 4 ---- test/litest-synaptics.c | 4 ---- test/litest.c | 19 +++++++++++++++++++ test/litest.h | 2 ++ 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/test/litest-bcm5974.c b/test/litest-bcm5974.c index c7bd8573..035bed22 100644 --- a/test/litest-bcm5974.c +++ b/test/litest-bcm5974.c @@ -34,8 +34,6 @@ static void litest_bcm5974_setup(void) } struct input_event down[] = { - { .type = EV_KEY, .code = BTN_TOOL_FINGER, .value = 1 }, - { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = 30 }, @@ -53,8 +51,6 @@ static struct input_event move[] = { { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, - { .type = EV_KEY, .code = BTN_TOOL_FINGER, .value = 1 }, - { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; diff --git a/test/litest-synaptics-st.c b/test/litest-synaptics-st.c index fe263986..9f69332b 100644 --- a/test/litest-synaptics-st.c +++ b/test/litest-synaptics-st.c @@ -35,7 +35,6 @@ litest_synaptics_touchpad_setup(void) } static struct input_event down[] = { - { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = 30 }, @@ -47,13 +46,11 @@ static struct input_event down[] = { static struct input_event move[] = { { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, - { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; struct input_event up[] = { - { .type = EV_KEY, .code = BTN_TOUCH, .value = 0 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; diff --git a/test/litest-synaptics-t440.c b/test/litest-synaptics-t440.c index e3f14413..65a0ad4e 100644 --- a/test/litest-synaptics-t440.c +++ b/test/litest-synaptics-t440.c @@ -35,8 +35,6 @@ litest_synaptics_t440_setup(void) } static struct input_event down[] = { - { .type = EV_KEY, .code = BTN_TOOL_FINGER, .value = 1 }, - { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = 30 }, @@ -54,8 +52,6 @@ static struct input_event move[] = { { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, - { .type = EV_KEY, .code = BTN_TOOL_FINGER, .value = 1 }, - { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; diff --git a/test/litest-synaptics.c b/test/litest-synaptics.c index d55b65c4..5565e635 100644 --- a/test/litest-synaptics.c +++ b/test/litest-synaptics.c @@ -35,8 +35,6 @@ litest_synaptics_clickpad_setup(void) } static struct input_event down[] = { - { .type = EV_KEY, .code = BTN_TOOL_FINGER, .value = 1 }, - { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_PRESSURE, .value = 30 }, @@ -54,8 +52,6 @@ static struct input_event move[] = { { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, - { .type = EV_KEY, .code = BTN_TOOL_FINGER, .value = 1 }, - { .type = EV_KEY, .code = BTN_TOUCH, .value = 1 }, { .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, { .type = -1, .code = -1 }, }; diff --git a/test/litest.c b/test/litest.c index 4e79f7bc..deab0cff 100644 --- a/test/litest.c +++ b/test/litest.c @@ -24,6 +24,7 @@ #include "config.h" #endif +#include #include #include #include @@ -620,6 +621,16 @@ auto_assign_value(struct litest_device *d, return value; } +static void +send_btntool(struct litest_device *d) +{ + litest_event(d, EV_KEY, BTN_TOUCH, d->ntouches_down != 0); + litest_event(d, EV_KEY, BTN_TOOL_FINGER, d->ntouches_down == 1); + litest_event(d, EV_KEY, BTN_TOOL_DOUBLETAP, d->ntouches_down == 2); + litest_event(d, EV_KEY, BTN_TOOL_TRIPLETAP, d->ntouches_down == 3); + litest_event(d, EV_KEY, BTN_TOOL_QUADTAP, d->ntouches_down == 4); + litest_event(d, EV_KEY, BTN_TOOL_QUINTTAP, d->ntouches_down == 5); +} void litest_touch_down(struct litest_device *d, unsigned int slot, @@ -627,6 +638,10 @@ litest_touch_down(struct litest_device *d, unsigned int slot, { struct input_event *ev; + assert(++d->ntouches_down > 0); + + send_btntool(d); + if (d->interface->touch_down) { d->interface->touch_down(d, slot, x, y); return; @@ -651,6 +666,10 @@ litest_touch_up(struct litest_device *d, unsigned int slot) { .type = -1, .code = -1 } }; + assert(--d->ntouches_down >= 0); + + send_btntool(d); + if (d->interface->touch_up) { d->interface->touch_up(d, slot); return; diff --git a/test/litest.h b/test/litest.h index 2363c7f9..9a9d10a6 100644 --- a/test/litest.h +++ b/test/litest.h @@ -67,6 +67,8 @@ struct litest_device { bool owns_context; struct libinput_device *libinput_device; struct litest_device_interface *interface; + + int ntouches_down; }; struct libinput *litest_create_context(void); -- 2.34.1