qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>, Anthony Liguori <aliguori@amazon.com>
Subject: [Qemu-devel] [PULL 04/10] input: use KeyValue directly in sendkey monitor command
Date: Fri, 16 May 2014 08:47:25 +0200	[thread overview]
Message-ID: <1400222851-6725-5-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1400222851-6725-1-git-send-email-kraxel@redhat.com>

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/input-legacy.c | 47 +++++++++++++++++++++++------------------------
 1 file changed, 23 insertions(+), 24 deletions(-)

diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index ff85220..2a53860 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -74,38 +74,44 @@ int index_from_key(const char *key)
     return i;
 }
 
-static int *keycodes;
-static int keycodes_size;
+static KeyValue **keyvalues;
+static int keyvalues_size;
 static QEMUTimer *key_timer;
 
-static void free_keycodes(void)
+static void free_keyvalues(void)
 {
-    g_free(keycodes);
-    keycodes = NULL;
-    keycodes_size = 0;
+    g_free(keyvalues);
+    keyvalues = NULL;
+    keyvalues_size = 0;
 }
 
 static void release_keys(void *opaque)
 {
-    while (keycodes_size > 0) {
-        qemu_input_event_send_key_number(NULL, keycodes[--keycodes_size],
-                                         false);
+    while (keyvalues_size > 0) {
+        qemu_input_event_send_key(NULL, keyvalues[--keyvalues_size],
+                                  false);
     }
 
-    free_keycodes();
+    free_keyvalues();
+}
+
+static KeyValue *copy_key_value(KeyValue *src)
+{
+    KeyValue *dst = g_new(KeyValue, 1);
+    memcpy(dst, src, sizeof(*src));
+    return dst;
 }
 
 void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
                   Error **errp)
 {
-    int keycode;
     KeyValueList *p;
 
     if (!key_timer) {
         key_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, release_keys, NULL);
     }
 
-    if (keycodes != NULL) {
+    if (keyvalues != NULL) {
         timer_del(key_timer);
         release_keys(NULL);
     }
@@ -115,23 +121,16 @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
     }
 
     for (p = keys; p != NULL; p = p->next) {
-        /* key down events */
-        keycode = qemu_input_key_value_to_number(p->value);
-        if (keycode < 0x01 || keycode > 0xff) {
-            error_setg(errp, "invalid hex keycode 0x%x", keycode);
-            free_keycodes();
-            return;
-        }
-
-        qemu_input_event_send_key_number(NULL, keycode, true);
+        qemu_input_event_send_key(NULL, copy_key_value(p->value), true);
 
-        keycodes = g_realloc(keycodes, sizeof(int) * (keycodes_size + 1));
-        keycodes[keycodes_size++] = keycode;
+        keyvalues = g_realloc(keyvalues, sizeof(KeyValue *) *
+                              (keyvalues_size + 1));
+        keyvalues[keyvalues_size++] = copy_key_value(p->value);
     }
 
     /* delayed key up events */
     timer_mod(key_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
-                   muldiv64(get_ticks_per_sec(), hold_time, 1000));
+              muldiv64(get_ticks_per_sec(), hold_time, 1000));
 }
 
 static void legacy_kbd_event(DeviceState *dev, QemuConsole *src,
-- 
1.8.3.1

  parent reply	other threads:[~2014-05-16  6:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-16  6:47 [Qemu-devel] [PULL 00/10] input layer rework continued Gerd Hoffmann
2014-05-16  6:47 ` [Qemu-devel] [PULL 01/10] ps2: set ps/2 output buffer size as the same as kernel Gerd Hoffmann
2014-05-16  6:47 ` [Qemu-devel] [PULL 02/10] input: key mapping helpers Gerd Hoffmann
2014-05-16  6:47 ` [Qemu-devel] [PULL 03/10] input: add qemu_input_handler_deactivate Gerd Hoffmann
2014-05-16  6:47 ` Gerd Hoffmann [this message]
2014-05-16  6:47 ` [Qemu-devel] [PULL 05/10] input: switch ps/2 kbd to new input api Gerd Hoffmann
2014-05-16  6:47 ` [Qemu-devel] [PULL 06/10] input: switch ps/2 mouse " Gerd Hoffmann
2014-05-16  6:47 ` [Qemu-devel] [PULL 07/10] input: switch sparc32 kbd " Gerd Hoffmann
2014-05-16  6:47 ` [Qemu-devel] [PULL 08/10] input: remove sparc keymap hack Gerd Hoffmann
2014-05-16  6:47 ` [Qemu-devel] [PULL 09/10] input: sparc32 kbd: fix some key mappings Gerd Hoffmann
2014-05-16  6:47 ` [Qemu-devel] [PULL 10/10] input: sparc32 kbd: claim en-us layout Gerd Hoffmann
2014-05-18 16:14 ` [Qemu-devel] [PULL 00/10] input layer rework continued Olivier Danet
2014-05-19 13:09 ` Peter Maydell

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=1400222851-6725-5-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=aliguori@amazon.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).