qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: qemu-devel@nongnu.org
Cc: kraxel@redhat.com, aliguori@amazon.com, lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH v2] ui/input: fix event emitting of repeated combined keys
Date: Fri, 26 Sep 2014 18:23:19 +0800	[thread overview]
Message-ID: <1411726999-26513-1-git-send-email-akong@redhat.com> (raw)

Currently we emit press events of combined keys first, then emit
release events by reverse order. But it doesn't match with physical
keyboard if the keys contain continued & repeated keys.

For example, (qemu) sendkey a-b-b

Current emited events: (actually the second 'presse b' and 'release b'
can't be identified by guest, the interval is too short)
  press a
  press b
  press b
  release b
  release b
  release a

Correct events order of physical keyboard:
  press a
  press b
  release b
  press b
  release b
  release a

This patch fixed the event order if keys contain continued & repeated
keys. his patch based on:
http://lists.nongnu.org/archive/html/qemu-devel/2014-09/msg05150.html

Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Amos Kong <akong@redhat.com>
---
V2: rebase this patch on Gerd's better fix of release order
---
 ui/input-legacy.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index a698a34..3fd3e83 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -95,9 +95,17 @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
     for (p = keys; p != NULL; p = p->next) {
         qemu_input_event_send_key(NULL, copy_key_value(p->value), true);
         qemu_input_event_send_key_delay(hold_time);
-        up = g_realloc(up, sizeof(*up) * (count+1));
-        up[count] = copy_key_value(p->value);
-        count++;
+
+        /* release event will be emitted immediately if next key is repeated */
+        if (p->next && p->value->kind == p->next->value->kind &&
+            p->value->qcode == p->next->value->qcode) {
+            qemu_input_event_send_key(NULL, copy_key_value(p->value), false);
+            qemu_input_event_send_key_delay(hold_time);
+        } else {
+            up = g_realloc(up, sizeof(*up) * (count+1));
+            up[count] = copy_key_value(p->value);
+            count++;
+        }
     }
     while (count) {
         count--;
-- 
1.9.3

             reply	other threads:[~2014-09-26 10:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-26 10:23 Amos Kong [this message]
2014-09-26 10:36 ` [Qemu-devel] [PATCH v2] ui/input: fix event emitting of repeated combined keys Gerd Hoffmann
2014-09-26 10:53   ` Amos Kong
2014-09-26 11:24     ` Gerd Hoffmann
2014-09-26 15:15       ` Marcelo Tosatti
2014-09-29  8:59         ` Gerd Hoffmann
2014-09-27  3:29       ` Amos Kong
2014-09-29  9:09         ` Gerd Hoffmann
2014-10-29  7:12           ` Amos Kong
2014-09-26 14:04     ` Eric Blake

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=1411726999-26513-1-git-send-email-akong@redhat.com \
    --to=akong@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=kraxel@redhat.com \
    --cc=lcapitulino@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).