peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0008-spice-add-tablet-support.patch

Justin M. Forbes a81953
From e3c6e18e27f0d598b37e9be1795dbcb42f740071 Mon Sep 17 00:00:00 2001
Justin M. Forbes a81953
From: Gerd Hoffmann <kraxel@redhat.com>
Justin M. Forbes a81953
Date: Tue, 13 Apr 2010 09:05:03 +0200
Justin M. Forbes a81953
Subject: [PATCH 08/39] spice: add tablet support
Justin M. Forbes a81953
Justin M. Forbes a81953
Add support for the spice tablet interface.  The tablet interface will
Justin M. Forbes a81953
be registered (and then used by the spice client) as soon as a absolute
Justin M. Forbes a81953
pointing device is available and used by the guest, i.e. you'll have to
Justin M. Forbes a81953
configure your guest with '-usbdevice tablet'.
Justin M. Forbes a81953
---
Justin M. Forbes a81953
 spice-display.c |    2 +-
Justin M. Forbes a81953
 spice-input.c   |   99 +++++++++++++++++++++++++++++++++++++++++++++++++++----
Justin M. Forbes a81953
 2 files changed, 93 insertions(+), 8 deletions(-)
Justin M. Forbes a81953
Justin M. Forbes a81953
diff --git a/spice-display.c b/spice-display.c
Justin M. Forbes a81953
index 13a620e..a749e64 100644
Justin M. Forbes a81953
--- a/spice-display.c
Justin M. Forbes a81953
+++ b/spice-display.c
Justin M. Forbes a81953
@@ -143,7 +143,7 @@ void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd)
Justin M. Forbes a81953
     surface.width      = ds_get_width(ssd->ds);
Justin M. Forbes a81953
     surface.height     = ds_get_height(ssd->ds);
Justin M. Forbes a81953
     surface.stride     = -surface.width * 4;
Justin M. Forbes a81953
-    surface.mouse_mode = 0;
Justin M. Forbes a81953
+    surface.mouse_mode = true;
Justin M. Forbes a81953
     surface.flags      = 0;
Justin M. Forbes a81953
     surface.type       = 0;
Justin M. Forbes a81953
     surface.mem        = (intptr_t)ssd->buf;
Justin M. Forbes a81953
diff --git a/spice-input.c b/spice-input.c
Justin M. Forbes a81953
index 8f3deb4..5646ff9 100644
Justin M. Forbes a81953
--- a/spice-input.c
Justin M. Forbes a81953
+++ b/spice-input.c
Justin M. Forbes a81953
@@ -1,5 +1,6 @@
Justin M. Forbes a81953
 #include <stdlib.h>
Justin M. Forbes a81953
 #include <stdio.h>
Justin M. Forbes a81953
+#include <stdbool.h>
Justin M. Forbes a81953
 #include <string.h>
Justin M. Forbes a81953
Justin M. Forbes a81953
 #include <spice.h>
Justin M. Forbes a81953
@@ -48,9 +49,13 @@ static void kbd_leds(void *opaque, int ledstate)
Justin M. Forbes a81953
Justin M. Forbes a81953
 /* mouse bits */
Justin M. Forbes a81953
Justin M. Forbes a81953
-typedef struct QemuSpiceMouse {
Justin M. Forbes a81953
-    SpiceMouseInstance sin;
Justin M. Forbes a81953
-} QemuSpiceMouse;
Justin M. Forbes a81953
+typedef struct QemuSpicePointer {
Justin M. Forbes a81953
+    SpiceMouseInstance  mouse;
Justin M. Forbes a81953
+    SpiceTabletInstance tablet;
Justin M. Forbes a81953
+    int width, height, x, y;
Justin M. Forbes a81953
+    Notifier mouse_mode;
Justin M. Forbes a81953
+    bool absolute;
Justin M. Forbes a81953
+} QemuSpicePointer;
Justin M. Forbes a81953
Justin M. Forbes a81953
 static void mouse_motion(SpiceMouseInstance *sin, int dx, int dy, int dz,
Justin M. Forbes a81953
                          uint32_t buttons_state)
Justin M. Forbes a81953
@@ -72,17 +77,97 @@ static const SpiceMouseInterface mouse_interface = {
Justin M. Forbes a81953
     .buttons            = mouse_buttons,
Justin M. Forbes a81953
 };
