[Spice-devel] [PATCH xf86-video-qxl v2 04/11] spiceqxl_inputs: expose buttons & position api for agent usage

Alon Levy alevy at redhat.com
Sun Sep 8 05:11:46 PDT 2013


Signed-off-by: Alon Levy <alevy at redhat.com>
---
 src/spiceqxl_inputs.c | 41 +++++++++++++++++++++++++----------------
 src/spiceqxl_inputs.h |  2 ++
 2 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/src/spiceqxl_inputs.c b/src/spiceqxl_inputs.c
index 2b8a15e..b39eeae 100644
--- a/src/spiceqxl_inputs.c
+++ b/src/spiceqxl_inputs.c
@@ -270,6 +270,8 @@ typedef struct XSpicePointer {
     InputInfoPtr     pInfo; /* xf86 device handle to post events */
 } XSpicePointer;
 
+static XSpicePointer *g_xspice_pointer;
+
 static void mouse_motion(SpiceMouseInstance *sin, int dx, int dy, int dz,
                          uint32_t buttons_state)
 {
@@ -304,22 +306,35 @@ static void tablet_set_logical_size(SpiceTabletInstance* sin, int width, int hei
     spice_pointer->height = height;
 }
 
+void spiceqxl_tablet_position(int x, int y, uint32_t buttons_state)
+{
+    // TODO: don't ignore buttons_state
+    xf86PostMotionEvent(g_xspice_pointer->pInfo->dev, 1, 0, 2, x, y);
+}
+
 static void tablet_position(SpiceTabletInstance* sin, int x, int y,
                             uint32_t buttons_state)
 {
-    XSpicePointer *spice_pointer = container_of(sin, XSpicePointer, tablet);
-
-    // TODO: don't ignore buttons_state
-    xf86PostMotionEvent(spice_pointer->pInfo->dev, 1, 0, 2, x, y);
+    spiceqxl_tablet_position(x, y, buttons_state);
 }
 
-static void tablet_buttons(SpiceTabletInstance *sin,
-                           uint32_t buttons_state)
+void spiceqxl_tablet_buttons(uint32_t buttons_state)
 {
-    XSpicePointer *spice_pointer = container_of(sin, XSpicePointer, tablet);
     static uint32_t old_buttons_state = 0;
     int i;
 
+    for (i = 0; i < BUTTONS; i++) {
+        if ((buttons_state ^ old_buttons_state) & (1 << i)) {
+            int action = (buttons_state & (1 << i));
+            xf86PostButtonEvent(g_xspice_pointer->pInfo->dev, 0, i + 1, action, 0, 0);
+        }
+    }
+    old_buttons_state = buttons_state;
+}
+
+static void tablet_buttons(SpiceTabletInstance *sin,
+                           uint32_t buttons_state)
+{
     // For some reason spice switches the second and third button, undo that.
     // basically undo RED_MOUSE_STATE_TO_LOCAL
     buttons_state = (buttons_state & SPICE_MOUSE_BUTTON_MASK_LEFT) |
@@ -327,14 +342,7 @@ static void tablet_buttons(SpiceTabletInstance *sin,
         ((buttons_state & SPICE_MOUSE_BUTTON_MASK_RIGHT) >> 1) |
         (buttons_state & ~(SPICE_MOUSE_BUTTON_MASK_LEFT | SPICE_MOUSE_BUTTON_MASK_MIDDLE
                           |SPICE_MOUSE_BUTTON_MASK_RIGHT));
-
-    for (i = 0; i < BUTTONS; i++) {
-        if ((buttons_state ^ old_buttons_state) & (1 << i)) {
-            int action = (buttons_state & (1 << i));
-            xf86PostButtonEvent(spice_pointer->pInfo->dev, 0, i + 1, action, 0, 0);
-        }
-    }
-    old_buttons_state = buttons_state;
+    spiceqxl_tablet_buttons(buttons_state);
 }
 
 static void tablet_wheel(SpiceTabletInstance* sin, int wheel,
@@ -358,6 +366,7 @@ static const SpiceTabletInterface tablet_interface = {
 };
 
 static char unknown_type_string[] = "UNKNOWN";
+
 static int
 XSpiceKeyboardPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
 {
@@ -382,7 +391,7 @@ XSpicePointerPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags)
 {
     XSpicePointer *spice_pointer;
 
-    spice_pointer = calloc(sizeof(*spice_pointer), 1);
+    g_xspice_pointer = spice_pointer = calloc(sizeof(*spice_pointer), 1);
     spice_pointer->mouse.base.sif  = &mouse_interface.base;
     spice_pointer->tablet.base.sif = &tablet_interface.base;
     spice_pointer->absolute = TRUE;
diff --git a/src/spiceqxl_inputs.h b/src/spiceqxl_inputs.h
index 8b2c815..9ff78cf 100644
--- a/src/spiceqxl_inputs.h
+++ b/src/spiceqxl_inputs.h
@@ -26,5 +26,7 @@
 #include "qxl.h"
 
 void xspice_add_input_drivers(pointer module);
+void spiceqxl_tablet_buttons(uint32_t buttons_state);
+void spiceqxl_tablet_position(int x, int y, uint32_t buttons_state);
 
 #endif // QXL_SPICE_INPUTS_H
-- 
1.8.3.1



More information about the Spice-devel mailing list