Skip to content

Commit

Permalink
Keeps track of each multi-touch coordinate state
Browse files Browse the repository at this point in the history
Apparently evdev MT events out of laziness might update only one of coordinates on multi-touch slot update, thus causing residual coordinate from last parsed touch leak into the partially updated touch event.
  • Loading branch information
cipharius committed Sep 25, 2023
1 parent 3ed7f88 commit e384204
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/platform/evdev/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ static const char* envopts[] = {
*/
#define MAX_DEVICES 256

#define MAX_MT_SLOTS 5

struct devnode;
#include "device_db.h"

Expand Down Expand Up @@ -199,8 +201,8 @@ struct devnode {
struct {
bool active;
bool pending;
int x;
int y;
int x[MAX_MT_SLOTS];
int y[MAX_MT_SLOTS];
int pressure;
int size;
int ind;
Expand Down Expand Up @@ -1588,8 +1590,8 @@ static void flush_pending(
verbose_print("kind=touch:device=%d:base=%d", node->devnum, node->touch.ind);

newev.io.input.touch.active = node->touch.active;
newev.io.input.touch.x = node->touch.x;
newev.io.input.touch.y = node->touch.y;
newev.io.input.touch.x = node->touch.x[MIN(MAX_MT_SLOTS-1, node->touch.ind)];
newev.io.input.touch.y = node->touch.y[MIN(MAX_MT_SLOTS-1, node->touch.ind)];
newev.io.input.touch.pressure = node->touch.pressure;
newev.io.input.touch.size = node->touch.size;

Expand All @@ -1612,26 +1614,26 @@ static void decode_mt(struct arcan_evctx* ctx,
flush_pending(ctx, node);

node->touch.ind = 0;
node->touch.x = val;
node->touch.x[0] = val;
node->touch.pending = true;
break;
case ABS_Y:
if (node->touch.ind != 0 && node->touch.pending)
flush_pending(ctx, node);

node->touch.ind = 0;
node->touch.y = val;
node->touch.y[0] = val;
node->touch.pending = true;
break;
case ABS_MT_PRESSURE:
node->touch.pressure = val;
break;
case ABS_MT_POSITION_X:
node->touch.x = val;
node->touch.x[MIN(MAX_MT_SLOTS-1, node->touch.ind)] = val;
node->touch.pending = true;
break;
case ABS_MT_POSITION_Y:
node->touch.y = val;
node->touch.y[MIN(MAX_MT_SLOTS-1, node->touch.ind)] = val;
node->touch.pending = true;
break;
case ABS_DISTANCE:
Expand Down

0 comments on commit e384204

Please sign in to comment.