From patchwork Wed Feb 17 17:22:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ahelenia_Ziemia=C5=84ska?= X-Patchwork-Id: 384117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 236F4C43381 for ; Wed, 17 Feb 2021 17:33:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC69564E4B for ; Wed, 17 Feb 2021 17:33:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234462AbhBQRc7 (ORCPT ); Wed, 17 Feb 2021 12:32:59 -0500 Received: from [139.28.40.42] ([139.28.40.42]:46858 "EHLO tarta.nabijaczleweli.xyz" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S233885AbhBQRcq (ORCPT ); Wed, 17 Feb 2021 12:32:46 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 3CCEE3601D2; Wed, 17 Feb 2021 18:22:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=nabijaczleweli.xyz; s=202006; t=1613582569; bh=ziY0iXdxwSWXFOzoXNDOFn5JohGhP3IMScquKcj790E=; h=Date:From:Cc:Subject:References:In-Reply-To:From; b=dBtD6W7ffddYH3UpRpeMSIBASbBvDE0f49x3J5KBtcCW6VsP4BcwMFuR6FL1oFJxa bqy4Kh7A5puaWJgQ8kP2TKCLApSB4rerNuVZ4gMfWmndAyFpk3d334E71H9rjJzRl5 kQWbdinoT448hsAqOqRcfuC3JfpZjslvphls0uDvUvLu5Mx/RVHjPqF4lqqnsDjrUb 2Qo/pEWxJ9ftZzVYC0HTmnGc+kfwQMV6SsCE236BBZA2i1yrD9Ze42LrOeMxjUtqfE 50x014EZIDuKlnOIH7k5GyTSo1HNe+F9IIeCSLXik4PDut/m/NHDuIIlfTTzkxhr8w ZhTU12bo9duHQ== Date: Wed, 17 Feb 2021 18:22:48 +0100 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= Cc: Benjamin Tissoires , Peter Hutterer , Jiri Kosina , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] HID: input: work around Win8 stylus-on-touchscreen reporting Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20210205 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org With this, these devices now behave as tablets as expected by userspace Signed-off-by: Ahelenia ZiemiaƄska --- drivers/hid/hid-input.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index a5ba92978473..b8813fc3e9d2 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -1273,6 +1273,41 @@ static void hidinput_handle_scroll(struct hid_usage *usage, input_event(input, EV_REL, usage->code, hi_res); } +/* + * Win8 tablet stylus devices send, in order: + * HID_DG_TIPSWITCH (BTN_TOUCH) + * HID_DG_INVERT (BTN_TOOL_RUBBER) + * HID_DG_ERASER (BTN_TOUCH) + * HID_DG_INRANGE (BTN_TOOL_PEN) + * + * For each of these states: + * hover : INRANGE + * touching : TIPSWITCH + * hover+2 : INVERT INRANGE + * touching+2: ERASER INRANGE + * + * Which means we'd send BTN_TOUCH=0 + BTN_TOOL_PEN=1 on proximity, + * then BTN_TOUCH=1 and BTN_TOOL_PEN=0 in consecutive groups when touched, + * indicating the stylus leaving the screen as soon as the two meet. + */ +static void hidinput_fixup_win8_inrange(struct hid_device *hid, struct hid_field *field, __s32 *value) +{ + unsigned f, u; + struct hid_field *rfield; + + if (!*value) { + for (f = 0; f < field->report->maxfield; ++f) { + rfield = field->report->field[f]; + for (u = 0; u < rfield->maxusage; ++u) { + if (rfield->usage[u].hid == HID_DG_TIPSWITCH) { + *value = rfield->value[u]; + return; + } + } + } + } +} + void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value) { struct input_dev *input; @@ -1306,7 +1341,13 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct return; } + if (usage->hid == HID_DG_ERASER && value) + *quirks |= HID_QUIRK_INVERT; + if (usage->hid == HID_DG_INRANGE) { + if (hid->group == HID_GROUP_MULTITOUCH_WIN_8) + hidinput_fixup_win8_inrange(hid, field, &value); + if (value) { input_event(input, usage->type, (*quirks & HID_QUIRK_INVERT) ? BTN_TOOL_RUBBER : usage->code, 1); return;