Skip to content

Commit

Permalink
test: make the custom touch override methods filter-able
Browse files Browse the repository at this point in the history
Let those functions return true if they handled the event or false where they
didn't. This makes it more flexible to override touches in special cases only
and fall back to the normal litest handling otherwise.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Jan 29, 2020
1 parent 8fdeba9 commit 56f1ac2
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 30 deletions.
12 changes: 9 additions & 3 deletions test/litest-device-protocol-a-touch-screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protocolA_create(struct litest_device *d)
return true; /* we want litest to create our device */
}

static void
static bool
protocolA_down(struct litest_device *d, unsigned int slot, double x, double y)
{
struct protocolA_device *dev = d->private;
Expand Down Expand Up @@ -90,9 +90,11 @@ protocolA_down(struct litest_device *d, unsigned int slot, double x, double y)
litest_event(d, EV_KEY, BTN_TOUCH, 1);
litest_event(d, EV_SYN, SYN_REPORT, 0);
}

return true; /* we handled the event */
}

static void
static bool
protocolA_move(struct litest_device *d, unsigned int slot, double x, double y)
{
struct protocolA_device *dev = d->private;
Expand Down Expand Up @@ -128,9 +130,11 @@ protocolA_move(struct litest_device *d, unsigned int slot, double x, double y)

if (!first)
litest_event(d, EV_SYN, SYN_REPORT, 0);

return true; /* we handled the event */
}

static void
static bool
protocolA_up(struct litest_device *d, unsigned int slot)
{
struct protocolA_device *dev = d->private;
Expand Down Expand Up @@ -166,6 +170,8 @@ protocolA_up(struct litest_device *d, unsigned int slot)
if (first)
litest_event(d, EV_KEY, BTN_TOUCH, 0);
litest_event(d, EV_SYN, SYN_REPORT, 0);

return true; /* we handled the event */
}

static struct litest_device_interface interface = {
Expand Down
17 changes: 12 additions & 5 deletions test/litest-device-qemu-usb-tablet.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,37 @@
#include "litest-int.h"
#include <assert.h>

static void touch_down(struct litest_device *d, unsigned int slot,
double x, double y)
static bool
touch_down(struct litest_device *d, unsigned int slot, double x, double y)
{
assert(slot == 0);

litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x));
litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y));
litest_event(d, EV_SYN, SYN_REPORT, 0);

return true; /* we handled the event */
}

static void touch_move(struct litest_device *d, unsigned int slot,
double x, double y)
static bool
touch_move(struct litest_device *d, unsigned int slot, double x, double y)
{
assert(slot == 0);

litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x));
litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y));
litest_event(d, EV_SYN, SYN_REPORT, 0);

return true; /* we handled the event */
}

static void touch_up(struct litest_device *d, unsigned int slot)
static bool
touch_up(struct litest_device *d, unsigned int slot)
{
assert(slot == 0);
litest_event(d, EV_SYN, SYN_REPORT, 0);

return true; /* we handled the event */
}

static struct litest_device_interface interface = {
Expand Down
17 changes: 12 additions & 5 deletions test/litest-device-vmware-virtual-usb-mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,37 @@
#include "litest-int.h"
#include <assert.h>

static void touch_down(struct litest_device *d, unsigned int slot,
double x, double y)
static bool
touch_down(struct litest_device *d, unsigned int slot, double x, double y)
{
assert(slot == 0);

litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x));
litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y));
litest_event(d, EV_SYN, SYN_REPORT, 0);

return true; /* we handled the event */
}

static void touch_move(struct litest_device *d, unsigned int slot,
double x, double y)
static bool
touch_move(struct litest_device *d, unsigned int slot, double x, double y)
{
assert(slot == 0);

litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x));
litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y));
litest_event(d, EV_SYN, SYN_REPORT, 0);

return true; /* we handled the event */
}

static void touch_up(struct litest_device *d, unsigned int slot)
static bool
touch_up(struct litest_device *d, unsigned int slot)
{
assert(slot == 0);
litest_event(d, EV_SYN, SYN_REPORT, 0);

return true; /* we handled the event */
}

static struct litest_device_interface interface = {
Expand Down
17 changes: 12 additions & 5 deletions test/litest-device-xen-virtual-pointer.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,37 @@
#include "litest-int.h"
#include <assert.h>

static void touch_down(struct litest_device *d, unsigned int slot,
double x, double y)
static bool
touch_down(struct litest_device *d, unsigned int slot, double x, double y)
{
assert(slot == 0);

litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x));
litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y));
litest_event(d, EV_SYN, SYN_REPORT, 0);

return true; /* we handled the event */
}

static void touch_move(struct litest_device *d, unsigned int slot,
double x, double y)
static bool
touch_move(struct litest_device *d, unsigned int slot, double x, double y)
{
assert(slot == 0);

litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x));
litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y));
litest_event(d, EV_SYN, SYN_REPORT, 0);

return true; /* we handled the event */
}

static void touch_up(struct litest_device *d, unsigned int slot)
static bool
touch_up(struct litest_device *d, unsigned int slot)
{
assert(slot == 0);
litest_event(d, EV_SYN, SYN_REPORT, 0);

return true; /* we handled the event */
}

static struct litest_device_interface interface = {
Expand Down
6 changes: 3 additions & 3 deletions test/litest-int.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ struct litest_test_device {
};

struct litest_device_interface {
void (*touch_down)(struct litest_device *d, unsigned int slot, double x, double y);
void (*touch_move)(struct litest_device *d, unsigned int slot, double x, double y);
void (*touch_up)(struct litest_device *d, unsigned int slot);
bool (*touch_down)(struct litest_device *d, unsigned int slot, double x, double y);
bool (*touch_move)(struct litest_device *d, unsigned int slot, double x, double y);
bool (*touch_up)(struct litest_device *d, unsigned int slot);

/**
* Default value for the given EV_ABS axis.
Expand Down
18 changes: 9 additions & 9 deletions test/litest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1954,10 +1954,11 @@ slot_start(struct litest_device *d,

send_btntool(d, !touching);

if (d->interface->touch_down) {
d->interface->touch_down(d, slot, x, y);
return;
}
/* If the test device overrides touch_down and says it didn't
* handle the event, let's continue normally */
if (d->interface->touch_down &&
d->interface->touch_down(d, slot, x, y))
return;

for (ev = d->interface->touch_down_events;
ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1;
Expand Down Expand Up @@ -1991,10 +1992,9 @@ slot_move(struct litest_device *d,
{
struct input_event *ev;

if (d->interface->touch_move) {
d->interface->touch_move(d, slot, x, y);
if (d->interface->touch_move &&
d->interface->touch_move(d, slot, x, y))
return;
}

for (ev = d->interface->touch_move_events;
ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1;
Expand Down Expand Up @@ -2036,8 +2036,8 @@ touch_up(struct litest_device *d, unsigned int slot)

send_btntool(d, false);

if (d->interface->touch_up) {
d->interface->touch_up(d, slot);
if (d->interface->touch_up &&
d->interface->touch_up(d, slot)) {
return;
} else if (d->interface->touch_up_events) {
ev = d->interface->touch_up_events;
Expand Down

0 comments on commit 56f1ac2

Please sign in to comment.