input: make vnc use mouse mode notifiers
authorAnthony Liguori <aliguori@us.ibm.com>
Wed, 10 Mar 2010 15:38:29 +0000 (09:38 -0600)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 19 Mar 2010 20:27:38 +0000 (15:27 -0500)
When we switch to absolute mode, we send out a notification (if the client
supports it).  Today, we only send this notification when the client sends us
a mouse event and we're in the wrong mode.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
vnc.c
vnc.h

diff --git a/vnc.c b/vnc.c
index 088e1c67f14cb5bd77b57b12b19446d074b6e500..e678fccac0887032af55edb3b7914e477c57ca7a 100644 (file)
--- a/vnc.c
+++ b/vnc.c
@@ -1109,6 +1109,7 @@ static void vnc_disconnect_finish(VncState *vs)
         dcl->idle = 1;
     }
 
+    qemu_remove_mouse_mode_change_notifier(&vs->mouse_mode_notifier);
     vnc_remove_timer(vs->vd);
     if (vs->vd->lock_key_sync)
         qemu_remove_led_event_handler(vs->led);
@@ -1427,8 +1428,11 @@ static void client_cut_text(VncState *vs, size_t len, uint8_t *text)
 {
 }
 
-static void check_pointer_type_change(VncState *vs, int absolute)
+static void check_pointer_type_change(Notifier *notifier)
 {
+    VncState *vs = container_of(notifier, VncState, mouse_mode_notifier);
+    int absolute = kbd_mouse_is_absolute();
+
     if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE) && vs->absolute != absolute) {
         vnc_write_u8(vs, 0);
         vnc_write_u8(vs, 0);
@@ -1476,8 +1480,6 @@ static void pointer_event(VncState *vs, int button_mask, int x, int y)
         vs->last_x = x;
         vs->last_y = y;
     }
-
-    check_pointer_type_change(vs, kbd_mouse_is_absolute());
 }
 
 static void reset_keys(VncState *vs)
@@ -1818,8 +1820,6 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
             break;
         }
     }
-
-    check_pointer_type_change(vs, kbd_mouse_is_absolute());
 }
 
 static void set_pixel_conversion(VncState *vs)
@@ -2436,6 +2436,9 @@ static void vnc_connect(VncDisplay *vd, int csock)
     if (vs->vd->lock_key_sync)
         vs->led = qemu_add_led_event_handler(kbd_leds, vs);
 
+    vs->mouse_mode_notifier.notify = check_pointer_type_change;
+    qemu_add_mouse_mode_change_notifier(&vs->mouse_mode_notifier);
+
     vnc_init_timer(vd);
 
     /* vs might be free()ed here */
diff --git a/vnc.h b/vnc.h
index a4211ae687eee53069652dde54abde1f763aec6f..0a7487bdb279025553f5aead74c035c50bc1c138 100644 (file)
--- a/vnc.h
+++ b/vnc.h
@@ -168,6 +168,8 @@ struct VncState
     Buffer zlib_tmp;
     z_stream zlib_stream[4];
 
+    Notifier mouse_mode_notifier;
+
     QTAILQ_ENTRY(VncState) next;
 };