From owner-dev-commits-src-branches@freebsd.org Wed Sep 8 00:02:28 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 49D46670390; Wed, 8 Sep 2021 00:02:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H42Pt6x2Rz4Wdr; Wed, 8 Sep 2021 00:02:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 90EA21C025; Wed, 8 Sep 2021 00:02:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 18802Q29050311; Wed, 8 Sep 2021 00:02:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 18802Q1s050310; Wed, 8 Sep 2021 00:02:26 GMT (envelope-from git) Date: Wed, 8 Sep 2021 00:02:26 GMT Message-Id: <202109080002.18802Q1s050310@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Vladimir Kondratyev Subject: git: de6d60ee1c86 - stable/13 - evdev: Normalize width and pressure of single touch compat events MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: de6d60ee1c86054563f4ff9eceaf988403d8b56c Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2021 00:02:28 -0000 The branch stable/13 has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=de6d60ee1c86054563f4ff9eceaf988403d8b56c commit de6d60ee1c86054563f4ff9eceaf988403d8b56c Author: Vladimir Kondratyev AuthorDate: 2021-08-24 22:46:49 +0000 Commit: Vladimir Kondratyev CommitDate: 2021-09-07 23:57:57 +0000 evdev: Normalize width and pressure of single touch compat events to match Synaptics touchpad reporting range. (cherry picked from commit 127e54deb6d8899e1dc1bc6251d512e19f21b0f1) --- sys/dev/evdev/evdev_mt.c | 67 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 18 deletions(-) diff --git a/sys/dev/evdev/evdev_mt.c b/sys/dev/evdev/evdev_mt.c index 0b5d2cb6bb85..a3600e837960 100644 --- a/sys/dev/evdev/evdev_mt.c +++ b/sys/dev/evdev/evdev_mt.c @@ -49,11 +49,15 @@ _Static_assert(MAX_MT_SLOTS < sizeof(slotset_t) * 8, "MAX_MT_SLOTS too big"); #define FOREACHBIT(v, i) \ for ((i) = ffs(v) - 1; (i) != -1; (i) = ffs((v) & (~1 << (i))) - 1) -static uint16_t evdev_mtstmap[][2] = { - { ABS_MT_POSITION_X, ABS_X }, - { ABS_MT_POSITION_Y, ABS_Y }, - { ABS_MT_PRESSURE, ABS_PRESSURE }, - { ABS_MT_TOUCH_MAJOR, ABS_TOOL_WIDTH }, +struct { + uint16_t mt; + uint16_t st; + int32_t max; +} static evdev_mtstmap[] = { + { ABS_MT_POSITION_X, ABS_X, 0 }, + { ABS_MT_POSITION_Y, ABS_Y, 0 }, + { ABS_MT_PRESSURE, ABS_PRESSURE, 255 }, + { ABS_MT_TOUCH_MAJOR, ABS_TOOL_WIDTH, 15 }, }; struct evdev_mt_slot { @@ -62,6 +66,7 @@ struct evdev_mt_slot { struct evdev_mt { int last_reported_slot; + u_int mtst_events; /* the set of slots with active touches */ slotset_t touches; /* the set of slots with unsynchronized state */ @@ -175,9 +180,20 @@ evdev_get_mt_slot_by_tracking_id(struct evdev_dev *evdev, int32_t tracking_id) return (ffc_slot(evdev, mt->touches | mt->frame)); } +static inline int32_t +evdev_mt_normalize(int32_t value, int32_t mtmin, int32_t mtmax, int32_t stmax) +{ + if (stmax != 0 && mtmax != mtmin) { + value = (value - mtmin) * stmax / (mtmax - mtmin); + value = MAX(MIN(value, stmax), 0); + } + return (value); +} + void evdev_support_mt_compat(struct evdev_dev *evdev) { + struct input_absinfo *ai; int i; if (evdev->ev_absinfo == NULL) @@ -191,14 +207,28 @@ evdev_support_mt_compat(struct evdev_dev *evdev) evdev_support_nfingers(evdev, MAXIMAL_MT_SLOT(evdev) + 1); /* Echo 0-th MT-slot as ST-slot */ - for (i = 0; i < nitems(evdev_mtstmap); i++) - if (bit_test(evdev->ev_abs_flags, evdev_mtstmap[i][0])) - evdev_support_abs(evdev, evdev_mtstmap[i][1], - evdev->ev_absinfo[evdev_mtstmap[i][0]].minimum, - evdev->ev_absinfo[evdev_mtstmap[i][0]].maximum, + for (i = 0; i < nitems(evdev_mtstmap); i++) { + if (!bit_test(evdev->ev_abs_flags, evdev_mtstmap[i].mt) || + bit_test(evdev->ev_abs_flags, evdev_mtstmap[i].st)) + continue; + ai = evdev->ev_absinfo + evdev_mtstmap[i].mt; + evdev->ev_mt->mtst_events |= 1U << i; + if (evdev_mtstmap[i].max != 0) + evdev_support_abs(evdev, evdev_mtstmap[i].st, 0, - evdev->ev_absinfo[evdev_mtstmap[i][0]].flat, - evdev->ev_absinfo[evdev_mtstmap[i][0]].resolution); + evdev_mtstmap[i].max, + 0, + evdev_mt_normalize( + ai->flat, 0, ai->maximum, evdev_mtstmap[i].max), + 0); + else + evdev_support_abs(evdev, evdev_mtstmap[i].st, + ai->minimum, + ai->maximum, + 0, + ai->flat, + ai->resolution); + } } static void @@ -215,12 +245,13 @@ evdev_mt_send_st_compat(struct evdev_dev *evdev) /* Send first active MT-slot state as single touch report */ st_slot = ffs(mt->touches) - 1; if (st_slot != -1) - for (i = 0; i < nitems(evdev_mtstmap); i++) - if (bit_test(evdev->ev_abs_flags, evdev_mtstmap[i][1])) - evdev_send_event(evdev, EV_ABS, - evdev_mtstmap[i][1], - evdev_mt_get_value(evdev, st_slot, - evdev_mtstmap[i][0])); + FOREACHBIT(mt->mtst_events, i) + evdev_send_event(evdev, EV_ABS, evdev_mtstmap[i].st, + evdev_mt_normalize(evdev_mt_get_value(evdev, + st_slot, evdev_mtstmap[i].mt), + evdev->ev_absinfo[evdev_mtstmap[i].mt].minimum, + evdev->ev_absinfo[evdev_mtstmap[i].mt].maximum, + evdev_mtstmap[i].max)); /* Touchscreens should not report tool taps */ if (!bit_test(evdev->ev_prop_flags, INPUT_PROP_DIRECT))