Commit 601a22f3 authored by Jason Gerecke's avatar Jason Gerecke Committed by Jiri Kosina

HID: wacom: Report input events for each finger on generic devices

The existing generic touch code only reports events after reading an
entire HID report, which practically means that only data about the last
contact in a report will ever be provided to userspace. This patch uses
a trick from hid-multitouch.c to discover what type of field is at the
end of each contact; when such a field is encountered all the stored
contact data will be reported.
Signed-off-by: default avatarJason Gerecke <killertofu@gmail.com>
Reviewed-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent b58ba1ba
...@@ -1381,10 +1381,12 @@ static void wacom_wac_finger_usage_mapping(struct hid_device *hdev, ...@@ -1381,10 +1381,12 @@ static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
{ {
struct wacom *wacom = hid_get_drvdata(hdev); struct wacom *wacom = hid_get_drvdata(hdev);
struct wacom_wac *wacom_wac = &wacom->wacom_wac; struct wacom_wac *wacom_wac = &wacom->wacom_wac;
struct wacom_features *features = &wacom_wac->features;
unsigned touch_max = wacom_wac->features.touch_max; unsigned touch_max = wacom_wac->features.touch_max;
switch (usage->hid) { switch (usage->hid) {
case HID_GD_X: case HID_GD_X:
features->last_slot_field = usage->hid;
if (touch_max == 1) if (touch_max == 1)
wacom_map_usage(wacom, usage, field, EV_ABS, ABS_X, 4); wacom_map_usage(wacom, usage, field, EV_ABS, ABS_X, 4);
else else
...@@ -1392,6 +1394,7 @@ static void wacom_wac_finger_usage_mapping(struct hid_device *hdev, ...@@ -1392,6 +1394,7 @@ static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
ABS_MT_POSITION_X, 4); ABS_MT_POSITION_X, 4);
break; break;
case HID_GD_Y: case HID_GD_Y:
features->last_slot_field = usage->hid;
if (touch_max == 1) if (touch_max == 1)
wacom_map_usage(wacom, usage, field, EV_ABS, ABS_Y, 4); wacom_map_usage(wacom, usage, field, EV_ABS, ABS_Y, 4);
else else
...@@ -1399,17 +1402,48 @@ static void wacom_wac_finger_usage_mapping(struct hid_device *hdev, ...@@ -1399,17 +1402,48 @@ static void wacom_wac_finger_usage_mapping(struct hid_device *hdev,
ABS_MT_POSITION_Y, 4); ABS_MT_POSITION_Y, 4);
break; break;
case HID_DG_CONTACTID: case HID_DG_CONTACTID:
features->last_slot_field = usage->hid;
break; break;
case HID_DG_INRANGE: case HID_DG_INRANGE:
features->last_slot_field = usage->hid;
break; break;
case HID_DG_INVERT: case HID_DG_INVERT:
features->last_slot_field = usage->hid;
break; break;
case HID_DG_TIPSWITCH: case HID_DG_TIPSWITCH:
features->last_slot_field = usage->hid;
wacom_map_usage(wacom, usage, field, EV_KEY, BTN_TOUCH, 0); wacom_map_usage(wacom, usage, field, EV_KEY, BTN_TOUCH, 0);
break; break;
} }
} }
static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac,
struct input_dev *input)
{
struct hid_data *hid_data = &wacom_wac->hid_data;
bool mt = wacom_wac->features.touch_max > 1;
bool prox = hid_data->tipswitch &&
!wacom_wac->shared->stylus_in_proximity;
if (mt) {
int slot;
slot = input_mt_get_slot_by_key(input, hid_data->id);
input_mt_slot(input, slot);
input_mt_report_slot_state(input, MT_TOOL_FINGER, prox);
}
else {
input_report_key(input, BTN_TOUCH, prox);
}
if (prox) {
input_report_abs(input, mt ? ABS_MT_POSITION_X : ABS_X,
hid_data->x);
input_report_abs(input, mt ? ABS_MT_POSITION_Y : ABS_Y,
hid_data->y);
}
}
static int wacom_wac_finger_event(struct hid_device *hdev, static int wacom_wac_finger_event(struct hid_device *hdev,
struct hid_field *field, struct hid_usage *usage, __s32 value) struct hid_field *field, struct hid_usage *usage, __s32 value)
{ {
...@@ -1432,36 +1466,35 @@ static int wacom_wac_finger_event(struct hid_device *hdev, ...@@ -1432,36 +1466,35 @@ static int wacom_wac_finger_event(struct hid_device *hdev,
} }
if (usage->usage_index + 1 == field->report_count) {
if (usage->hid == wacom_wac->features.last_slot_field)
wacom_wac_finger_slot(wacom_wac, wacom_wac->input);
}
return 0; return 0;
} }
static void wacom_wac_finger_mt_report(struct wacom_wac *wacom_wac, static int wacom_wac_finger_count_touches(struct hid_device *hdev)
struct input_dev *input, bool touch)
{ {
int slot; struct wacom *wacom = hid_get_drvdata(hdev);
struct hid_data *hid_data = &wacom_wac->hid_data; struct wacom_wac *wacom_wac = &wacom->wacom_wac;
struct input_dev *input = wacom_wac->input;
unsigned touch_max = wacom_wac->features.touch_max;
int count = 0;
int i;
slot = input_mt_get_slot_by_key(input, hid_data->id); if (touch_max == 1)
return wacom_wac->hid_data.tipswitch &&
!wacom_wac->shared->stylus_in_proximity;
input_mt_slot(input, slot); for (i = 0; i < input->mt->num_slots; i++) {
input_mt_report_slot_state(input, MT_TOOL_FINGER, touch); struct input_mt_slot *ps = &input->mt->slots[i];
if (touch) { int id = input_mt_get_value(ps, ABS_MT_TRACKING_ID);
input_report_abs(input, ABS_MT_POSITION_X, hid_data->x); if (id >= 0)
input_report_abs(input, ABS_MT_POSITION_Y, hid_data->y); count++;
} }
input_mt_sync_frame(input);
}
static void wacom_wac_finger_single_touch_report(struct wacom_wac *wacom_wac,
struct input_dev *input, bool touch)
{
struct hid_data *hid_data = &wacom_wac->hid_data;
if (touch) { return count;
input_report_abs(input, ABS_X, hid_data->x);
input_report_abs(input, ABS_Y, hid_data->y);
}
input_report_key(input, BTN_TOUCH, touch);
} }
static void wacom_wac_finger_report(struct hid_device *hdev, static void wacom_wac_finger_report(struct hid_device *hdev,
...@@ -1470,18 +1503,15 @@ static void wacom_wac_finger_report(struct hid_device *hdev, ...@@ -1470,18 +1503,15 @@ static void wacom_wac_finger_report(struct hid_device *hdev,
struct wacom *wacom = hid_get_drvdata(hdev); struct wacom *wacom = hid_get_drvdata(hdev);
struct wacom_wac *wacom_wac = &wacom->wacom_wac; struct wacom_wac *wacom_wac = &wacom->wacom_wac;
struct input_dev *input = wacom_wac->input; struct input_dev *input = wacom_wac->input;
bool touch = wacom_wac->hid_data.tipswitch &&
!wacom_wac->shared->stylus_in_proximity;
unsigned touch_max = wacom_wac->features.touch_max; unsigned touch_max = wacom_wac->features.touch_max;
if (touch_max > 1) if (touch_max > 1)
wacom_wac_finger_mt_report(wacom_wac, input, touch); input_mt_sync_frame(input);
else
wacom_wac_finger_single_touch_report(wacom_wac, input, touch);
input_sync(input); input_sync(input);
/* keep touch state for pen event */ /* keep touch state for pen event */
wacom_wac->shared->touch_down = touch; wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(hdev);
} }
#define WACOM_PEN_FIELD(f) (((f)->logical == HID_DG_STYLUS) || \ #define WACOM_PEN_FIELD(f) (((f)->logical == HID_DG_STYLUS) || \
......
...@@ -145,6 +145,7 @@ struct wacom_features { ...@@ -145,6 +145,7 @@ struct wacom_features {
int pktlen; int pktlen;
bool check_for_hid_type; bool check_for_hid_type;
int hid_type; int hid_type;
int last_slot_field;
}; };
struct wacom_shared { struct wacom_shared {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment