mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-30 07:10:08 +01:00
test: Add infrastructure for testing tablet events.
no vfuncs are used, only input_event arrays. Signed-off-by: Carlos Garnacho <carlosg@gnome.org> Signed-off-by: Stephen Chandler Paul <thatslyude@gmail.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
6d0fceb225
commit
204d1d7514
3 changed files with 110 additions and 0 deletions
|
|
@ -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];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -58,6 +58,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 +72,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 +125,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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue