From 35c95172f83208128ec843412dcf6b8fdb695f74 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 5 Jan 2011 15:29:23 -0200 Subject: [PATCH 18/48] spice: add mouse RH-Author: Gerd Hoffmann Message-id: <1294241382-17988-20-git-send-email-kraxel@redhat.com> Patchwork-id: 15765 O-Subject: [RHEL-6 kvm PATCH 19/38] spice: add mouse Bugzilla: 642131 634153 615947 632458 631832 647865 RH-Acked-by: Uri Lublin RH-Acked-by: Alon Levy RH-Acked-by: Hans de Goede Open mouse channel. Now you can move the guests mouse pointer. No tablet / absolute positioning (yet) though. upstream: 78dd9ac1ca5130ae144a6abe8361a59483a5464b Signed-off-by: Gerd Hoffmann --- ui/spice-input.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 52 insertions(+), 0 deletions(-) Signed-off-by: Luiz Capitulino --- ui/spice-input.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 52 insertions(+), 0 deletions(-) diff --git a/ui/spice-input.c b/ui/spice-input.c index 5538a79..91cf18d 100644 --- a/ui/spice-input.c +++ b/ui/spice-input.c @@ -74,12 +74,64 @@ 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; + + /* + * Note: SPICE_MOUSE_BUTTON_* specifies the wire protocol but this + * isn't what we get passed in via interface callbacks for the + * middle and right button ... + */ + if (spice_buttons & SPICE_MOUSE_BUTTON_MASK_LEFT) { + qemu_buttons |= MOUSE_EVENT_LBUTTON; + } + if (spice_buttons & 0x04 /* SPICE_MOUSE_BUTTON_MASK_MIDDLE */) { + qemu_buttons |= MOUSE_EVENT_MBUTTON; + } + if (spice_buttons & 0x02 /* 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; qemu_spice_add_interface(&kbd->sin.base); qemu_add_led_event_handler(kbd_leds, kbd); + + mouse = qemu_mallocz(sizeof(*mouse)); + mouse->sin.base.sif = &mouse_interface.base; + qemu_spice_add_interface(&mouse->sin.base); } -- 1.7.4.rc1.16.gd2f15e