Patchwork [v3,08/10] spice: add mouse

login
register
mail settings
Submitter Gerd Hoffmann
Date Aug. 25, 2010, 2:19 p.m.
Message ID <1282745970-11506-9-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/62687/
State New
Headers show

Comments

Gerd Hoffmann - Aug. 25, 2010, 2:19 p.m.
Open mouse channel.  Now you can move the guests mouse pointer.
No tablet / absolute positioning (yet) though.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/spice-input.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

Patch

diff --git a/ui/spice-input.c b/ui/spice-input.c
index d4f44f4..130760d 100644
--- a/ui/spice-input.c
+++ b/ui/spice-input.c
@@ -71,12 +71,56 @@  static void kbd_leds(void *opaque, int ledstate)
     spice_server_kbd_leds(&kbd->sin, ledstate);
 }
 
+/* mouse bits */
+
+typedef struct QemuSpiceMouse {
+    SpiceMouseInstance sin;
+} QemuSpiceMouse;
+
+static int map_buttons(int spice_buttons)
+{
+    int qemu_buttons = 0;
+
+    if (spice_buttons & SPICE_MOUSE_BUTTON_MASK_LEFT)
+        qemu_buttons |= MOUSE_EVENT_LBUTTON;
+    if (spice_buttons & SPICE_MOUSE_BUTTON_MASK_MIDDLE)
+        qemu_buttons |= MOUSE_EVENT_MBUTTON;
+    if (spice_buttons & SPICE_MOUSE_BUTTON_MASK_RIGHT)
+        qemu_buttons |= MOUSE_EVENT_RBUTTON;
+    return qemu_buttons;
+}
+
+static void mouse_motion(SpiceMouseInstance *sin, int dx, int dy, int dz,
+                         uint32_t buttons_state)
+{
+    kbd_mouse_event(dx, dy, dz, map_buttons(buttons_state));
+}
+
+static void mouse_buttons(SpiceMouseInstance *sin, uint32_t buttons_state)
+{
+    kbd_mouse_event(0, 0, 0, map_buttons(buttons_state));
+}
+
+static const SpiceMouseInterface mouse_interface = {
+    .base.type          = SPICE_INTERFACE_MOUSE,
+    .base.description   = "mouse",
+    .base.major_version = SPICE_INTERFACE_MOUSE_MAJOR,
+    .base.minor_version = SPICE_INTERFACE_MOUSE_MINOR,
+    .motion             = mouse_motion,
+    .buttons            = mouse_buttons,
+};
+
 void qemu_spice_input_init(void)
 {
     QemuSpiceKbd *kbd;
+    QemuSpiceMouse *mouse;
 
     kbd = qemu_mallocz(sizeof(*kbd));
     kbd->sin.base.sif = &kbd_interface.base;
     spice_server_add_interface(spice_server, &kbd->sin.base);
     qemu_add_led_event_handler(kbd_leds, kbd);
+
+    mouse = qemu_mallocz(sizeof(*mouse));
+    mouse->sin.base.sif = &mouse_interface.base;
+    spice_server_add_interface(spice_server, &mouse->sin.base);
 }