Justin M. Forbes a81953
Justin M. Forbes a81953
+static void tablet_set_logical_size(SpiceTabletInstance* sin, int width, int height)
Justin M. Forbes a81953
+{
Justin M. Forbes a81953
+    QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+    fprintf(stderr, "%s: %dx%d\n", __FUNCTION__, width, height);
Justin M. Forbes a81953
+    if (height < 16)
Justin M. Forbes a81953
+        height = 16;
Justin M. Forbes a81953
+    if (width < 16)
Justin M. Forbes a81953
+        width = 16;
Justin M. Forbes a81953
+    pointer->width  = width;
Justin M. Forbes a81953
+    pointer->height = height;
Justin M. Forbes a81953
+}
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+static void tablet_position(SpiceTabletInstance* sin, int x, int y,
Justin M. Forbes a81953
+                            uint32_t buttons_state)
Justin M. Forbes a81953
+{
Justin M. Forbes a81953
+    QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+    pointer->x = x * 0x7FFF / (pointer->width - 1);
Justin M. Forbes a81953
+    pointer->y = y * 0x7FFF / (pointer->height - 1);
Justin M. Forbes a81953
+    kbd_mouse_event(pointer->x, pointer->y, 0, buttons_state);
Justin M. Forbes a81953
+}
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+static void tablet_wheel(SpiceTabletInstance* sin, int wheel,
Justin M. Forbes a81953
+                         uint32_t buttons_state)
Justin M. Forbes a81953
+{
Justin M. Forbes a81953
+    QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+    kbd_mouse_event(pointer->x, pointer->y, wheel, buttons_state);
Justin M. Forbes a81953
+}
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+static void tablet_buttons(SpiceTabletInstance *sin,
Justin M. Forbes a81953
+                           uint32_t buttons_state)
Justin M. Forbes a81953
+{
Justin M. Forbes a81953
+    QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+    kbd_mouse_event(pointer->x, pointer->y, 0, buttons_state);
Justin M. Forbes a81953
+}
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+static const SpiceTabletInterface tablet_interface = {
Justin M. Forbes a81953
+    .base.type          = SPICE_INTERFACE_TABLET,
Justin M. Forbes a81953
+    .base.description   = "tablet",
Justin M. Forbes a81953
+    .base.major_version = SPICE_INTERFACE_TABLET_MAJOR,
Justin M. Forbes a81953
+    .base.minor_version = SPICE_INTERFACE_TABLET_MINOR,
Justin M. Forbes a81953
+    .set_logical_size   = tablet_set_logical_size,
Justin M. Forbes a81953
+    .position           = tablet_position,
Justin M. Forbes a81953
+    .wheel              = tablet_wheel,
Justin M. Forbes a81953
+    .buttons            = tablet_buttons,
Justin M. Forbes a81953
+};
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+static void mouse_mode_notifier(Notifier *notifier)
Justin M. Forbes a81953
+{
Justin M. Forbes a81953
+    QemuSpicePointer *pointer = container_of(notifier, QemuSpicePointer, mouse_mode);
Justin M. Forbes a81953
+    bool is_absolute  = kbd_mouse_is_absolute();
Justin M. Forbes a81953
+    bool has_absolute = kbd_mouse_has_absolute();
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+    fprintf(stderr, "%s: absolute pointer: %s%s\n", __FUNCTION__,
Justin M. Forbes a81953
+            has_absolute ? "present" : "not available",
Justin M. Forbes a81953
+            is_absolute  ? "+active" : "");
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+    if (pointer->absolute == is_absolute)
Justin M. Forbes a81953
+        return;
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+    if (is_absolute) {
Justin M. Forbes a81953
+        fprintf(stderr, "%s: using absolute pointer (client mode)\n", __FUNCTION__);
Justin M. Forbes a81953
+        spice_server_add_interface(spice_server, &pointer->tablet.base);
Justin M. Forbes a81953
+    } else {
Justin M. Forbes a81953
+        fprintf(stderr, "%s: using relative pointer (server mode)\n", __FUNCTION__);
Justin M. Forbes a81953
+        spice_server_remove_interface(&pointer->tablet.base);
Justin M. Forbes a81953
+    }
Justin M. Forbes a81953
+    pointer->absolute = is_absolute;
Justin M. Forbes a81953
+}
Justin M. Forbes a81953
+
Justin M. Forbes a81953
 void qemu_spice_input_init(void)
Justin M. Forbes a81953
 {
Justin M. Forbes a81953
     QemuSpiceKbd *kbd;
Justin M. Forbes a81953
-    QemuSpiceMouse *mouse;
Justin M. Forbes a81953
+    QemuSpicePointer *pointer;
Justin M. Forbes a81953
Justin M. Forbes a81953
     kbd = qemu_mallocz(sizeof(*kbd));
Justin M. Forbes a81953
     kbd->sin.base.sif = &kbd_interface.base;
Justin M. Forbes a81953
     spice_server_add_interface(spice_server, &kbd->sin.base);
Justin M. Forbes a81953
     qemu_add_led_event_handler(kbd_leds, kbd);
Justin M. Forbes a81953
Justin M. Forbes a81953
-    mouse = qemu_mallocz(sizeof(*mouse));
Justin M. Forbes a81953
-    mouse->sin.base.sif = &mouse_interface.base;
Justin M. Forbes a81953
-    spice_server_add_interface(spice_server, &mouse->sin.base);
Justin M. Forbes a81953
+    pointer = qemu_mallocz(sizeof(*pointer));
Justin M. Forbes a81953
+    pointer->mouse.base.sif  = &mouse_interface.base;
Justin M. Forbes a81953
+    pointer->tablet.base.sif = &tablet_interface.base;
Justin M. Forbes a81953
+    spice_server_add_interface(spice_server, &pointer->mouse.base);
Justin M. Forbes a81953
+
Justin M. Forbes a81953
+    pointer->absolute = false;
Justin M. Forbes a81953
+    pointer->mouse_mode.notify = mouse_mode_notifier;
Justin M. Forbes a81953
+    qemu_add_mouse_mode_change_notifier(&pointer->mouse_mode);
Justin M. Forbes a81953
+    mouse_mode_notifier(&pointer->mouse_mode);
Justin M. Forbes a81953
 }
Justin M. Forbes a81953
-- 
Justin M. Forbes a81953
1.7.2.3
Justin M. Forbes a81953