From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 3/5] keymap: numpad keysyms and keycodes are fixed
Date: Fri, 16 Feb 2018 15:44:16 +0100 [thread overview]
Message-ID: <20180216144418.21986-4-kraxel@redhat.com> (raw)
In-Reply-To: <20180216144418.21986-1-kraxel@redhat.com>
No need to figure them at runtime from the keymap.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
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"
-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 inline gpointer hashkey(int keysym)
@@ -70,29 +62,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;
@@ -165,13 +134,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;
}
@@ -232,24 +194,18 @@ 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;
- }
- }
- return 0;
+ if (keycode >= 0x47 && keycode <= 0x53)
+ return true;
+ 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;
}
--
2.9.3
next prev parent reply other threads:[~2018-02-16 14:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-16 14:44 [Qemu-devel] [PATCH 0/5] keymap: support kbd layouts with multiple mappings for the same key Gerd Hoffmann
2018-02-16 14:44 ` [Qemu-devel] [PATCH 1/5] keymap: make struct kbd_layout_t private to ui/keymaps.c Gerd Hoffmann
2018-02-16 14:44 ` [Qemu-devel] [PATCH 2/5] keymap: use glib hash for kbd_layout_t Gerd Hoffmann
2018-02-16 14:44 ` Gerd Hoffmann [this message]
2018-02-16 14:44 ` [Qemu-devel] [PATCH 4/5] keymap: record multiple keysym -> keycode mappings Gerd Hoffmann
2018-02-16 14:44 ` [Qemu-devel] [PATCH 5/5] keymap: consider modifier state when picking a mapping Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180216144418.21986-4-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).