From 04a90a73e42a13f738eda37fe3799f8e427b4f4c Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Tue, 11 May 2010 19:35:47 -0300
Subject: [PATCH 2/9] vnc: sync lock modifier state on connect.

RH-Author: Gerd Hoffmann <kraxel@redhat.com>
Message-id: <1273606547-3733-1-git-send-email-kraxel@redhat.com>
Patchwork-id: 9194
O-Subject: [RHEL-6 kvm PATCH] vnc: sync lock modifier state on connect.
Bugzilla: 569767
RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>
RH-Acked-by: Amit Shah <amit.shah@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>

Slightly different approach compared to upstream as we
don't have notifiers.

bugzilla: #569767
upstream: submitted
	http://patchwork.ozlabs.org/patch/51916/
	http://patchwork.ozlabs.org/patch/51947/

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 console.h |    1 +
 vl.c      |    9 ++++++++-
 vnc.c     |    1 +
 3 files changed, 10 insertions(+), 1 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 console.h |    1 +
 vl.c      |    9 ++++++++-
 vnc.c     |    1 +
 3 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/console.h b/console.h
index 5371beb..b605cdf 100644
--- a/console.h
+++ b/console.h
@@ -48,6 +48,7 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
 
 void kbd_put_keycode(int keycode);
 void kbd_put_ledstate(int ledstate);
+int kbd_get_ledstate(void);
 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
 int kbd_mouse_is_absolute(void);
 
diff --git a/vl.c b/vl.c
index 53b8f88..2589f99 100644
--- a/vl.c
+++ b/vl.c
@@ -409,6 +409,7 @@ static void *qemu_put_kbd_event_opaque;
 static QEMUPutMouseEntry *qemu_put_mouse_event_head;
 static QEMUPutMouseEntry *qemu_put_mouse_event_current;
 static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers = QTAILQ_HEAD_INITIALIZER(led_handlers);
+static int ledstate;
 
 void qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
 {
@@ -506,15 +507,21 @@ void kbd_put_keycode(int keycode)
     }
 }
 
-void kbd_put_ledstate(int ledstate)
+void kbd_put_ledstate(int l)
 {
     QEMUPutLEDEntry *cursor;
 
+    ledstate = l;
     QTAILQ_FOREACH(cursor, &led_handlers, next) {
         cursor->put_led(cursor->opaque, ledstate);
     }
 }
 
+int kbd_get_ledstate(void)
+{
+    return ledstate;
+}
+
 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
 {
     QEMUPutMouseEvent *mouse_event;
diff --git a/vnc.c b/vnc.c
index ef450a6..4997114 100644
--- a/vnc.c
+++ b/vnc.c
@@ -2449,6 +2449,7 @@ static void vnc_connect(VncDisplay *vd, int csock)
     vnc_read_when(vs, protocol_version, 12);
     reset_keys(vs);
     vs->led = qemu_add_led_event_handler(kbd_leds, vs);
+    kbd_leds(vs, kbd_get_ledstate());
 
     vnc_init_timer(vd);
 
-- 
1.7.0.3

