Skip to content

Commit

Permalink
(platform/evdev) track 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 2b45b6e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/platform/evdev/event.c
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 @@ -1604,34 +1606,32 @@ static void decode_mt(struct arcan_evctx* ctx,
/* there are multiple protocols and mappings for this that we don't
* account for here, move it to a toch event with the basic information
* and let higher layers deal with it */
int newind = -1;

switch(code){
case ABS_X:
if (node->touch.ind != 0 && node->touch.pending)
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 2b45b6e

Please sign in to comment.