Skip to content

Commit

Permalink
Get XI2 X and Y axes from valuators, not root
Browse files Browse the repository at this point in the history
The root value is not in device space, which causes the re-mapping
done in the output function to no longer map up 1:1 with what is
on-screen. We can either pre-scale the root values or grab them
from the valuators to fix this; this patch goes with the latter.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
jigpu authored and whot committed May 15, 2014
1 parent f62e306 commit aa2ee2f
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions tools/mtview.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ struct touch_info {
int current_slot;

/* XI2 axis mapping */
int x_valuator;
int y_valuator;
int pressure_valuator;
int mt_major_valuator;
int mt_minor_valuator;
Expand Down Expand Up @@ -627,9 +629,11 @@ static int init_device(Display *dpy, int deviceid, struct touch_info *ti) {
if (vi->number == 0) {
ti->minx = vi->min;
ti->maxx = vi->max;
ti->x_valuator = vi->number;
} else if (vi->number == 1) {
ti->miny = vi->min;
ti->maxy = vi->max;
ti->y_valuator = vi->number;
}
if (vi->label == pressure) {
ti->has_pressure = 1;
Expand Down Expand Up @@ -663,7 +667,8 @@ static int init_device(Display *dpy, int deviceid, struct touch_info *ti) {

static void handle_xi2_event(Display *dpy, XEvent *e, struct touch_info *ti)
{
int i, max_axnum;
int i;
double *v;
struct touch_data *touch = NULL;
XIDeviceEvent *ev;
XGetEventData(dpy, &e->xcookie);
Expand Down Expand Up @@ -705,23 +710,22 @@ static void handle_xi2_event(Display *dpy, XEvent *e, struct touch_info *ti)
touch->data[ABS_MT_POSITION_Y] = ev->root_y;
touch->data[ABS_MT_TRACKING_ID] = ev->detail;

max_axnum = max(ti->pressure_valuator, max(ti->mt_minor_valuator, ti->mt_major_valuator));
max_axnum = min(max_axnum, ev->valuators.mask_len);

if ((ti->has_pressure || ti->has_touch_major || ti->has_touch_minor)) {
double *v = ev->valuators.values;
for (i = 0; i <= max_axnum; i++) {
if (!XIMaskIsSet(ev->valuators.mask, i))
continue;
if (i == ti->pressure_valuator)
touch->data[ABS_MT_PRESSURE] = (int)*v;
else if (i == ti->mt_major_valuator)
touch->data[ABS_MT_TOUCH_MAJOR] = (int)*v;
else if (i == ti->mt_minor_valuator)
touch->data[ABS_MT_TOUCH_MINOR] = (int)*v;

v++;
}
v = ev->valuators.values;
for (i = 0; i <= ev->valuators.mask_len; i++) {
if (!XIMaskIsSet(ev->valuators.mask, i))
continue;
if (i == ti->x_valuator)
touch->data[ABS_MT_POSITION_X] = (int)*v;
else if (i == ti->y_valuator)
touch->data[ABS_MT_POSITION_Y] = (int)*v;
else if (i == ti->pressure_valuator)
touch->data[ABS_MT_PRESSURE] = (int)*v;
else if (i == ti->mt_major_valuator)
touch->data[ABS_MT_TOUCH_MAJOR] = (int)*v;
else if (i == ti->mt_minor_valuator)
touch->data[ABS_MT_TOUCH_MINOR] = (int)*v;

v++;
}

XFreeEventData(dpy, &e->xcookie);
Expand Down

0 comments on commit aa2ee2f

Please sign in to comment.