From 56f1ac2b721d2b42679425e12dba9710864611ef Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 9 Jan 2020 09:48:29 +1000 Subject: [PATCH] test: make the custom touch override methods filter-able 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 --- test/litest-device-protocol-a-touch-screen.c | 12 +++++++++--- test/litest-device-qemu-usb-tablet.c | 17 ++++++++++++----- test/litest-device-vmware-virtual-usb-mouse.c | 17 ++++++++++++----- test/litest-device-xen-virtual-pointer.c | 17 ++++++++++++----- test/litest-int.h | 6 +++--- test/litest.c | 18 +++++++++--------- 6 files changed, 57 insertions(+), 30 deletions(-) diff --git a/test/litest-device-protocol-a-touch-screen.c b/test/litest-device-protocol-a-touch-screen.c index 258955c8..3a6bfbcc 100644 --- a/test/litest-device-protocol-a-touch-screen.c +++ b/test/litest-device-protocol-a-touch-screen.c @@ -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; @@ -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; @@ -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; @@ -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 = { diff --git a/test/litest-device-qemu-usb-tablet.c b/test/litest-device-qemu-usb-tablet.c index bfcbc736..f8ed1b94 100644 --- a/test/litest-device-qemu-usb-tablet.c +++ b/test/litest-device-qemu-usb-tablet.c @@ -27,30 +27,37 @@ #include "litest-int.h" #include -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 = { diff --git a/test/litest-device-vmware-virtual-usb-mouse.c b/test/litest-device-vmware-virtual-usb-mouse.c index faefda33..81fd0b7c 100644 --- a/test/litest-device-vmware-virtual-usb-mouse.c +++ b/test/litest-device-vmware-virtual-usb-mouse.c @@ -27,30 +27,37 @@ #include "litest-int.h" #include -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 = { diff --git a/test/litest-device-xen-virtual-pointer.c b/test/litest-device-xen-virtual-pointer.c index 44d30131..79c4c555 100644 --- a/test/litest-device-xen-virtual-pointer.c +++ b/test/litest-device-xen-virtual-pointer.c @@ -27,30 +27,37 @@ #include "litest-int.h" #include -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 = { diff --git a/test/litest-int.h b/test/litest-int.h index 598c8d0a..36be7a5b 100644 --- a/test/litest-int.h +++ b/test/litest-int.h @@ -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. diff --git a/test/litest.c b/test/litest.c index f93eb990..9f441704 100644 --- a/test/litest.c +++ b/test/litest.c @@ -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; @@ -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; @@ -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;