The current code sometimes misses to report the last BTN_TOUCH event
when multiple fingers are lifted simultaneously. With the
introduction of MT slots, the tracking id is available to determine
the oldest active contact. Use this information to simplify and
correct the touchscreen emulation logic.
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Acked-by: Stéphane Chatty <chatty@enac.fr>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
struct mmm_finger {
__s32 x, y, w, h;
__u16 id;
struct mmm_finger {
__s32 x, y, w, h;
__u16 id;
bool prev_touch;
bool touch, valid;
};
bool prev_touch;
bool touch, valid;
};
struct mmm_data {
struct mmm_finger f[MAX_SLOTS];
__u16 id;
struct mmm_data {
struct mmm_finger f[MAX_SLOTS];
__u16 id;
__u8 nexp, nreal;
bool touch, valid;
};
__u8 nexp, nreal;
bool touch, valid;
};
static void mmm_filter_event(struct mmm_data *md, struct input_dev *input)
{
struct mmm_finger *oldest = 0;
static void mmm_filter_event(struct mmm_data *md, struct input_dev *input)
{
struct mmm_finger *oldest = 0;
- bool pressed = false, released = false;
-
- /*
- * we need to iterate on all fingers to decide if we have a press
- * or a release event in our touchscreen emulation.
- */
for (i = 0; i < MAX_SLOTS; ++i) {
struct mmm_finger *f = &md->f[i];
if (!f->valid) {
for (i = 0; i < MAX_SLOTS; ++i) {
struct mmm_finger *f = &md->f[i];
if (!f->valid) {
wide ? f->w : f->h);
input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR,
wide ? f->h : f->w);
wide ? f->w : f->h);
input_event(input, EV_ABS, ABS_MT_TOUCH_MINOR,
wide ? f->h : f->w);
- /*
- * touchscreen emulation: maintain the age rank
- * of this finger, decide if we have a press
- */
- if (f->rank == 0) {
- f->rank = ++(md->num);
- if (f->rank == 1)
- pressed = true;
- }
- if (f->rank == 1)
+ /* touchscreen emulation: pick the oldest contact */
+ if (!oldest || ((f->id - oldest->id) & (SHRT_MAX + 1)))
oldest = f;
} else {
/* this finger took off the screen */
oldest = f;
} else {
/* this finger took off the screen */
- /* touchscreen emulation: maintain age rank of others */
- int j;
-
- for (j = 0; j < 10; ++j) {
- struct mmm_finger *g = &md->f[j];
- if (g->rank > f->rank) {
- g->rank--;
- if (g->rank == 1)
- oldest = g;
- }
- }
- f->rank = 0;
- --(md->num);
- if (md->num == 0)
- released = true;
input_event(input, EV_ABS, ABS_MT_TRACKING_ID, -1);
}
f->prev_touch = f->touch;
input_event(input, EV_ABS, ABS_MT_TRACKING_ID, -1);
}
f->prev_touch = f->touch;
/* touchscreen emulation */
if (oldest) {
/* touchscreen emulation */
if (oldest) {
- if (pressed)
- input_event(input, EV_KEY, BTN_TOUCH, 1);
+ input_event(input, EV_KEY, BTN_TOUCH, 1);
input_event(input, EV_ABS, ABS_X, oldest->x);
input_event(input, EV_ABS, ABS_Y, oldest->y);
input_event(input, EV_ABS, ABS_X, oldest->x);
input_event(input, EV_ABS, ABS_Y, oldest->y);
input_event(input, EV_KEY, BTN_TOUCH, 0);
}
input_sync(input);
input_event(input, EV_KEY, BTN_TOUCH, 0);
}
input_sync(input);