[PATCH libinput] test: add a semi-mt Alps test device

Hans de Goede hdegoede at redhat.com
Sun Jul 27 13:45:54 PDT 2014


Hi,

On 07/24/2014 08:53 AM, Peter Hutterer wrote:
> Provides the bounding box only, with slot 0 always being the upper/left, slot
> 1 being the lower-right touch. This needs to use the touch_down etc. litest
> interfaces, which are now widened to double (leftover from 489630f58) and a
> device-specific private pointer in the litest device.
> 
> New device feature for litest: LITEST_SEMI_MT
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

Thanks for working on this!

A few very small nitpicks, see below.


> ---
>  test/Makefile.am           |   1 +
>  test/litest-alps-semi-mt.c | 258 +++++++++++++++++++++++++++++++++++++++++++++
>  test/litest-int.h          |   4 +-
>  test/litest.c              |  17 +--
>  test/litest.h              |   6 ++
>  5 files changed, 277 insertions(+), 9 deletions(-)
>  create mode 100644 test/litest-alps-semi-mt.c
> 
> diff --git a/test/Makefile.am b/test/Makefile.am
> index c3c293a..35c3bf8 100644
> --- a/test/Makefile.am
> +++ b/test/Makefile.am
> @@ -15,6 +15,7 @@ liblitest_la_SOURCES = \
>  	../src/libinput-util.c \
>  	litest.h \
>  	litest-int.h \
> +	litest-alps-semi-mt.c \
>  	litest-bcm5974.c \
>  	litest-keyboard.c \
>  	litest-mouse.c \
> diff --git a/test/litest-alps-semi-mt.c b/test/litest-alps-semi-mt.c
> new file mode 100644
> index 0000000..2e85540
> --- /dev/null
> +++ b/test/litest-alps-semi-mt.c
> @@ -0,0 +1,258 @@
> +/*
> + * Copyright © 2014 Red Hat, Inc.
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and its
> + * documentation for any purpose is hereby granted without fee, provided that
> + * the above copyright notice appear in all copies and that both that copyright
> + * notice and this permission notice appear in supporting documentation, and
> + * that the name of the copyright holders not be used in advertising or
> + * publicity pertaining to distribution of the software without specific,
> + * written prior permission.  The copyright holders make no representations
> + * about the suitability of this software for any purpose.  It is provided "as
> + * is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
> + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
> + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
> + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
> + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
> + * OF THIS SOFTWARE.
> + */
> +
> +#if HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> +#include <assert.h>
> +
> +#include "libinput-util.h"
> +
> +#include "litest.h"
> +#include "litest-int.h"
> +
> +static int tracking_id;
> +
> +/* this is a semi-mt device, so we keep track of the touches that the tests
> + * send and modify them so that the first touch is always slot 0 and sends
> + * the top-left of the bounding box, the second is always slot 1 and sends
> + * the bottom-right of the bounding box.
> + * Lifting any of two fingers terminates slot 1
> + */
> +struct alps {
> +	/* The actual touches requested by the test for the two slots
> +	 * in the 0..100 range used by litest */
> +	struct {
> +		double x, y;
> +	} touches[2];
> +};
> +
> +static void alps_create(struct litest_device *d);
> +
> +static void
> +litest_alps_setup(void)
> +{
> +	struct litest_device *d = litest_create_device(LITEST_ALPS_SEMI_MT);
> +	litest_set_current_device(d);
> +}
> +
> +static void
> +send_abs_xy(struct litest_device *d, double x, double y)
> +{
> +	struct input_event e;
> +	int val;
> +
> +	e.type = EV_ABS;
> +	e.code = ABS_X;
> +	e.value = LITEST_AUTO_ASSIGN;
> +	val = litest_auto_assign_value(d, &e, 0, x, y);
> +	litest_event(d, EV_ABS, ABS_X, val);
> +
> +	e.code = ABS_Y;
> +	val = litest_auto_assign_value(d, &e, 0, x, y);
> +	litest_event(d, EV_ABS, ABS_Y, val);
> +}
> +
> +static void
> +send_abs_mt_xy(struct litest_device *d, double x, double y)
> +{
> +	struct input_event e;
> +	int val;
> +
> +	e.type = EV_ABS;
> +	e.code = ABS_MT_POSITION_X;
> +	e.value = LITEST_AUTO_ASSIGN;
> +	val = litest_auto_assign_value(d, &e, 0, x, y);
> +	litest_event(d, EV_ABS, ABS_MT_POSITION_X, val);
> +
> +	e.code = ABS_MT_POSITION_Y;
> +	e.value = LITEST_AUTO_ASSIGN;
> +	val = litest_auto_assign_value(d, &e, 0, x, y);
> +	litest_event(d, EV_ABS, ABS_MT_POSITION_Y, val);
> +}
> +
> +static void
> +alps_touch_down(struct litest_device *d, unsigned int slot, double x, double y)
> +{
> +	struct alps *alps = d->private;
> +	double t, l, r, b; /* top, left, right, bottom */
> +
> +	if (d->ntouches_down > 2 || slot > 1)
> +		return;
> +
> +	if (d->ntouches_down == 1) {
> +		l = x;
> +		t = y;
> +	} else {
> +		int other = (slot + 1) % 2;
> +		l = min(x, alps->touches[other].x);
> +		t = min(y, alps->touches[other].y);
> +		r = max(x, alps->touches[other].x);
> +		b = max(y, alps->touches[other].y);
> +	}
> +
> +	send_abs_xy(d, l, t);

Please add an empty line here to separate the single touch
coordinate sending from the slot 0 handling.

> +	litest_event(d, EV_ABS, ABS_MT_SLOT, 0);
> +
> +	if (d->ntouches_down == 1)
> +		litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, ++tracking_id);
> +
> +	send_abs_mt_xy(d, l, t);
> +
> +	if (d->ntouches_down == 2) {
> +		litest_event(d, EV_ABS, ABS_MT_SLOT, 1);
> +		litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, ++tracking_id);
> +
> +		send_abs_mt_xy(d, r, b);
> +	}
> +
> +	litest_event(d, EV_SYN, SYN_REPORT, 0);
> +
> +	alps->touches[slot].x = x;
> +	alps->touches[slot].y = y;
> +}
> +
> +static void
> +alps_touch_move(struct litest_device *d, unsigned int slot, double x, double y)
> +{
> +	struct alps *alps = d->private;
> +	double t, l, r, b; /* top, left, right, bottom */
> +
> +	if (d->ntouches_down > 2 || slot > 1)
> +		return;
> +
> +	if (d->ntouches_down == 1) {
> +		l = x;
> +		t = y;
> +	} else {
> +		int other = (slot + 1) % 2;
> +		l = min(x, alps->touches[other].x);
> +		t = min(y, alps->touches[other].y);
> +		r = max(x, alps->touches[other].x);
> +		b = max(y, alps->touches[other].y);
> +	}
> +
> +	send_abs_xy(d, l, t);

Idem (Please add an empty line here to separate the single touch
coordinate sending from the slot 0 handling).

With these 2 fixed this patch is:

Acked-by: Hans de Goede <hdegoede at redhat.com>

> +	litest_event(d, EV_ABS, ABS_MT_SLOT, 0);
> +	send_abs_mt_xy(d, l, t);
> +
> +	if (d->ntouches_down == 2) {
> +		litest_event(d, EV_ABS, ABS_MT_SLOT, 1);
> +		send_abs_mt_xy(d, r, b);
> +	}
> +
> +	litest_event(d, EV_SYN, SYN_REPORT, 0);
> +
> +	alps->touches[slot].x = x;
> +	alps->touches[slot].y = y;
> +}
> +
> +static void
> +alps_touch_up(struct litest_device *d, unsigned int slot)
> +{
> +	struct alps *alps = d->private;
> +
> +	/* note: ntouches_down is decreased before we get here */
> +	if (d->ntouches_down >= 2 || slot > 1)
> +		return;
> +
> +	litest_event(d, EV_ABS, ABS_MT_SLOT, d->ntouches_down);
> +	litest_event(d, EV_ABS, ABS_MT_TRACKING_ID, -1);
> +
> +	/* if we have one finger left, send x/y coords for that finger left.
> +	   this is likely to happen with a real touchpad */
> +	if (d->ntouches_down == 1) {
> +		int other = (slot + 1) % 2;
> +		send_abs_xy(d, alps->touches[other].x, alps->touches[other].y);
> +		litest_event(d, EV_ABS, ABS_MT_SLOT, 0);
> +		send_abs_mt_xy(d, alps->touches[other].x, alps->touches[other].y);
> +	}
> +
> +	litest_event(d, EV_SYN, SYN_REPORT, 0);
> +}
> +
> +static struct litest_device_interface interface = {
> +	.touch_down = alps_touch_down,
> +	.touch_move = alps_touch_move,
> +	.touch_up = alps_touch_up,
> +};
> +
> +static struct input_id input_id = {
> +	.bustype = 0x11,
> +	.vendor = 0x2,
> +	.product = 0x8,
> +};
> +
> +static int events[] = {
> +	EV_KEY, BTN_LEFT,
> +	EV_KEY, BTN_RIGHT,
> +	EV_KEY, BTN_MIDDLE,
> +	EV_KEY, BTN_TOOL_FINGER,
> +	EV_KEY, BTN_TOUCH,
> +	EV_KEY, BTN_TOOL_DOUBLETAP,
> +	EV_KEY, BTN_TOOL_TRIPLETAP,
> +	EV_KEY, BTN_TOOL_QUADTAP,
> +	INPUT_PROP_MAX, INPUT_PROP_POINTER,
> +	INPUT_PROP_MAX, INPUT_PROP_SEMI_MT,
> +	-1, -1,
> +};
> +
> +static struct input_absinfo absinfo[] = {
> +	{ ABS_X, 0, 2000, 0, 0, 0 },
> +	{ ABS_Y, 0, 1400, 0, 0, 0 },
> +	{ ABS_PRESSURE, 0, 127, 0, 0, 0 },
> +	{ ABS_MT_SLOT, 0, 1, 0, 0, 0 },
> +	{ ABS_MT_POSITION_X, 0, 2000, 0, 0, 0 },
> +	{ ABS_MT_POSITION_Y, 0, 1400, 0, 0, 0 },
> +	{ ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 },
> +	{ .value = -1 }
> +};
> +
> +struct litest_test_device litest_alps_device = {
> +	.type = LITEST_ALPS_SEMI_MT,
> +	.features = LITEST_TOUCHPAD | LITEST_BUTTON | LITEST_SEMI_MT,
> +	.shortname = "alps semi-mt",
> +	.setup = litest_alps_setup,
> +	.interface = &interface,
> +	.create = alps_create,
> +
> +	.name = "AlpsPS/2 ALPS GlidePoint",
> +	.id = &input_id,
> +	.events = events,
> +	.absinfo = absinfo,
> +};
> +
> +static void
> +alps_create(struct litest_device *d)
> +{
> +	struct alps *alps = zalloc(sizeof(*alps));
> +	assert(alps);
> +
> +	d->private = alps;
> +
> +	d->uinput = litest_create_uinput_device_from_description(litest_alps_device.name,
> +								 litest_alps_device.id,
> +								 absinfo,
> +								 events);
> +	d->interface = &interface;
> +}
> diff --git a/test/litest-int.h b/test/litest-int.h
> index 581930b..95bc248 100644
> --- a/test/litest-int.h
> +++ b/test/litest-int.h
> @@ -72,8 +72,8 @@ struct litest_test_device {
>  };
>  
>  struct litest_device_interface {
> -	void (*touch_down)(struct litest_device *d, unsigned int slot, int x, int y);
> -	void (*touch_move)(struct litest_device *d, unsigned int slot, int x, int y);
> +	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);
>  
>  	/**
> diff --git a/test/litest.c b/test/litest.c
> index deab0cf..18e2e32 100644
> --- a/test/litest.c
> +++ b/test/litest.c
> @@ -85,6 +85,7 @@ extern struct litest_test_device litest_trackpoint_device;
>  extern struct litest_test_device litest_bcm5974_device;
>  extern struct litest_test_device litest_mouse_device;
>  extern struct litest_test_device litest_wacom_touch_device;
> +extern struct litest_test_device litest_alps_device;
>  
>  struct litest_test_device* devices[] = {
>  	&litest_synaptics_clickpad_device,
> @@ -95,6 +96,7 @@ struct litest_test_device* devices[] = {
>  	&litest_bcm5974_device,
>  	&litest_mouse_device,
>  	&litest_wacom_touch_device,
> +	&litest_alps_device,
>  	NULL,
>  };
>  
> @@ -578,6 +580,7 @@ litest_delete_device(struct litest_device *d)
>  		libinput_unref(d->libinput);
>  	libevdev_free(d->evdev);
>  	libevdev_uinput_destroy(d->uinput);
> +	free(d->private);
>  	memset(d,0, sizeof(*d));
>  	free(d);
>  }
> @@ -590,10 +593,10 @@ litest_event(struct litest_device *d, unsigned int type,
>  	ck_assert_int_eq(ret, 0);
>  }
>  
> -static int
> -auto_assign_value(struct litest_device *d,
> -		  const struct input_event *ev,
> -		  int slot, double x, double y)
> +int
> +litest_auto_assign_value(struct litest_device *d,
> +			 const struct input_event *ev,
> +			 int slot, double x, double y)
>  {
>  	static int tracking_id;
>  	int value = ev->value;
> @@ -649,7 +652,7 @@ litest_touch_down(struct litest_device *d, unsigned int slot,
>  
>  	ev = d->interface->touch_down_events;
>  	while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
> -		int value = auto_assign_value(d, ev, slot, x, y);
> +		int value = litest_auto_assign_value(d, ev, slot, x, y);
>  		litest_event(d, ev->type, ev->code, value);
>  		ev++;
>  	}
> @@ -679,7 +682,7 @@ litest_touch_up(struct litest_device *d, unsigned int slot)
>  		ev = up;
>  
>  	while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
> -		int value = auto_assign_value(d, ev, slot, 0, 0);
> +		int value = litest_auto_assign_value(d, ev, slot, 0, 0);
>  		litest_event(d, ev->type, ev->code, value);
>  		ev++;
>  	}
> @@ -698,7 +701,7 @@ litest_touch_move(struct litest_device *d, unsigned int slot,
>  
>  	ev = d->interface->touch_move_events;
>  	while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
> -		int value = auto_assign_value(d, ev, slot, x, y);
> +		int value = litest_auto_assign_value(d, ev, slot, x, y);
>  		litest_event(d, ev->type, ev->code, value);
>  		ev++;
>  	}
> diff --git a/test/litest.h b/test/litest.h
> index 9a9d10a..bb3fd7d 100644
> --- a/test/litest.h
> +++ b/test/litest.h
> @@ -43,6 +43,7 @@ enum litest_device_type {
>  	LITEST_TRACKPOINT,
>  	LITEST_MOUSE,
>  	LITEST_WACOM_TOUCH,
> +	LITEST_ALPS_SEMI_MT,
>  };
>  
>  enum litest_device_feature {
> @@ -58,6 +59,7 @@ enum litest_device_feature {
>  	LITEST_SINGLE_TOUCH = 1 << 7,
>  	LITEST_APPLE_CLICKPAD = 1 << 8,
>  	LITEST_TOPBUTTONPAD = 1 << 9,
> +	LITEST_SEMI_MT = 1 << 10,
>  };
>  
>  struct litest_device {
> @@ -69,6 +71,7 @@ struct litest_device {
>  	struct litest_device_interface *interface;
>  
>  	int ntouches_down;
> +	void *private; /* device-specific data */
>  };
>  
>  struct libinput *litest_create_context(void);
> @@ -107,6 +110,9 @@ void litest_event(struct litest_device *t,
>  		  unsigned int type,
>  		  unsigned int code,
>  		  int value);
> +int litest_auto_assign_value(struct litest_device *d,
> +			     const struct input_event *ev,
> +			     int slot, double x, double y);
>  void litest_touch_up(struct litest_device *d, unsigned int slot);
>  void litest_touch_move(struct litest_device *d,
>  		       unsigned int slot,
> 


More information about the wayland-devel mailing list