Skip to content

Commit

Permalink
Hook up pressure and mt touch minor/major
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Jul 19, 2013
1 parent 36c3590 commit ae24ed4
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion tools/mtview.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ struct touch_info {
int ntouches;
struct touch_data touches[DIM_TOUCH];
int current_slot;

/* XI2 axis mapping */
int pressure_valuator;
int mt_major_valuator;
int mt_minor_valuator;
};

struct windata {
Expand Down Expand Up @@ -121,6 +126,11 @@ static inline float max(float a, float b)
return b > a ? b : a;
}

static inline float min(float a, float b)
{
return b < a ? b : a;
}

static struct color new_color(struct windata *w)
{
struct color c;
Expand Down Expand Up @@ -587,12 +597,16 @@ static int scan_devices_xi2(void)
static int init_device(Display *dpy, int deviceid, struct touch_info *ti) {
XIDeviceInfo *info;
int ndevices, i;
Atom pressure, mt_major, mt_minor;

info = XIQueryDevice(dpy, deviceid, &ndevices);
if (!info || ndevices == 0) {
error("Failed to open device\n");
return -1;
}
pressure = XInternAtom(dpy, "Abs Pressure", True);
mt_major = XInternAtom(dpy, "Abs MT Touch Major", True);
mt_minor = XInternAtom(dpy, "Abs MT Touch Minor", True);

for (i = 0; i < info->num_classes; i++) {
switch(info->classes[i]->type) {
Expand All @@ -613,6 +627,16 @@ static int init_device(Display *dpy, int deviceid, struct touch_info *ti) {
ti->miny = vi->min;
ti->maxy = vi->max;
}
if (vi->label == pressure) {
ti->has_pressure = 1;
ti->pressure_valuator = i;
} else if (vi->label == mt_major) {
ti->has_touch_major = 1;
ti->mt_major_valuator = i;
} else if (vi->label == mt_minor) {
ti->has_touch_minor = 1;
ti->mt_minor_valuator = i;
}
}
break;
}
Expand All @@ -630,7 +654,7 @@ 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;
int i, max_axnum;
static int next_slot;
XIDeviceEvent *ev;
XGetEventData(dpy, &e->xcookie);
Expand Down Expand Up @@ -666,6 +690,26 @@ static void handle_xi2_event(Display *dpy, XEvent *e, struct touch_info *ti)
if (ev->evtype == XI_TouchBegin)
ti->touches[i].data[ABS_MT_SLOT] = next_slot++;

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)
ti->touches[i].data[ABS_MT_PRESSURE] = (int)*v;
else if (i == ti->mt_major_valuator)
ti->touches[i].data[ABS_MT_TOUCH_MAJOR] = (int)*v;
else if (i == ti->mt_minor_valuator)
ti->touches[i].data[ABS_MT_TOUCH_MINOR] = (int)*v;

v++;
}
}

XFreeEventData(dpy, &e->xcookie);
}

Expand Down

0 comments on commit ae24ed4

Please sign in to comment.