aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/drivers/hid
diff options
context:
space:
mode:
authorBenjamin Tissoires <benjamin.tissoires@redhat.com>2022-02-03 15:32:24 +0100
committerJiri Kosina <jkosina@suse.cz>2022-03-01 15:46:03 +0100
commit87562fcd134214a68e58d0714b820f2f2da75b1f (patch)
treea6b96cf1ded766a48812c979d2370a79d388b6be /drivers/hid
parentHID: input: enforce Invert usage to be processed before InRange (diff)
downloadwireguard-linux-87562fcd134214a68e58d0714b820f2f2da75b1f.tar.xz
wireguard-linux-87562fcd134214a68e58d0714b820f2f2da75b1f.zip
HID: input: remove the need for HID_QUIRK_INVERT
HID_QUIRK_INVERT is kind of complex to deal with and was bogus. Furthermore, it didn't make sense to use a global per struct hid_device quirk for something dynamic as the current state. Store the current tool information in the report itself, and re-order the processing of the fields to enforce having all the tablet "state" fields before getting to In Range and other input fields. This way, we now have all the information whether a tool is present or not while processing In Range. This new behavior enforces that only one tool gets forwarded to userspace at the same time, and that if either eraser or invert is set, we enforce BTN_TOOL_RUBBER. Note that the release of the previous tool now happens in its own EV_SYN report so userspace doesn't get confused by having 2 tools. These changes are tested in the following hid-tools regression tests: https://gitlab.freedesktop.org/libevdev/hid-tools/-/merge_requests/127 Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Reviewed-by: Ping Cheng <ping.cheng@wacom.com> Acked-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid')
-rw-r--r--drivers/hid/hid-input.c98
1 files changed, 90 insertions, 8 deletions
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 61d91117f4ae..9f8853640648 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -63,8 +63,11 @@ static const struct {
* This still leaves us 65535 individual priority values.
*/
static const __u32 hidinput_usages_priorities[] = {
+ HID_DG_ERASER, /* Eraser (eraser touching) must always come before tipswitch */
HID_DG_INVERT, /* Invert must always come before In Range */
- HID_DG_INRANGE,
+ HID_DG_TIPSWITCH, /* Is the tip of the tool touching? */
+ HID_DG_TIPPRESSURE, /* Tip Pressure might emulate tip switch */
+ HID_DG_INRANGE, /* In Range needs to come after the other tool states */
};
#define map_abs(c) hid_map_usage(hidinput, usage, &bit, &max, EV_ABS, (c))
@@ -1365,9 +1368,38 @@ static void hidinput_handle_scroll(struct hid_usage *usage,
input_event(input, EV_REL, usage->code, hi_res);
}
+static void hid_report_release_tool(struct hid_report *report, struct input_dev *input,
+ unsigned int tool)
+{
+ /* if the given tool is not currently reported, ignore */
+ if (!test_bit(tool, input->key))
+ return;
+
+ /*
+ * if the given tool was previously set, release it,
+ * release any TOUCH and send an EV_SYN
+ */
+ input_event(input, EV_KEY, BTN_TOUCH, 0);
+ input_event(input, EV_KEY, tool, 0);
+ input_event(input, EV_SYN, SYN_REPORT, 0);
+
+ report->tool = 0;
+}
+
+static void hid_report_set_tool(struct hid_report *report, struct input_dev *input,
+ unsigned int new_tool)
+{
+ if (report->tool != new_tool)
+ hid_report_release_tool(report, input, report->tool);
+
+ input_event(input, EV_KEY, new_tool, 1);
+ report->tool = new_tool;
+}
+
void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)
{
struct input_dev *input;
+ struct hid_report *report = field->report;
unsigned *quirks = &hid->quirks;
if (!usage->type)
@@ -1418,25 +1450,75 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
}
switch (usage->hid) {
+ case HID_DG_ERASER:
+ report->tool_active |= !!value;
+
+ /*
+ * if eraser is set, we must enforce BTN_TOOL_RUBBER
+ * to accommodate for devices not following the spec.
+ */
+ if (value)
+ hid_report_set_tool(report, input, BTN_TOOL_RUBBER);
+ else if (report->tool != BTN_TOOL_RUBBER)
+ /* value is off, tool is not rubber, ignore */
+ return;
+
+ /* let hid-input set BTN_TOUCH */
+ break;
+
case HID_DG_INVERT:
- *quirks = value ? (*quirks | HID_QUIRK_INVERT) : (*quirks & ~HID_QUIRK_INVERT);
+ report->tool_active |= !!value;
+
+ /*
+ * If invert is set, we store BTN_TOOL_RUBBER.
+ */
+ if (value)
+ hid_report_set_tool(report, input, BTN_TOOL_RUBBER);
+ else if (!report->tool_active)
+ /* tool_active not set means Invert and Eraser are not set */
+ hid_report_release_tool(report, input, BTN_TOOL_RUBBER);
+
+ /* no further processing */
return;
case HID_DG_INRANGE:
- if (value) {
- input_event(input, usage->type, (*quirks & HID_QUIRK_INVERT) ? BTN_TOOL_RUBBER : usage->code, 1);
- return;
+ report->tool_active |= !!value;
+
+ if (report->tool_active) {
+ /*
+ * if tool is not set but is marked as active,
+ * assume ours
+ */
+ if (!report->tool)
+ hid_report_set_tool(report, input, usage->code);
+ } else {
+ hid_report_release_tool(report, input, usage->code);
}
- input_event(input, usage->type, usage->code, 0);
- input_event(input, usage->type, BTN_TOOL_RUBBER, 0);
+
+ /* reset tool_active for the next event */
+ report->tool_active = false;
+
+ /* no further processing */
return;
+ case HID_DG_TIPSWITCH:
+ report->tool_active |= !!value;
+
+ /* if tool is set to RUBBER we should ignore the current value */
+ if (report->tool == BTN_TOOL_RUBBER)
+ return;
+
+ break;
+
case HID_DG_TIPPRESSURE:
if (*quirks & HID_QUIRK_NOTOUCH) {
int a = field->logical_minimum;
int b = field->logical_maximum;
- input_event(input, EV_KEY, BTN_TOUCH, value > a + ((b - a) >> 3));
+ if (value > a + ((b - a) >> 3)) {
+ input_event(input, EV_KEY, BTN_TOUCH, 1);
+ report->tool_active = true;
+ }
}
break;