[PATCH libinput 14/23] test: Add infrastructure for testing tablet events.
Stephen Chandler Paul
thatslyude at gmail.com
Thu Jun 12 20:28:35 PDT 2014
From: Carlos Garnacho <carlosg at gnome.org>
no vfuncs are used, only input_event arrays.
Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
Signed-off-by: Stephen Chandler Paul <thatslyude at gmail.com>
--- Changes ---
- Removed clear_axes and clear_buttons input_event fields
- Add field for bad distance events
- Add feature to indicate that a tablet is capable of sending distance events
---
test/litest-int.h | 8 +++++
test/litest.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
test/litest.h | 14 +++++++++
3 files changed, 111 insertions(+)
diff --git a/test/litest-int.h b/test/litest-int.h
index 19e6e68..e64f8b8 100644
--- a/test/litest-int.h
+++ b/test/litest-int.h
@@ -88,6 +88,14 @@ struct litest_device_interface {
struct input_event *touch_move_events;
struct input_event *touch_up_events;
+ /**
+ * Tablet events, LITEST_AUTO_ASSIGN is allowed on event values for
+ * ABS_X, ABS_Y, ABS_DISTANCE and ABS_PRESSURE.
+ */
+ struct input_event *tablet_proximity_in_events;
+ struct input_event *tablet_proximity_out_events;
+ struct input_event *tablet_motion_events;
+
int min[2];
int max[2];
};
diff --git a/test/litest.c b/test/litest.c
index 0a9cc72..f728707 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -695,6 +695,95 @@ litest_touch_move_to(struct litest_device *d,
litest_touch_move(d, slot, x_to, y_to);
}
+static int32_t
+axis_replacement_value(struct axis_replacement *axes,
+ int32_t evcode)
+{
+ struct axis_replacement *axis = axes;
+
+ while (axis->evcode != -1) {
+ if (axis->evcode == evcode)
+ return axis->value;
+ axis++;
+ }
+
+ return -1;
+}
+
+static int
+auto_assign_tablet_value(struct litest_device *d,
+ const struct input_event *ev,
+ int x, int y,
+ struct axis_replacement *axes)
+{
+ int value = ev->value;
+
+ if (value != LITEST_AUTO_ASSIGN || ev->type != EV_ABS)
+ return value;
+
+ switch (ev->code) {
+ case ABS_X:
+ value = litest_scale(d, ABS_X, x);
+ break;
+ case ABS_Y:
+ value = litest_scale(d, ABS_Y, y);
+ break;
+ default:
+ value = axis_replacement_value(axes, ev->code);
+ break;
+ }
+
+ return value;
+}
+
+static int
+tablet_ignore_event(const struct input_event *ev, int value)
+{
+ return value == -1 && (ev->code == ABS_PRESSURE || ev->code == ABS_DISTANCE);
+}
+
+void
+litest_tablet_proximity_in(struct litest_device *d, int x, int y, struct axis_replacement *axes)
+{
+ struct input_event *ev;
+
+ ev = d->interface->tablet_proximity_in_events;
+ while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
+ int value = auto_assign_tablet_value(d, ev, x, y, axes);
+ if (!tablet_ignore_event(ev, value))
+ litest_event(d, ev->type, ev->code, value);
+ ev++;
+ }
+}
+
+void
+litest_tablet_proximity_out(struct litest_device *d)
+{
+ struct input_event *ev;
+
+ ev = d->interface->tablet_proximity_out_events;
+ while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
+ int value = auto_assign_tablet_value(d, ev, -1, -1, NULL);
+ if (!tablet_ignore_event(ev, value))
+ litest_event(d, ev->type, ev->code, value);
+ ev++;
+ }
+}
+
+void
+litest_tablet_motion(struct litest_device *d, int x, int y, struct axis_replacement *axes)
+{
+ struct input_event *ev;
+
+ ev = d->interface->tablet_motion_events;
+ while (ev && (int16_t)ev->type != -1 && (int16_t)ev->code != -1) {
+ int value = auto_assign_tablet_value(d, ev, x, y, axes);
+ if (!tablet_ignore_event(ev, value))
+ litest_event(d, ev->type, ev->code, value);
+ ev++;
+ }
+}
+
void
litest_button_click(struct litest_device *d, unsigned int button, bool is_press)
{
diff --git a/test/litest.h b/test/litest.h
index 3e75dd5..ec7026f 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_WACOM_TABLET,
};
enum litest_device_feature {
@@ -58,6 +59,8 @@ enum litest_device_feature {
LITEST_SINGLE_TOUCH = 1 << 7,
LITEST_APPLE_CLICKPAD = 1 << 8,
LITEST_TOPBUTTONPAD = 1 << 9,
+ LITEST_TABLET = 1 << 10,
+ LITEST_DISTANCE = 1 << 11,
};
struct litest_device {
@@ -70,6 +73,10 @@ struct litest_device {
};
struct libinput *litest_create_context(void);
+struct axis_replacement {
+ int32_t evcode;
+ int32_t value;
+};
void litest_add(const char *name, void *func,
enum litest_device_feature required_feature,
@@ -119,6 +126,13 @@ void litest_touch_move_to(struct litest_device *d,
int x_from, int y_from,
int x_to, int y_to,
int steps);
+void litest_tablet_proximity_in(struct litest_device *d,
+ int x, int y,
+ struct axis_replacement *axes);
+void litest_tablet_proximity_out(struct litest_device *d);
+void litest_tablet_motion(struct litest_device *d,
+ int x, int y,
+ struct axis_replacement *axes);
void litest_button_click(struct litest_device *d,
unsigned int button,
bool is_press);
--
1.8.5.5
More information about the wayland-devel
mailing list