From nobody Mon Feb 9 04:14:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1545221759640900.7424881243293; Wed, 19 Dec 2018 04:15:59 -0800 (PST) Received: from localhost ([::1]:59689 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZala-0000HW-3o for importer@patchew.org; Wed, 19 Dec 2018 07:15:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZafC-0003Ju-DE for qemu-devel@nongnu.org; Wed, 19 Dec 2018 07:09:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZafA-0000G5-6x for qemu-devel@nongnu.org; Wed, 19 Dec 2018 07:09:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40724) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gZaf6-0000Aa-Eg for qemu-devel@nongnu.org; Wed, 19 Dec 2018 07:09:18 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 05CB989AE7 for ; Wed, 19 Dec 2018 12:09:14 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-174.ams2.redhat.com [10.36.117.174]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7020608EE; Wed, 19 Dec 2018 12:09:10 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 659E25E50B; Wed, 19 Dec 2018 13:09:05 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 19 Dec 2018 13:09:04 +0100 Message-Id: <20181219120904.17643-8-kraxel@redhat.com> In-Reply-To: <20181219120904.17643-1-kraxel@redhat.com> References: <20181219120904.17643-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 19 Dec 2018 12:09:14 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH v2 7/7] keymap: fix keyup mappings X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It is possible that the modifier state on keyup is different from the modifier state on keydown. In that case the keycode lookup can end up with different keys in case multiple keysym -> keycode mappings exist, because it picks the mapping depending on modifier state. To fix that change the lookup logic for keyup events. Instead of looking at the modifier state check the key state and prefer a keycodes where the key is in "down" state right now. Fixes: abb4f2c965 keymap: consider modifier state when picking a mapping Buglink: https://bugs.launchpad.net/bugs/1738283 Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1658676 Signed-off-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrang=C3=A9 --- ui/keymaps.h | 2 +- ui/curses.c | 2 +- ui/keymaps.c | 55 ++++++++++++++++++++++++++++++++++--------------------- ui/vnc.c | 2 +- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/ui/keymaps.h b/ui/keymaps.h index 6a2365196a..97deec3437 100644 --- a/ui/keymaps.h +++ b/ui/keymaps.h @@ -56,7 +56,7 @@ typedef struct kbd_layout_t kbd_layout_t; kbd_layout_t *init_keyboard_layout(const name2keysym_t *table, const char *language, Error **errp); int keysym2scancode(kbd_layout_t *k, int keysym, - KbdState *kbd); + KbdState *kbd, bool down); int keycode_is_keypad(kbd_layout_t *k, int keycode); int keysym_is_numlock(kbd_layout_t *k, int keysym); =20 diff --git a/ui/curses.c b/ui/curses.c index 54687589d4..6e0091c3b2 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -273,7 +273,7 @@ static void curses_refresh(DisplayChangeListener *dcl) } =20 keycode =3D keysym2scancode(kbd_layout, keysym & KEYSYM_MASK, - NULL); + NULL, false); if (keycode =3D=3D 0) continue; =20 diff --git a/ui/keymaps.c b/ui/keymaps.c index 6be87cc201..9ec0bc5333 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -28,6 +28,7 @@ #include "trace.h" #include "qemu/error-report.h" #include "qapi/error.h" +#include "ui/input.h" =20 struct keysym2code { uint32_t count; @@ -189,7 +190,7 @@ kbd_layout_t *init_keyboard_layout(const name2keysym_t = *table, =20 =20 int keysym2scancode(kbd_layout_t *k, int keysym, - KbdState *kbd) + KbdState *kbd, bool down) { static const uint32_t mask =3D SCANCODE_SHIFT | SCANCODE_ALTGR | SCANCODE_CTRL; @@ -213,27 +214,39 @@ int keysym2scancode(kbd_layout_t *k, int keysym, return keysym2code->keycodes[0]; } =20 - /* - * We have multiple keysym -> keycode mappings. - * - * Check whenever we find one mapping where the modifier state of - * the mapping matches the current user interface modifier state. - * If so, prefer that one. - */ - mods =3D 0; - if (kbd && kbd_state_modifier_get(kbd, KBD_MOD_SHIFT)) { - mods |=3D SCANCODE_SHIFT; - } - if (kbd && kbd_state_modifier_get(kbd, KBD_MOD_ALTGR)) { - mods |=3D SCANCODE_ALTGR; - } - if (kbd && kbd_state_modifier_get(kbd, KBD_MOD_CTRL)) { - mods |=3D SCANCODE_CTRL; - } + /* We have multiple keysym -> keycode mappings. */ + if (down) { + /* + * On keydown: Check whenever we find one mapping where the + * modifier state of the mapping matches the current user + * interface modifier state. If so, prefer that one. + */ + mods =3D 0; + if (kbd && kbd_state_modifier_get(kbd, KBD_MOD_SHIFT)) { + mods |=3D SCANCODE_SHIFT; + } + if (kbd && kbd_state_modifier_get(kbd, KBD_MOD_ALTGR)) { + mods |=3D SCANCODE_ALTGR; + } + if (kbd && kbd_state_modifier_get(kbd, KBD_MOD_CTRL)) { + mods |=3D SCANCODE_CTRL; + } =20 - for (i =3D 0; i < keysym2code->count; i++) { - if ((keysym2code->keycodes[i] & mask) =3D=3D mods) { - return keysym2code->keycodes[i]; + for (i =3D 0; i < keysym2code->count; i++) { + if ((keysym2code->keycodes[i] & mask) =3D=3D mods) { + return keysym2code->keycodes[i]; + } + } + } else { + /* + * On keyup: Try find a key which is actually down. + */ + for (i =3D 0; i < keysym2code->count; i++) { + QKeyCode qcode =3D qemu_input_key_number_to_qcode + (keysym2code->keycodes[i]); + if (kbd && kbd_state_key_get(kbd, qcode)) { + return keysym2code->keycodes[i]; + } } } return keysym2code->keycodes[0]; diff --git a/ui/vnc.c b/ui/vnc.c index 704a138667..08eba8b6ed 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -1962,7 +1962,7 @@ static void key_event(VncState *vs, int down, uint32_= t sym) } =20 keycode =3D keysym2scancode(vs->vd->kbd_layout, lsym & 0xFFFF, - vs->vd->kbd) & SCANCODE_KEYMASK; + vs->vd->kbd, down) & SCANCODE_KEYMASK; trace_vnc_key_event_map(down, sym, keycode, code2name(keycode)); do_key_event(vs, down, keycode, sym); } --=20 2.9.3