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>
Subject: [Qemu-devel] [PATCH 4/4] kbd keds: vnc
Date: Thu, 25 Feb 2010 09:39:21 +0100	[thread overview]
Message-ID: <1267087161-15204-5-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1267087161-15204-1-git-send-email-kraxel@redhat.com>

Use led status notification support in vnc.

The qemu vnc server keeps track of the capslock and numlock states based
on the key presses it receives from the vnc client.  But this fails in
case the guests idea of the capslock and numlock state changes for other
reasons.  One case is guest reboot (+ keyboard reset).  Another case are
more recent windows versions which reset capslock state before
presenting the login screen.

Usually guests use the keyboard leds to signal the capslock and numlock
state to the user, so we can use this to better keep track of capslock
and numlock state in the qemu vnc server.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 vnc.c |   20 +++++++++++++++++++-
 vnc.h |    1 +
 2 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/vnc.c b/vnc.c
index db34b0e..38690e2 100644
--- a/vnc.c
+++ b/vnc.c
@@ -1111,6 +1111,7 @@ static void vnc_disconnect_finish(VncState *vs)
     }
 
     vnc_remove_timer(vs->vd);
+    qemu_remove_led_event_handler(vs->led);
     qemu_free(vs);
 }
 
@@ -1496,6 +1497,22 @@ static void press_key(VncState *vs, int keysym)
     kbd_put_keycode(keysym2scancode(vs->vd->kbd_layout, keysym) | 0x80);
 }
 
+static void kbd_leds(void *opaque, int ledstate)
+{
+    VncState *vs = opaque;
+    int caps, num;
+
+    caps = ledstate & QEMU_CAPS_LOCK_LED ? 1 : 0;
+    num  = ledstate & QEMU_NUM_LOCK_LED  ? 1 : 0;
+
+    if (vs->modifiers_state[0x3a] != caps) {
+        vs->modifiers_state[0x3a] = caps;
+    }
+    if (vs->modifiers_state[0x45] != num) {
+        vs->modifiers_state[0x45] = num;
+    }
+}
+
 static void do_key_event(VncState *vs, int down, int keycode, int sym)
 {
     /* QEMU console switch */
@@ -1521,7 +1538,7 @@ static void do_key_event(VncState *vs, int down, int keycode, int sym)
         break;
     case 0x3a:                        /* CapsLock */
     case 0x45:                        /* NumLock */
-        if (!down)
+        if (down)
             vs->modifiers_state[keycode] ^= 1;
         break;
     }
@@ -2407,6 +2424,7 @@ static void vnc_connect(VncDisplay *vd, int csock)
     vnc_flush(vs);
     vnc_read_when(vs, protocol_version, 12);
     reset_keys(vs);
+    vs->led = qemu_add_led_event_handler(kbd_leds, vs);
 
     vnc_init_timer(vd);
 
diff --git a/vnc.h b/vnc.h
index ff9a699..0fc89bd 100644
--- a/vnc.h
+++ b/vnc.h
@@ -161,6 +161,7 @@ struct VncState
     size_t read_handler_expect;
     /* input */
     uint8_t modifiers_state[256];
+    QEMUPutLEDEntry *led;
 
     Buffer zlib;
     Buffer zlib_tmp;
-- 
1.6.6

  parent reply	other threads:[~2010-02-25  8:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-25  8:39 [Qemu-devel] [PATCH 0/4] keyboard led status tracking Gerd Hoffmann
2010-02-25  8:39 ` [Qemu-devel] [PATCH 1/4] kbd leds: infrastructure Gerd Hoffmann
2010-02-25 10:57   ` [Qemu-devel] " Juan Quintela
2010-02-25 14:15   ` [Qemu-devel] " Anthony Liguori
2010-02-25 14:36     ` Gerd Hoffmann
2010-02-25 15:07       ` Anthony Liguori
2010-02-25 16:51         ` Gerd Hoffmann
2010-02-25 17:05           ` Anthony Liguori
2010-02-25  8:39 ` [Qemu-devel] [PATCH 2/4] kbd leds: ps/2 kbd Gerd Hoffmann
2010-02-25 10:59   ` [Qemu-devel] " Juan Quintela
2010-02-25  8:39 ` [Qemu-devel] [PATCH 3/4] kbd leds: usb kbd Gerd Hoffmann
2010-02-25  8:39 ` Gerd Hoffmann [this message]
2010-02-25 11:03   ` [Qemu-devel] Re: [PATCH 4/4] kbd keds: vnc Juan Quintela
2010-02-25 11:11     ` Paolo Bonzini
2010-02-26 16:05     ` Gerd Hoffmann
2010-02-28  1:38   ` [Qemu-devel] " Paul Brook
2010-03-01  8:12     ` 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=1267087161-15204-5-git-send-email-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).