From patchwork Thu Feb 22 07:05:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 10234767 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7219360209 for ; Thu, 22 Feb 2018 07:06:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DFF528925 for ; Thu, 22 Feb 2018 07:06:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72A0E28926; Thu, 22 Feb 2018 07:06:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F24F828921 for ; Thu, 22 Feb 2018 07:06:32 +0000 (UTC) Received: from localhost ([::1]:36489 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eokxb-0000MP-4s for patchwork-qemu-devel@patchwork.kernel.org; Thu, 22 Feb 2018 02:06:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eokwb-00089e-P8 for qemu-devel@nongnu.org; Thu, 22 Feb 2018 02:05:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eokwX-00084g-Qf for qemu-devel@nongnu.org; Thu, 22 Feb 2018 02:05:29 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38802 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 1eokwX-000843-HD for qemu-devel@nongnu.org; Thu, 22 Feb 2018 02:05:25 -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 B3A3E818B137 for ; Thu, 22 Feb 2018 07:05:20 +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 E635F1049464; Thu, 22 Feb 2018 07:05:17 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 25AF017528; Thu, 22 Feb 2018 08:05:14 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 22 Feb 2018 08:05:11 +0100 Message-Id: <20180222070513.8740-4-kraxel@redhat.com> In-Reply-To: <20180222070513.8740-1-kraxel@redhat.com> References: <20180222070513.8740-1-kraxel@redhat.com> MIME-Version: 1.0 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.8]); Thu, 22 Feb 2018 07:05:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Thu, 22 Feb 2018 07:05:20 +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 v3 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP No need to figure them at runtime from the keymap. Signed-off-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrangé --- ui/keymaps.c | 61 +++++++++--------------------------------------------------- 1 file changed, 9 insertions(+), 52 deletions(-) diff --git a/ui/keymaps.c b/ui/keymaps.c index 449c3dec22..cbdd65c767 100644 --- a/ui/keymaps.c +++ b/ui/keymaps.c @@ -28,20 +28,12 @@ #include "trace.h" #include "qemu/error-report.h" -struct key_range { - int start; - int end; - struct key_range *next; -}; - struct keysym2code { uint16_t keycode; }; struct kbd_layout_t { GHashTable *hash; - struct key_range *keypad_range; - struct key_range *numlock_range; }; static int get_keysym(const name2keysym_t *table, @@ -64,29 +56,6 @@ static int get_keysym(const name2keysym_t *table, } -static void add_to_key_range(struct key_range **krp, int code) { - struct key_range *kr; - for (kr = *krp; kr; kr = kr->next) { - if (code >= kr->start && code <= kr->end) { - break; - } - if (code == kr->start - 1) { - kr->start--; - break; - } - if (code == kr->end + 1) { - kr->end++; - break; - } - } - if (kr == NULL) { - kr = g_malloc0(sizeof(*kr)); - kr->start = kr->end = code; - kr->next = *krp; - *krp = kr; - } -} - static void add_keysym(char *line, int keysym, int keycode, kbd_layout_t *k) { struct keysym2code *keysym2code; @@ -160,13 +129,6 @@ static kbd_layout_t *parse_keyboard_layout(const name2keysym_t *table, const char *rest = line + offset + 1; int keycode = strtol(rest, NULL, 0); - 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 |= SCANCODE_SHIFT; } @@ -228,24 +190,19 @@ int keysym2scancode(kbd_layout_t *k, int keysym) int keycode_is_keypad(kbd_layout_t *k, int keycode) { - struct key_range *kr; - - for (kr = k->keypad_range; kr; kr = kr->next) { - if (keycode >= kr->start && keycode <= kr->end) { - return 1; - } + if (keycode >= 0x47 && keycode <= 0x53) { + return true; } - return 0; + return false; } int keysym_is_numlock(kbd_layout_t *k, int keysym) { - struct key_range *kr; - - for (kr = k->numlock_range; kr; kr = kr->next) { - if (keysym >= kr->start && keysym <= 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; }