Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp380686imm; Fri, 1 Jun 2018 02:33:08 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJeJkokDOlm5xNrilh2L0FkZN6Hg3ECnWwbD+uJeTQ7i2hho2OkRCAon7ubseCIjzz0a2Uo X-Received: by 2002:a17:902:aa4b:: with SMTP id c11-v6mr10397208plr.17.1527845588310; Fri, 01 Jun 2018 02:33:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527845588; cv=none; d=google.com; s=arc-20160816; b=p8Z/GF/q3UTZfXEf1r5NQxdHJ+0RDadFWJ6BZMU27i2CoppnVarT/WTbuqXrYvZqmQ DNCy4D/GGJaD8U1PL4Zabefnn2z+klXSDt09mHQgFR9hLPzANxY2MNn1t0EWlLnGakmj sYsqgt0atSbsfu2q7QwaBIsGz+bNW2H17XUV/PPVoeRqYc9oAXzpH/GBvicnlCCuvEpI YKAOzxWxrR/Y50etUmqZ1MceUZ/mCI7/OHXLB8QgZ/hJMpfuTXJOKkgmpCA7EzRD3HI8 uKbBM1Fsf1W7SLwvrmPFDSjgGgiH6nWqjX3OjjpC1QNOd0V7ia6Fr3sO+zjM5kiLkw3T Tsxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:arc-authentication-results; bh=x0Bnhvi/dQxuAr47LpLE/BJ540/yy1jTgoUNuXVNfv4=; b=HQPEab4h4KShnY3LWvPT/nA2FACkXpFk1fD8W1IGGd/O8a1m9G2LL1DOqhqHwHAEav VgFqkxcAGXQ7FqHoHDUCSc0v78pj1BgxnviKNmgyvOSDRB/EDUIuDAH7Dx9i8yP2b6DP rFFZEQ+uaAw6q/kT/3hMI3tXVH8RF+or8o2ik+b/fc5+zXgUnQCylhA5mSzuvDg6/N8W aUqRDsT6mmQ4GeFsmtGUVkFEszvVyCycjrHA1PfloLGmZ6qZuNQ/mgxGfHxvxISPy5fV /zlCHAhZ7oYXnwNsde8Dmnopej0ygRQzWq3FnsBbPjlOoiNzTm3pgxxBZuHdbMxrw+vE 3SEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b15-v6si10371847pfc.320.2018.06.01.02.32.53; Fri, 01 Jun 2018 02:33:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750881AbeFAJbZ (ORCPT + 99 others); Fri, 1 Jun 2018 05:31:25 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:35741 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750740AbeFAJbU (ORCPT ); Fri, 1 Jun 2018 05:31:20 -0400 Received: by mail-qt0-f195.google.com with SMTP id s9-v6so1833486qtg.2 for ; Fri, 01 Jun 2018 02:31:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=x0Bnhvi/dQxuAr47LpLE/BJ540/yy1jTgoUNuXVNfv4=; b=jK24im47tVp08cQomR5O2M6px4nAvUKqa4k7TUX+Hk1xenQu+Yr4VbBUs8UQRti943 x6aBGUEfhWTxjb+aUmo3jz6tpYAWSh5PXWHe70CNbrw5+U6sU8eeBJ8HSPDhT+14ESYV 2vjs76iOKUUmsZ1Uu15nmLRnFNWPyXmt7gDXIS/kGTpI1DyrTalDTAe6GTjauQ7CvyC8 /btndrS7BpA4YqhN8IHCcU2GqFage76lhtElvuTUR6qsHAebaP0IC8YwG1ylmBnDCUQ3 R+ReOtz1ity27ELjqWG6REkZT9c0U3neB+szm6n2I1aEfHfg5yhQuZLtj9R99fb5+fjp 8H5w== X-Gm-Message-State: APt69E2dWpqX62hNVMXuAZE8kD7tvgfeno9s3yn0wT5QrbIHxSmWExNh mc/bo2/oNi02Cg596863E6cR15voOwBGk+dCmanixg== X-Received: by 2002:ac8:1bee:: with SMTP id m43-v6mr10006883qtk.339.1527845480292; Fri, 01 Jun 2018 02:31:20 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:aed:2bc7:0:0:0:0:0 with HTTP; Fri, 1 Jun 2018 02:31:19 -0700 (PDT) In-Reply-To: <20180530231208.GA19976@jelly> References: <20170811004500.13740-1-dmitry.torokhov@gmail.com> <20180530231208.GA19976@jelly> From: Benjamin Tissoires Date: Fri, 1 Jun 2018 11:31:19 +0200 Message-ID: Subject: Re: [PATCH 1/2] HID: multitouch: report MT_TOOL_PALM for non-confident touches To: Peter Hutterer Cc: Dmitry Torokhov , Jiri Kosina , Henrik Rydberg , Jason Gerecke , Dennis Kempin , Andrew de los Reyes , "open list:HID CORE LAYER" , lkml Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 31, 2018 at 1:12 AM, Peter Hutterer wrote: > Hi Dmitry, > > On Thu, Aug 10, 2017 at 05:44:59PM -0700, Dmitry Torokhov wrote: >> According to Microsoft specification [1] for Precision Touchpads (and >> Touchscreens) the devices use "confidence" reports to signal accidental >> touches, or contacts that are "too large to be a finger". Instead of >> simply marking contact inactive in this case (which causes issues if >> contact was originally proper and we lost confidence in it later, as >> this results in accidental clicks, drags, etc), let's report such >> contacts as MT_TOOL_PALM and let userspace decide what to do. >> Additionally, let's report contact size for such touches as maximum >> allowed for major/minor, which should help userspace that is not yet >> aware of MT_TOOL_PALM to still perform palm rejection. >> >> An additional complication, is that some firmwares do not report >> non-confident touches as active. To cope with this we delay release of >> such contact (i.e. if contact was active we first report it as still >> active MT+TOOL_PALM and then synthesize the release event in a separate >> frame). >> >> [1] https://docs.microsoft.com/en-us/windows-hardware/design/component-guidelines/touchpad-windows-precision-touchpad-collection >> >> Signed-off-by: Dmitry Torokhov > > This one popped up again in a bug report [1] and it looks like it never > got merged. fwiw, libinput does support ABS_MT_TOOL_PALM for touchpads as of > 1.8.0 and just releasing the touch causes fake taps. So you have the green > light from me to merge this :) > > Cheers, > Peter > > [1] https://bugs.freedesktop.org/show_bug.cgi?id=106716 I can probably integrate this one in the hid-multitouch revamp I am making, to avoid other the pain of rebasing. Cheers, Benjamin > >> --- >> drivers/hid/hid-multitouch.c | 86 +++++++++++++++++++++++++++++++++++++++----- >> 1 file changed, 77 insertions(+), 9 deletions(-) >> >> diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c >> index 440b999304a5..c28defe50a10 100644 >> --- a/drivers/hid/hid-multitouch.c >> +++ b/drivers/hid/hid-multitouch.c >> @@ -114,6 +114,8 @@ struct mt_device { >> struct timer_list release_timer; /* to release sticky fingers */ >> struct mt_fields *fields; /* temporary placeholder for storing the >> multitouch fields */ >> + unsigned long *pending_palm_slots; /* slots where we reported palm >> + and need to release */ >> unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */ >> int cc_index; /* contact count field index in the report */ >> int cc_value_index; /* contact count value index in the field */ >> @@ -543,8 +545,12 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, >> case HID_DG_CONFIDENCE: >> if ((cls->name == MT_CLS_WIN_8 || >> cls->name == MT_CLS_WIN_8_DUAL) && >> - field->application == HID_DG_TOUCHPAD) >> + field->application == HID_DG_TOUCHPAD) { >> cls->quirks |= MT_QUIRK_CONFIDENCE; >> + input_set_abs_params(hi->input, >> + ABS_MT_TOOL_TYPE, >> + MT_TOOL_FINGER, MT_TOOL_PALM, 0, 0); >> + } >> mt_store_field(usage, td, hi); >> return 1; >> case HID_DG_TIPSWITCH: >> @@ -657,6 +663,7 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input) >> >> if (td->curvalid || (td->mtclass.quirks & MT_QUIRK_ALWAYS_VALID)) { >> int active; >> + int tool; >> int slotnum = mt_compute_slot(td, input); >> struct mt_slot *s = &td->curdata; >> struct input_mt *mt = input->mt; >> @@ -671,24 +678,56 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input) >> return; >> } >> >> + active = s->touch_state || s->inrange_state; >> + >> if (!(td->mtclass.quirks & MT_QUIRK_CONFIDENCE)) >> s->confidence_state = 1; >> - active = (s->touch_state || s->inrange_state) && >> - s->confidence_state; >> + >> + if (likely(s->confidence_state)) { >> + tool = MT_TOOL_FINGER; >> + } else { >> + tool = MT_TOOL_PALM; >> + if (!active && >> + input_mt_is_active(&mt->slots[slotnum])) { >> + /* >> + * The non-confidence was reported for >> + * previously valid contact that is also no >> + * longer valid. We can't simply report >> + * lift-off as userspace will not be aware >> + * of non-confidence, so we need to split >> + * it into 2 events: active MT_TOOL_PALM >> + * and a separate liftoff. >> + */ >> + active = true; >> + set_bit(slotnum, td->pending_palm_slots); >> + } >> + } >> >> input_mt_slot(input, slotnum); >> - input_mt_report_slot_state(input, MT_TOOL_FINGER, active); >> + input_mt_report_slot_state(input, tool, active); >> if (active) { >> /* this finger is in proximity of the sensor */ >> int wide = (s->w > s->h); >> int major = max(s->w, s->h); >> int minor = min(s->w, s->h); >> >> - /* >> - * divided by two to match visual scale of touch >> - * for devices with this quirk >> - */ >> - if (td->mtclass.quirks & MT_QUIRK_TOUCH_SIZE_SCALING) { >> + if (unlikely(!s->confidence_state)) { >> + /* >> + * When reporting palm, set contact to maximum >> + * size to help userspace that does not >> + * recognize MT_TOOL_PALM to reject contacts >> + * that are too large. >> + */ >> + major = input_abs_get_max(input, >> + ABS_MT_TOUCH_MAJOR); >> + minor = input_abs_get_max(input, >> + ABS_MT_TOUCH_MINOR); >> + } else if (td->mtclass.quirks & >> + MT_QUIRK_TOUCH_SIZE_SCALING) { >> + /* >> + * divided by two to match visual scale of touch >> + * for devices with this quirk >> + */ >> major = major >> 1; >> minor = minor >> 1; >> } >> @@ -711,6 +750,25 @@ static void mt_complete_slot(struct mt_device *td, struct input_dev *input) >> td->num_received++; >> } >> >> +static void mt_release_pending_palms(struct mt_device *td, >> + struct input_dev *input) >> +{ >> + int slotnum; >> + bool need_sync = false; >> + >> + for_each_set_bit(slotnum, td->pending_palm_slots, td->maxcontacts) { >> + clear_bit(slotnum, td->pending_palm_slots); >> + >> + input_mt_slot(input, slotnum); >> + input_mt_report_slot_state(input, MT_TOOL_PALM, false); >> + >> + need_sync = true; >> + } >> + >> + if (need_sync) >> + input_sync(input); >> +} >> + >> /* >> * this function is called when a whole packet has been received and processed, >> * so that it can decide what to send to the input layer. >> @@ -719,6 +777,9 @@ static void mt_sync_frame(struct mt_device *td, struct input_dev *input) >> { >> input_mt_sync_frame(input); >> input_sync(input); >> + >> + mt_release_pending_palms(td, input); >> + >> td->num_received = 0; >> if (test_bit(MT_IO_FLAGS_ACTIVE_SLOTS, &td->mt_io_flags)) >> set_bit(MT_IO_FLAGS_PENDING_SLOTS, &td->mt_io_flags); >> @@ -903,6 +964,13 @@ static int mt_touch_input_configured(struct hid_device *hdev, >> if (td->is_buttonpad) >> __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); >> >> + td->pending_palm_slots = devm_kcalloc(&hi->input->dev, >> + BITS_TO_LONGS(td->maxcontacts), >> + sizeof(long), >> + GFP_KERNEL); >> + if (!td->pending_palm_slots) >> + return -ENOMEM; >> + >> ret = input_mt_init_slots(input, td->maxcontacts, td->mt_flags); >> if (ret) >> return ret; >> -- >> 2.14.0.434.g98096fd7a8-goog >> >> -- >> To unsubscribe from this list: send the line "unsubscribe linux-input" in >> the body of a message to majordomo@vger.kernel.org >> More majordomo info at http://vger.kernel.org/majordomo-info.html >>