Skip to content

Commit 349fd67

Browse files
bentissJiri Kosina
authored andcommitted
HID: multitouch: support T and C for win8 devices
Win8 input specification clarifies the X and Y sent by devices. It distincts the position where the user wants to Touch (T) from the center of the ellipsoide (C). This patch enable supports for this distinction in hid-multitouch. Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com> Reviewed-by: Henrik Rydberg <rydberg@euromail.se> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent afbcb04 commit 349fd67

1 file changed

Lines changed: 37 additions & 9 deletions

File tree

‎drivers/hid/hid-multitouch.c‎

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ MODULE_LICENSE("GPL");
5454
#define MT_QUIRK_NO_AREA (1 << 9)
5555

5656
struct mt_slot {
57-
__s32 x, y, p, w, h;
57+
__s32 x, y, cx, cy, p, w, h;
5858
__s32 contactid; /* the device ContactID assigned to this slot */
5959
bool touch_state; /* is the touch valid? */
6060
};
@@ -322,6 +322,7 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
322322
struct mt_device *td = hid_get_drvdata(hdev);
323323
struct mt_class *cls = &td->mtclass;
324324
int code;
325+
struct hid_usage *prev_usage = NULL;
325326

326327
/* Only map fields from TouchScreen or TouchPad collections.
327328
* We need to ignore fields that belong to other collections
@@ -344,23 +345,42 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
344345
if (field->physical == HID_DG_STYLUS)
345346
return -1;
346347

348+
if (usage->usage_index)
349+
prev_usage = &field->usage[usage->usage_index - 1];
350+
347351
switch (usage->hid & HID_USAGE_PAGE) {
348352

349353
case HID_UP_GENDESK:
350354
switch (usage->hid) {
351355
case HID_GD_X:
352-
hid_map_usage(hi, usage, bit, max,
356+
if (prev_usage && (prev_usage->hid == usage->hid)) {
357+
hid_map_usage(hi, usage, bit, max,
358+
EV_ABS, ABS_MT_TOOL_X);
359+
set_abs(hi->input, ABS_MT_TOOL_X, field,
360+
cls->sn_move);
361+
} else {
362+
hid_map_usage(hi, usage, bit, max,
353363
EV_ABS, ABS_MT_POSITION_X);
354-
set_abs(hi->input, ABS_MT_POSITION_X, field,
355-
cls->sn_move);
364+
set_abs(hi->input, ABS_MT_POSITION_X, field,
365+
cls->sn_move);
366+
}
367+
356368
mt_store_field(usage, td, hi);
357369
td->last_field_index = field->index;
358370
return 1;
359371
case HID_GD_Y:
360-
hid_map_usage(hi, usage, bit, max,
372+
if (prev_usage && (prev_usage->hid == usage->hid)) {
373+
hid_map_usage(hi, usage, bit, max,
374+
EV_ABS, ABS_MT_TOOL_Y);
375+
set_abs(hi->input, ABS_MT_TOOL_Y, field,
376+
cls->sn_move);
377+
} else {
378+
hid_map_usage(hi, usage, bit, max,
361379
EV_ABS, ABS_MT_POSITION_Y);
362-
set_abs(hi->input, ABS_MT_POSITION_Y, field,
363-
cls->sn_move);
380+
set_abs(hi->input, ABS_MT_POSITION_Y, field,
381+
cls->sn_move);
382+
}
383+
364384
mt_store_field(usage, td, hi);
365385
td->last_field_index = field->index;
366386
return 1;
@@ -501,6 +521,8 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input)
501521

502522
input_event(input, EV_ABS, ABS_MT_POSITION_X, s->x);
503523
input_event(input, EV_ABS, ABS_MT_POSITION_Y, s->y);
524+
input_event(input, EV_ABS, ABS_MT_TOOL_X, s->cx);
525+
input_event(input, EV_ABS, ABS_MT_TOOL_Y, s->cy);
504526
input_event(input, EV_ABS, ABS_MT_ORIENTATION, wide);
505527
input_event(input, EV_ABS, ABS_MT_PRESSURE, s->p);
506528
input_event(input, EV_ABS, ABS_MT_TOUCH_MAJOR, major);
@@ -552,10 +574,16 @@ static int mt_event(struct hid_device *hid, struct hid_field *field,
552574
td->curdata.p = value;
553575
break;
554576
case HID_GD_X:
555-
td->curdata.x = value;
577+
if (usage->code == ABS_MT_TOOL_X)
578+
td->curdata.cx = value;
579+
else
580+
td->curdata.x = value;
556581
break;
557582
case HID_GD_Y:
558-
td->curdata.y = value;
583+
if (usage->code == ABS_MT_TOOL_Y)
584+
td->curdata.cy = value;
585+
else
586+
td->curdata.y = value;
559587
break;
560588
case HID_DG_WIDTH:
561589
td->curdata.w = value;

0 commit comments

Comments
 (0)