| 1 |
/* |
| 2 |
* Copyright © 2020 Red Hat, Inc. |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice (including the next |
| 12 |
* paragraph) shall be included in all copies or substantial portions of the |
| 13 |
* Software. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 |
* DEALINGS IN THE SOFTWARE. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include "config.h" |
| 25 |
|
| 26 |
#include <assert.h> |
| 27 |
|
| 28 |
#include "libinput-util.h" |
| 29 |
#include "litest-int.h" |
| 30 |
#include "litest.h" |
| 31 |
|
| 32 |
struct alps { |
| 33 |
unsigned int first, second; |
| 34 |
unsigned int active_touches; |
| 35 |
}; |
| 36 |
|
| 37 |
static bool |
| 38 |
alps_create(struct litest_device *d) |
| 39 |
{ |
| 40 |
d->private = zalloc(sizeof(struct alps)); |
| 41 |
return true; /* we want litest to create our device */ |
| 42 |
} |
| 43 |
|
| 44 |
static bool |
| 45 |
touch_down(struct litest_device *d, unsigned int slot, double x, double y) |
| 46 |
{ |
| 47 |
struct alps *alps = d->private; |
| 48 |
|
| 49 |
alps->active_touches++; |
| 50 |
|
| 51 |
if (alps->active_touches == 1) |
| 52 |
alps->first = slot; |
| 53 |
if (alps->active_touches == 2) |
| 54 |
alps->second = slot; |
| 55 |
|
| 56 |
/* This device announces 4 slots but only does two slots. So |
| 57 |
* anything over 2 slots we just drop for events, |
| 58 |
* litest takes care of BTN_TOOL_* for us. */ |
| 59 |
if (alps->active_touches > 2) { |
| 60 |
/* Need to send SYN_REPORT to flush litest's BTN_TOOL_* updates */ |
| 61 |
litest_event(d, EV_SYN, SYN_REPORT, 0); |
| 62 |
return true; |
| 63 |
} |
| 64 |
|
| 65 |
return false; |
| 66 |
} |
| 67 |
|
| 68 |
static bool |
| 69 |
touch_move(struct litest_device *d, unsigned int slot, double x, double y) |
| 70 |
{ |
| 71 |
struct alps *alps = d->private; |
| 72 |
|
| 73 |
if (alps->active_touches > 2 && slot != alps->first && slot != alps->second) |
| 74 |
return true; |
| 75 |
|
| 76 |
return false; |
| 77 |
} |
| 78 |
|
| 79 |
static bool |
| 80 |
touch_up(struct litest_device *d, unsigned int slot) |
| 81 |
{ |
| 82 |
struct alps *alps = d->private; |
| 83 |
|
| 84 |
assert(alps->active_touches >= 1); |
| 85 |
alps->active_touches--; |
| 86 |
|
| 87 |
/* Need to send SYN_REPORT to flush litest's BTN_TOOL_* updates */ |
| 88 |
if (alps->active_touches > 2 && slot != alps->first && slot != alps->second) { |
| 89 |
litest_event(d, EV_SYN, SYN_REPORT, 0); |
| 90 |
return true; |
| 91 |
} |
| 92 |
|
| 93 |
if (slot == alps->first) |
| 94 |
alps->first = UINT_MAX; |
| 95 |
if (slot == alps->second) |
| 96 |
alps->second = UINT_MAX; |
| 97 |
|
| 98 |
return false; |
| 99 |
} |
| 100 |
|
| 101 |
static struct input_event down[] = { |
| 102 |
{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, |
| 103 |
{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, |
| 104 |
{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, |
| 105 |
{ .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN }, |
| 106 |
{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, |
| 107 |
{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, |
| 108 |
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, |
| 109 |
{ .type = -1, .code = -1 }, |
| 110 |
}; |
| 111 |
|
| 112 |
static struct input_event move[] = { |
| 113 |
{ .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN }, |
| 114 |
{ .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN }, |
| 115 |
{ .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN }, |
| 116 |
{ .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN }, |
| 117 |
{ .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN }, |
| 118 |
{ .type = EV_SYN, .code = SYN_REPORT, .value = 0 }, |
| 119 |
{ .type = -1, .code = -1 }, |
| 120 |
}; |
| 121 |
|
| 122 |
static struct litest_device_interface interface = { |
| 123 |
.touch_down_events = down, |
| 124 |
.touch_move_events = move, |
| 125 |
|
| 126 |
.touch_down = touch_down, |
| 127 |
.touch_move = touch_move, |
| 128 |
.touch_up = touch_up, |
| 129 |
}; |
| 130 |
|
| 131 |
static struct input_id input_id = { |
| 132 |
.bustype = 0x11, |
| 133 |
.vendor = 0x2, |
| 134 |
.product = 0x8, |
| 135 |
.version = 0x700, |
| 136 |
}; |
| 137 |
|
| 138 |
/* clang-format off */ |
| 139 |
static int events[] = { |
| 140 |
EV_KEY, BTN_LEFT, |
| 141 |
EV_KEY, BTN_RIGHT, |
| 142 |
EV_KEY, BTN_MIDDLE, |
| 143 |
EV_KEY, BTN_TOOL_FINGER, |
| 144 |
EV_KEY, BTN_TOUCH, |
| 145 |
EV_KEY, BTN_TOOL_DOUBLETAP, |
| 146 |
EV_KEY, BTN_TOOL_TRIPLETAP, |
| 147 |
EV_KEY, BTN_TOOL_QUADTAP, |
| 148 |
EV_KEY, BTN_TOOL_QUINTTAP, |
| 149 |
INPUT_PROP_MAX, INPUT_PROP_POINTER, |
| 150 |
-1, -1, |
| 151 |
}; |
| 152 |
/* clang-format on */ |
| 153 |
|
| 154 |
/* Note: we use the user-supplied resolution here, see #408 */ |
| 155 |
/* clang-format off */ |
| 156 |
static struct input_absinfo absinfo[] = { |
| 157 |
{ ABS_X, 0, 4095, 0, 0, 37 }, |
| 158 |
{ ABS_Y, 0, 2047, 0, 0, 26 }, |
| 159 |
{ ABS_PRESSURE, 0, 127, 0, 0, 0 }, |
| 160 |
{ ABS_MT_SLOT, 0, 3, 0, 0, 0 }, |
| 161 |
{ ABS_MT_POSITION_X, 0, 4095, 0, 0, 37 }, |
| 162 |
{ ABS_MT_POSITION_Y, 0, 2047, 0, 0, 26 }, |
| 163 |
{ ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 }, |
| 164 |
{ .value = -1 }, |
| 165 |
}; |
| 166 |
/* clang-format on */ |
| 167 |
|
| 168 |
TEST_DEVICE(LITEST_ALPS_3FG, |
| 169 |
.features = LITEST_TOUCHPAD | LITEST_BUTTON, |
| 170 |
.interface = &interface, |
| 171 |
|
| 172 |
.name = "AlpsPS/2 ALPS GlidePoint", |
| 173 |
.id = &input_id, |
| 174 |
.events = events, |
| 175 |
.absinfo = absinfo, |
| 176 |
.create = alps_create, ) |