From owner-dev-commits-src-main@freebsd.org Thu Sep 9 21:41:45 2021 Return-Path: Delivered-To: dev-commits-src-main@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 C7FD96773DF; Thu, 9 Sep 2021 21:41:45 +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 4H5CBd4CRCz3GPY; Thu, 9 Sep 2021 21:41:45 +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 6ED1620D35; Thu, 9 Sep 2021 21:41:45 +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 189LfjsE016288; Thu, 9 Sep 2021 21:41:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 189Lfj5O016287; Thu, 9 Sep 2021 21:41:45 GMT (envelope-from git) Date: Thu, 9 Sep 2021 21:41:45 GMT Message-Id: <202109092141.189Lfj5O016287@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 598f0580f682 - main - hkbd(4): Fix key repeats on multireport keyboards 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/main X-Git-Reftype: branch X-Git-Commit: 598f0580f6822e2492231d055f49465a5b55d270 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Sep 2021 21:41:46 -0000 The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=598f0580f6822e2492231d055f49465a5b55d270 commit 598f0580f6822e2492231d055f49465a5b55d270 Author: Vladimir Kondratyev AuthorDate: 2021-09-09 21:40:13 +0000 Commit: Vladimir Kondratyev CommitDate: 2021-09-09 21:40:13 +0000 hkbd(4): Fix key repeats on multireport keyboards Currently hkbd counts all key states to be "Up" at the start of interrupt callback. That results in generation of "Key Up" event for each key that has been downed before but is not listed in current report while is still downed. Fix that with clearing of temporary key data storage bits only for keys contained in processed report. Reported by: Greg V Obtained from: sysutils/iichid MFC after: 2 weeks --- sys/dev/hid/hkbd.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sys/dev/hid/hkbd.c b/sys/dev/hid/hkbd.c index 65e8b9446e9d..bfd8e12df746 100644 --- a/sys/dev/hid/hkbd.c +++ b/sys/dev/hid/hkbd.c @@ -143,8 +143,12 @@ struct hkbd_softc { struct mtx sc_mtx; struct task sc_task; struct callout sc_callout; + /* All reported keycodes */ bitstr_t bit_decl(sc_ndata, HKBD_NKEYCODE); bitstr_t bit_decl(sc_odata, HKBD_NKEYCODE); + /* Keycodes reported in array fields only */ + bitstr_t bit_decl(sc_ndata0, HKBD_NKEYCODE); + bitstr_t bit_decl(sc_odata0, HKBD_NKEYCODE); struct thread *sc_poll_thread; #ifdef EVDEV_SUPPORT @@ -520,6 +524,7 @@ hkbd_interrupt(struct hkbd_softc *sc) } /* synchronize old data with new data */ + memcpy(sc->sc_odata0, sc->sc_ndata0, bitstr_size(HKBD_NKEYCODE)); memcpy(sc->sc_odata, sc->sc_ndata, bitstr_size(HKBD_NKEYCODE)); /* check if last key is still pressed */ @@ -654,7 +659,14 @@ hkbd_intr_callback(void *context, void *data, hid_size_t len) } /* clear temporary storage */ - memset(&sc->sc_ndata, 0, bitstr_size(HKBD_NKEYCODE)); + if (bit_test(sc->sc_loc_key_valid, 0) && id == sc->sc_id_loc_key[0]) { + bit_foreach(sc->sc_ndata0, HKBD_NKEYCODE, i) + bit_clear(sc->sc_ndata, i); + memset(&sc->sc_ndata0, 0, bitstr_size(HKBD_NKEYCODE)); + } + bit_foreach(sc->sc_ndata, HKBD_NKEYCODE, i) + if (id == sc->sc_id_loc_key[i]) + bit_clear(sc->sc_ndata, i); /* clear modifiers */ modifiers = 0; @@ -686,6 +698,8 @@ hkbd_intr_callback(void *context, void *data, hid_size_t len) tmp_loc.pos += tmp_loc.size; if (key == KEY_ERROR) { DPRINTF("KEY_ERROR\n"); + memcpy(sc->sc_ndata0, sc->sc_odata0, + bitstr_size(HKBD_NKEYCODE)); memcpy(sc->sc_ndata, sc->sc_odata, bitstr_size(HKBD_NKEYCODE)); return; /* ignore */ @@ -698,6 +712,7 @@ hkbd_intr_callback(void *context, void *data, hid_size_t len) continue; /* set key in bitmap */ bit_set(sc->sc_ndata, key); + bit_set(sc->sc_ndata0, key); } } else if (hid_get_data(buf, len, &sc->sc_loc_key[i])) { uint32_t key = i; @@ -1684,6 +1699,8 @@ hkbd_clear_state(keyboard_t *kbd) #endif memset(&sc->sc_ndata, 0, bitstr_size(HKBD_NKEYCODE)); memset(&sc->sc_odata, 0, bitstr_size(HKBD_NKEYCODE)); + memset(&sc->sc_ndata0, 0, bitstr_size(HKBD_NKEYCODE)); + memset(&sc->sc_odata0, 0, bitstr_size(HKBD_NKEYCODE)); sc->sc_repeat_time = 0; sc->sc_repeat_key = 0; }