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 <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
Peter Hutterer 2014-07-21 12:30:40 +10:00
parent bb10ec84d3
commit 61995348d9
6 changed files with 21 additions and 15 deletions

View file

@ -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 },
};

View file

@ -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 },
};

View file

@ -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 },
};

View file

@ -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 },
};

View file

@ -24,6 +24,7 @@
#include "config.h"
#endif
#include <assert.h>
#include <check.h>
#include <errno.h>
#include <fcntl.h>
@ -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;

View file

@ -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);