From nobody Fri Oct 24 09:38:22 2025 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 1518792434383507.6633847744291; Fri, 16 Feb 2018 06:47:14 -0800 (PST) Received: from localhost ([::1]:56383 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emhI8-0001pZ-So for importer@patchew.org; Fri, 16 Feb 2018 09:47:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emhFc-0000OY-3t for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emhFb-0003o5-1t for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:36 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43550 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1emhFa-0003nq-TO for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:34 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 01D52EAEA4 for ; Fri, 16 Feb 2018 14:44:23 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-147.ams2.redhat.com [10.36.116.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7999D213AEE4; Fri, 16 Feb 2018 14:44:19 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id BF8944F29D; Fri, 16 Feb 2018 15:44:18 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 16 Feb 2018 15:44:14 +0100 Message-Id: <20180216144418.21986-2-kraxel@redhat.com> In-Reply-To: <20180216144418.21986-1-kraxel@redhat.com> References: <20180216144418.21986-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 16 Feb 2018 14:44:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 16 Feb 2018 14:44:24 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 1/5] keymap: make struct kbd_layout_t private to ui/keymaps.c 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" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Also use kbd_layout_t pointers instead of void pointers. Signed-off-by: Gerd Hoffmann --- ui/keymaps.h | 28 +++++----------------------- ui/keymaps.c | 31 ++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/ui/keymaps.h b/ui/keymaps.h index 8757465529..5c0898bfcf 100644 --- a/ui/keymaps.h +++ b/ui/keymaps.h @@ -32,25 +32,6 @@ typedef struct { int keysym; } name2keysym_t; =20 -struct key_range { - int start; - int end; - struct key_range *next; -}; - -#define MAX_NORMAL_KEYCODE 512 -#define MAX_EXTRA_COUNT 256 -typedef struct { - uint16_t keysym2keycode[MAX_NORMAL_KEYCODE]; - struct { - int keysym; - uint16_t keycode; - } keysym2keycode_extra[MAX_EXTRA_COUNT]; - int extra_count; - struct key_range *keypad_range; - struct key_range *numlock_range; -} kbd_layout_t; - /* scancode without modifiers */ #define SCANCODE_KEYMASK 0xff /* scancode without grey or up bit */ @@ -69,10 +50,11 @@ typedef struct { #define SCANCODE_ALT 0x400 #define SCANCODE_ALTGR 0x800 =20 +typedef struct kbd_layout_t kbd_layout_t; =20 -void *init_keyboard_layout(const name2keysym_t *table, const char *languag= e); -int keysym2scancode(void *kbd_layout, int keysym); -int keycode_is_keypad(void *kbd_layout, int keycode); -int keysym_is_numlock(void *kbd_layout, int keysym); +kbd_layout_t* init_keyboard_layout(const name2keysym_t *table, const char = *language); +int keysym2scancode(kbd_layout_t *k, int keysym); +int keycode_is_keypad(kbd_layout_t *k, int keycode); +int keysym_is_numlock(kbd_layout_t *k, int keysym); =20 #endif /* QEMU_KEYMAPS_H */ diff --git a/ui/keymaps.c b/ui/keymaps.c index f9762d1497..74d93dee63 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -28,6 +28,26 @@ #include "trace.h" #include "qemu/error-report.h" =20 +#define MAX_NORMAL_KEYCODE 512 +#define MAX_EXTRA_COUNT 256 + +struct key_range { + int start; + int end; + struct key_range *next; +}; + +struct kbd_layout_t { + uint16_t keysym2keycode[MAX_NORMAL_KEYCODE]; + struct { + int keysym; + uint16_t keycode; + } keysym2keycode_extra[MAX_EXTRA_COUNT]; + int extra_count; + struct key_range *keypad_range; + struct key_range *numlock_range; +}; + static int get_keysym(const name2keysym_t *table, const char *name) { @@ -186,15 +206,14 @@ static kbd_layout_t *parse_keyboard_layout(const name= 2keysym_t *table, } =20 =20 -void *init_keyboard_layout(const name2keysym_t *table, const char *languag= e) +kbd_layout_t* init_keyboard_layout(const name2keysym_t *table, const char = *language) { return parse_keyboard_layout(table, language, NULL); } =20 =20 -int keysym2scancode(void *kbd_layout, int keysym) +int keysym2scancode(kbd_layout_t *k, int keysym) { - kbd_layout_t *k =3D kbd_layout; if (keysym < MAX_NORMAL_KEYCODE) { if (k->keysym2keycode[keysym] =3D=3D 0) { trace_keymap_unmapped(keysym); @@ -217,9 +236,8 @@ int keysym2scancode(void *kbd_layout, int keysym) return 0; } =20 -int keycode_is_keypad(void *kbd_layout, int keycode) +int keycode_is_keypad(kbd_layout_t *k, int keycode) { - kbd_layout_t *k =3D kbd_layout; struct key_range *kr; =20 for (kr =3D k->keypad_range; kr; kr =3D kr->next) { @@ -230,9 +248,8 @@ int keycode_is_keypad(void *kbd_layout, int keycode) return 0; } =20 -int keysym_is_numlock(void *kbd_layout, int keysym) +int keysym_is_numlock(kbd_layout_t *k, int keysym) { - kbd_layout_t *k =3D kbd_layout; struct key_range *kr; =20 for (kr =3D k->numlock_range; kr; kr =3D kr->next) { --=20 2.9.3 From nobody Fri Oct 24 09:38:22 2025 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 1518792653608750.0098219454235; Fri, 16 Feb 2018 06:50:53 -0800 (PST) Received: from localhost ([::1]:56444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emhLg-0004dZ-P8 for importer@patchew.org; Fri, 16 Feb 2018 09:50:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emhFZ-0000MA-Mz for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emhFW-0003lO-JM for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:33 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37301 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1emhFW-0003l1-DX for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:30 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C29B440FB647 for ; Fri, 16 Feb 2018 14:44:25 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-147.ams2.redhat.com [10.36.116.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 797C0100F9C3; Fri, 16 Feb 2018 14:44:19 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id C92984F29E; Fri, 16 Feb 2018 15:44:18 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 16 Feb 2018 15:44:15 +0100 Message-Id: <20180216144418.21986-3-kraxel@redhat.com> In-Reply-To: <20180216144418.21986-1-kraxel@redhat.com> References: <20180216144418.21986-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 16 Feb 2018 14:44:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 16 Feb 2018 14:44:25 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 2/5] keymap: use glib hash for kbd_layout_t 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" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Drop home-grown lookup code, which is a strange mix of a lookup table and a list. Use standard glib hash instead. Signed-off-by: Gerd Hoffmann --- ui/keymaps.c | 80 ++++++++++++++++++++++++++---------------------------= ---- ui/trace-events | 2 +- 2 files changed, 38 insertions(+), 44 deletions(-) diff --git a/ui/keymaps.c b/ui/keymaps.c index 74d93dee63..2260219e0a 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -28,26 +28,28 @@ #include "trace.h" #include "qemu/error-report.h" =20 -#define MAX_NORMAL_KEYCODE 512 -#define MAX_EXTRA_COUNT 256 - struct key_range { int start; int end; struct key_range *next; }; =20 +struct keysym2code { + uint16_t keycode; +}; + struct kbd_layout_t { - uint16_t keysym2keycode[MAX_NORMAL_KEYCODE]; - struct { - int keysym; - uint16_t keycode; - } keysym2keycode_extra[MAX_EXTRA_COUNT]; - int extra_count; + GHashTable *hash; struct key_range *keypad_range; struct key_range *numlock_range; }; =20 +static inline gpointer hashkey(int keysym) +{ + intptr_t ptr =3D keysym; + return (gpointer)(ptr); +} + static int get_keysym(const name2keysym_t *table, const char *name) { @@ -91,23 +93,18 @@ static void add_to_key_range(struct key_range **krp, in= t code) { } } =20 -static void add_keysym(char *line, int keysym, int keycode, kbd_layout_t *= k) { - if (keysym < MAX_NORMAL_KEYCODE) { - trace_keymap_add("normal", keysym, keycode, line); - k->keysym2keycode[keysym] =3D keycode; - } else { - if (k->extra_count >=3D MAX_EXTRA_COUNT) { - warn_report("Could not assign keysym %s (0x%x)" - " because of memory constraints.", line, keysym); - } else { - trace_keymap_add("extra", keysym, keycode, line); - k->keysym2keycode_extra[k->extra_count]. - keysym =3D keysym; - k->keysym2keycode_extra[k->extra_count]. - keycode =3D keycode; - k->extra_count++; - } - } +static void add_keysym(char *line, int keysym, int keycode, kbd_layout_t *= k) +{ + struct keysym2code *keysym2code; + + keysym2code =3D g_hash_table_lookup(k->hash, hashkey(keysym)); + if (keysym2code) + return; + + keysym2code =3D g_new0(struct keysym2code, 1); + keysym2code->keycode =3D keycode; + g_hash_table_replace(k->hash, hashkey(keysym), keysym2code); + trace_keymap_add(keysym, keycode, line); } =20 static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table, @@ -131,6 +128,7 @@ static kbd_layout_t *parse_keyboard_layout(const name2k= eysym_t *table, =20 if (!k) { k =3D g_new0(kbd_layout_t, 1); + k->hash =3D g_hash_table_new(NULL, NULL); } =20 for(;;) { @@ -214,26 +212,22 @@ kbd_layout_t* init_keyboard_layout(const name2keysym_= t *table, const char *langu =20 int keysym2scancode(kbd_layout_t *k, int keysym) { - if (keysym < MAX_NORMAL_KEYCODE) { - if (k->keysym2keycode[keysym] =3D=3D 0) { - trace_keymap_unmapped(keysym); - warn_report("no scancode found for keysym %d", keysym); - } - return k->keysym2keycode[keysym]; - } else { - int i; + struct keysym2code *keysym2code; + #ifdef XK_ISO_Left_Tab - if (keysym =3D=3D XK_ISO_Left_Tab) { - keysym =3D XK_Tab; - } + if (keysym =3D=3D XK_ISO_Left_Tab) { + keysym =3D XK_Tab; + } #endif - for (i =3D 0; i < k->extra_count; i++) { - if (k->keysym2keycode_extra[i].keysym =3D=3D keysym) { - return k->keysym2keycode_extra[i].keycode; - } - } + + keysym2code =3D g_hash_table_lookup(k->hash, hashkey(keysym)); + if (!keysym2code) { + trace_keymap_unmapped(keysym); + warn_report("no scancode found for keysym %d", keysym); + return 0; } - return 0; + + return keysym2code->keycode; } =20 int keycode_is_keypad(kbd_layout_t *k, int keycode) diff --git a/ui/trace-events b/ui/trace-events index 34229e6747..861b68a305 100644 --- a/ui/trace-events +++ b/ui/trace-events @@ -78,7 +78,7 @@ qemu_spice_create_update(uint32_t left, uint32_t right, u= int32_t top, uint32_t b =20 # ui/keymaps.c keymap_parse(const char *file) "file %s" -keymap_add(const char *type, int sym, int code, const char *line) "%-6s sy= m=3D0x%04x code=3D0x%04x (line: %s)" +keymap_add(int sym, int code, const char *line) "sym=3D0x%04x code=3D0x%04= x (line: %s)" keymap_unmapped(int sym) "sym=3D0x%04x" =20 # ui/x_keymap.c --=20 2.9.3 From nobody Fri Oct 24 09:38:22 2025 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 1518792814677431.5650508627392; Fri, 16 Feb 2018 06:53:34 -0800 (PST) Received: from localhost ([::1]:56806 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emhOI-00078S-0H for importer@patchew.org; Fri, 16 Feb 2018 09:53:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emhFb-0000OH-T8 for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emhFb-0003oA-2F for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:35 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43548 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1emhFa-0003nm-Th for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:35 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B6AE5EAEA0 for ; Fri, 16 Feb 2018 14:44:23 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-147.ams2.redhat.com [10.36.116.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 797102026DFD; Fri, 16 Feb 2018 14:44:19 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id D18B84F29F; Fri, 16 Feb 2018 15:44:18 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 16 Feb 2018 15:44:16 +0100 Message-Id: <20180216144418.21986-4-kraxel@redhat.com> In-Reply-To: <20180216144418.21986-1-kraxel@redhat.com> References: <20180216144418.21986-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 16 Feb 2018 14:44:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 16 Feb 2018 14:44:24 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 3/5] keymap: numpad keysyms and keycodes are fixed 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" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" No need to figure them at runtime from the keymap. Signed-off-by: Gerd Hoffmann --- ui/keymaps.c | 62 +++++++++-----------------------------------------------= ---- 1 file changed, 9 insertions(+), 53 deletions(-) diff --git a/ui/keymaps.c b/ui/keymaps.c index 2260219e0a..4dd92edc7d 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -28,20 +28,12 @@ #include "trace.h" #include "qemu/error-report.h" =20 -struct key_range { - int start; - int end; - struct key_range *next; -}; - struct keysym2code { uint16_t keycode; }; =20 struct kbd_layout_t { GHashTable *hash; - struct key_range *keypad_range; - struct key_range *numlock_range; }; =20 static inline gpointer hashkey(int keysym) @@ -70,29 +62,6 @@ static int get_keysym(const name2keysym_t *table, } =20 =20 -static void add_to_key_range(struct key_range **krp, int code) { - struct key_range *kr; - for (kr =3D *krp; kr; kr =3D kr->next) { - if (code >=3D kr->start && code <=3D kr->end) { - break; - } - if (code =3D=3D kr->start - 1) { - kr->start--; - break; - } - if (code =3D=3D kr->end + 1) { - kr->end++; - break; - } - } - if (kr =3D=3D NULL) { - kr =3D g_malloc0(sizeof(*kr)); - kr->start =3D kr->end =3D code; - kr->next =3D *krp; - *krp =3D kr; - } -} - static void add_keysym(char *line, int keysym, int keycode, kbd_layout_t *= k) { struct keysym2code *keysym2code; @@ -165,13 +134,6 @@ static kbd_layout_t *parse_keyboard_layout(const name2= keysym_t *table, const char *rest =3D line + offset + 1; int keycode =3D strtol(rest, NULL, 0); =20 - if (strstr(rest, "numlock")) { - add_to_key_range(&k->keypad_range, keycode); - add_to_key_range(&k->numlock_range, keysym); - /* fprintf(stderr, "keypad keysym %04x keycode %d\= n", - keysym, keycode); */ - } - if (strstr(rest, "shift")) { keycode |=3D SCANCODE_SHIFT; } @@ -232,24 +194,18 @@ int keysym2scancode(kbd_layout_t *k, int keysym) =20 int keycode_is_keypad(kbd_layout_t *k, int keycode) { - struct key_range *kr; - - for (kr =3D k->keypad_range; kr; kr =3D kr->next) { - if (keycode >=3D kr->start && keycode <=3D kr->end) { - return 1; - } - } - return 0; + if (keycode >=3D 0x47 && keycode <=3D 0x53) + return true; + return false; } =20 int keysym_is_numlock(kbd_layout_t *k, int keysym) { - struct key_range *kr; - - for (kr =3D k->numlock_range; kr; kr =3D kr->next) { - if (keysym >=3D kr->start && keysym <=3D kr->end) { - return 1; - } + switch (keysym) { + case 0xffb0 ... 0xffb9: /* KP_0 .. KP_9 */ + case 0xffac: /* KP_Separator */ + case 0xffae: /* KP_Decimal */ + return true; } - return 0; + return false; } --=20 2.9.3 From nobody Fri Oct 24 09:38:22 2025 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 1518792426953277.4064823248592; Fri, 16 Feb 2018 06:47:06 -0800 (PST) Received: from localhost ([::1]:56382 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emhHy-0001kp-KN for importer@patchew.org; Fri, 16 Feb 2018 09:47:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45573) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emhFZ-0000M5-M9 for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emhFW-0003lJ-JH for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:33 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37300 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1emhFW-0003l2-EW for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:30 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 82607407519B for ; Fri, 16 Feb 2018 14:44:25 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-147.ams2.redhat.com [10.36.116.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AAB8100F9C5; Fri, 16 Feb 2018 14:44:19 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id D9EB24F965; Fri, 16 Feb 2018 15:44:18 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 16 Feb 2018 15:44:17 +0100 Message-Id: <20180216144418.21986-5-kraxel@redhat.com> In-Reply-To: <20180216144418.21986-1-kraxel@redhat.com> References: <20180216144418.21986-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 16 Feb 2018 14:44:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 16 Feb 2018 14:44:25 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 4/5] keymap: record multiple keysym -> keycode 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" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Sometimes the same keysym can be created using different key combinations. Record them all in the reverse keymap, not only the first one. Signed-off-by: Gerd Hoffmann --- ui/keymaps.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ui/keymaps.c b/ui/keymaps.c index 4dd92edc7d..d22b3555dd 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -29,7 +29,8 @@ #include "qemu/error-report.h" =20 struct keysym2code { - uint16_t keycode; + uint32_t count; + uint16_t keycodes[4]; }; =20 struct kbd_layout_t { @@ -67,11 +68,19 @@ static void add_keysym(char *line, int keysym, int keyc= ode, kbd_layout_t *k) struct keysym2code *keysym2code; =20 keysym2code =3D g_hash_table_lookup(k->hash, hashkey(keysym)); - if (keysym2code) + if (keysym2code) { + if (keysym2code->count < ARRAY_SIZE(keysym2code->keycodes)) { + keysym2code->keycodes[keysym2code->count++] =3D keycode; + } else { + warn_report("more than %zd keycodes for keysym %d", + ARRAY_SIZE(keysym2code->keycodes), keysym); + } return; + } =20 keysym2code =3D g_new0(struct keysym2code, 1); - keysym2code->keycode =3D keycode; + keysym2code->keycodes[0] =3D keycode; + keysym2code->count =3D 1; g_hash_table_replace(k->hash, hashkey(keysym), keysym2code); trace_keymap_add(keysym, keycode, line); } @@ -189,7 +198,7 @@ int keysym2scancode(kbd_layout_t *k, int keysym) return 0; } =20 - return keysym2code->keycode; + return keysym2code->keycodes[0]; } =20 int keycode_is_keypad(kbd_layout_t *k, int keycode) --=20 2.9.3 From nobody Fri Oct 24 09:38:22 2025 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 1518792558777284.7601653651386; Fri, 16 Feb 2018 06:49:18 -0800 (PST) Received: from localhost ([::1]:56425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emhK9-0003TI-TP for importer@patchew.org; Fri, 16 Feb 2018 09:49:17 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45574) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emhFZ-0000M6-Ml for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emhFW-0003lS-Ja for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:33 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49632 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1emhFW-0003l0-F0 for qemu-devel@nongnu.org; Fri, 16 Feb 2018 09:44:30 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF1578424D for ; Fri, 16 Feb 2018 14:44:24 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-147.ams2.redhat.com [10.36.116.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D0122026E04; Fri, 16 Feb 2018 14:44:24 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id E61464F970; Fri, 16 Feb 2018 15:44:18 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 16 Feb 2018 15:44:18 +0100 Message-Id: <20180216144418.21986-6-kraxel@redhat.com> In-Reply-To: <20180216144418.21986-1-kraxel@redhat.com> References: <20180216144418.21986-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 16 Feb 2018 14:44:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 16 Feb 2018 14:44:24 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 5/5] keymap: consider modifier state when picking a mapping 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" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Pass the modifier state to the keymap lookup function. In case multiple keysym -> keycode mappings exist look at the modifier state and prefer the mapping where the modifier state matches. Signed-off-by: Gerd Hoffmann --- ui/keymaps.h | 3 ++- ui/curses.c | 3 ++- ui/keymaps.c | 33 ++++++++++++++++++++++++++++++++- ui/sdl.c | 6 +++++- ui/vnc.c | 9 +++++++-- 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/ui/keymaps.h b/ui/keymaps.h index 5c0898bfcf..142e40a2a4 100644 --- a/ui/keymaps.h +++ b/ui/keymaps.h @@ -53,7 +53,8 @@ typedef struct { typedef struct kbd_layout_t kbd_layout_t; =20 kbd_layout_t* init_keyboard_layout(const name2keysym_t *table, const char = *language); -int keysym2scancode(kbd_layout_t *k, int keysym); +int keysym2scancode(kbd_layout_t *k, int keysym, + bool shift, bool altgr, bool ctrl); 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 85503876c0..31cd43e73c 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -271,7 +271,8 @@ static void curses_refresh(DisplayChangeListener *dcl) keysym =3D chr; } =20 - keycode =3D keysym2scancode(kbd_layout, keysym & KEYSYM_MASK); + keycode =3D keysym2scancode(kbd_layout, keysym & KEYSYM_MASK, + false, false, false); if (keycode =3D=3D 0) continue; =20 diff --git a/ui/keymaps.c b/ui/keymaps.c index d22b3555dd..eb6c15b61f 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -181,8 +181,12 @@ kbd_layout_t* init_keyboard_layout(const name2keysym_t= *table, const char *langu } =20 =20 -int keysym2scancode(kbd_layout_t *k, int keysym) +int keysym2scancode(kbd_layout_t *k, int keysym, + bool shift, bool altgr, bool ctrl) { + static const uint32_t mask =3D + SCANCODE_SHIFT | SCANCODE_ALTGR | SCANCODE_CTRL; + uint32_t mods, i; struct keysym2code *keysym2code; =20 #ifdef XK_ISO_Left_Tab @@ -198,6 +202,33 @@ int keysym2scancode(kbd_layout_t *k, int keysym) return 0; } =20 + if (keysym2code->count =3D=3D 1) { + return keysym2code->keycodes[0]; + } + + /* + * 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 (shift) { + mods |=3D SCANCODE_SHIFT; + } + if (altgr) { + mods |=3D SCANCODE_ALTGR; + } + if (ctrl) { + mods |=3D SCANCODE_CTRL; + } + + for (i =3D 0; i < keysym2code->count; i++) { + if ((keysym2code->keycodes[i] & mask) =3D=3D mods) { + return keysym2code->keycodes[i]; + } + } return keysym2code->keycodes[0]; } =20 diff --git a/ui/sdl.c b/ui/sdl.c index a6bff301eb..4c46c40a7f 100644 --- a/ui/sdl.c +++ b/ui/sdl.c @@ -200,6 +200,9 @@ static kbd_layout_t *kbd_layout =3D NULL; =20 static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent *ev) { + bool shift =3D modifiers_state[0x2a] || modifiers_state[0x36]; + bool altgr =3D modifiers_state[0xb8]; + bool ctrl =3D modifiers_state[0x1d] || modifiers_state[0x9d]; int keysym; /* workaround for X11+SDL bug with AltGR */ keysym =3D ev->keysym.sym; @@ -209,7 +212,8 @@ static uint8_t sdl_keyevent_to_keycode_generic(const SD= L_KeyboardEvent *ev) if (keysym =3D=3D 92 && ev->keysym.scancode =3D=3D 133) { keysym =3D 0xa5; } - return keysym2scancode(kbd_layout, keysym) & SCANCODE_KEYMASK; + return keysym2scancode(kbd_layout, keysym, + shift, altgr, ctrl) & SCANCODE_KEYMASK; } =20 =20 diff --git a/ui/vnc.c b/ui/vnc.c index c715bae1cf..52762f3e99 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -1728,7 +1728,8 @@ static void reset_keys(VncState *vs) =20 static void press_key(VncState *vs, int keysym) { - int keycode =3D keysym2scancode(vs->vd->kbd_layout, keysym) & SCANCODE= _KEYMASK; + int keycode =3D keysym2scancode(vs->vd->kbd_layout, keysym, + false, false, false) & SCANCODE_KEYMASK; qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, true); qemu_input_event_send_key_delay(vs->vd->key_delay_ms); qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, false); @@ -1987,6 +1988,9 @@ static const char *code2name(int keycode) =20 static void key_event(VncState *vs, int down, uint32_t sym) { + bool shift =3D vs->modifiers_state[0x2a] || vs->modifiers_state[0x36]; + bool altgr =3D vs->modifiers_state[0xb8]; + bool ctrl =3D vs->modifiers_state[0x1d] || vs->modifiers_state[0x9d]; int keycode; int lsym =3D sym; =20 @@ -1994,7 +1998,8 @@ static void key_event(VncState *vs, int down, uint32_= t sym) lsym =3D lsym - 'A' + 'a'; } =20 - keycode =3D keysym2scancode(vs->vd->kbd_layout, lsym & 0xFFFF) & SCANC= ODE_KEYMASK; + keycode =3D keysym2scancode(vs->vd->kbd_layout, lsym & 0xFFFF, + shift, altgr, ctrl) & SCANCODE_KEYMASK; trace_vnc_key_event_map(down, sym, keycode, code2name(keycode)); do_key_event(vs, down, keycode, sym); } --=20 2.9.3