aboutsummaryrefslogtreecommitdiff
path: root/vnc.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2010-02-26 17:17:39 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2010-03-09 08:47:27 -0600
commit7ffb82ca6e13feeb37b86a8223da691eff5ee922 (patch)
tree8115121a288e7e5fefe74a1e5c95d702b1cc5948 /vnc.c
parentbd87813e8c3adfa1c12f763b35b2dbacc7796f0d (diff)
kbd keds: vnc
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. Also toggle the numlock and capslock states on keydown events (instead of keyup). Guests do the same. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'vnc.c')
-rw-r--r--vnc.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/vnc.c b/vnc.c
index 01353a96c8..7ce73dca3d 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);
}
@@ -1501,6 +1502,22 @@ static void press_key(VncState *vs, int keysym)
kbd_put_keycode(keycode | SCANCODE_UP);
}
+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 */
@@ -1526,7 +1543,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;
}
@@ -2412,6 +2429,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);