--- /dev/null
+/*
+ * 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);
+
+ 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);
+
+ 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;
+}
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,
&litest_bcm5974_device,
&litest_mouse_device,
&litest_wacom_touch_device,
+ &litest_alps_device,
NULL,
};
libinput_unref(d->libinput);
libevdev_free(d->evdev);
libevdev_uinput_destroy(d->uinput);
+ free(d->private);
memset(d,0, sizeof(*d));
free(d);
}
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;
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++;
}
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++;
}
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++;
}