[Spice-devel] [PATCH 25/35] TabletInterface: redesign

Gerd Hoffmann kraxel at redhat.com
Wed May 12 04:32:19 PDT 2010


---
 server/reds.c         |   41 ++++++++++++++++++++++++++---------------
 server/reds.h         |    4 ++++
 server/vd_interface.h |   27 +++++++++++++++++----------
 3 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index 62a2cab..24b1507 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -58,7 +58,7 @@ SpiceCoreInterface *core = NULL;
 static MigrationInterface *mig = NULL;
 static SpiceKbdInstance *keyboard = NULL;
 static SpiceMouseInstance *mouse = NULL;
-static TabletInterface *tablet = NULL;
+static SpiceTabletInstance *tablet = NULL;
 static VDIPortInterface *vdagent = NULL;
 
 #define MIGRATION_NOTIFY_SPICE_KEY "spice_mig_ext"
@@ -2192,7 +2192,9 @@ static void inputs_handle_input(void *opaque, SpiceDataHeader *header)
         }
         ASSERT((agent_mouse && vdagent) || tablet);
         if (!agent_mouse || !vdagent) {
-            tablet->position(tablet, pos->x, pos->y, RED_MOUSE_STATE_TO_LOCAL(pos->buttons_state));
+            SpiceTabletInterface *sif;
+            sif = SPICE_CONTAINEROF(tablet->base.sif, SpiceTabletInterface, base);
+            sif->position(tablet, pos->x, pos->y, RED_MOUSE_STATE_TO_LOCAL(pos->buttons_state));
             break;
         }
         VDAgentMouseState *mouse_state = &state->mouse_state;
@@ -2219,7 +2221,9 @@ static void inputs_handle_input(void *opaque, SpiceDataHeader *header)
                     (dz == 1 ? VD_AGENT_DBUTTON_MASK : 0);
                 reds_handle_agent_mouse_event();
             } else if (tablet) {
-                tablet->wheel(tablet, dz, RED_MOUSE_STATE_TO_LOCAL(mouse_press->buttons_state));
+                SpiceTabletInterface *sif;
+                sif = SPICE_CONTAINEROF(tablet->base.sif, SpiceTabletInterface, base);
+                sif->wheel(tablet, dz, RED_MOUSE_STATE_TO_LOCAL(mouse_press->buttons_state));
             }
         } else if (mouse) {
             SpiceMouseInterface *sif;
@@ -2237,7 +2241,9 @@ static void inputs_handle_input(void *opaque, SpiceDataHeader *header)
                     RED_MOUSE_BUTTON_STATE_TO_AGENT(mouse_release->buttons_state);
                 reds_handle_agent_mouse_event();
             } else if (tablet) {
-                tablet->buttons(tablet, RED_MOUSE_STATE_TO_LOCAL(mouse_release->buttons_state));
+                SpiceTabletInterface *sif;
+                sif = SPICE_CONTAINEROF(tablet->base.sif, SpiceTabletInterface, base);
+                sif->buttons(tablet, RED_MOUSE_STATE_TO_LOCAL(mouse_release->buttons_state));
             }
         } else if (mouse) {
             SpiceMouseInterface *sif;
@@ -2285,7 +2291,9 @@ void reds_set_client_mouse_allowed(int is_client_mouse_allowed, int x_res, int y
     reds->dispatcher_allows_client_mouse = is_client_mouse_allowed;
     reds_update_mouse_mode();
     if (reds->is_client_mouse_allowed && tablet) {
-        tablet->set_logical_size(tablet, reds->monitor_mode.x_res, reds->monitor_mode.y_res);
+        SpiceTabletInterface *sif;
+        sif = SPICE_CONTAINEROF(tablet->base.sif, SpiceTabletInterface, base);
+        sif->set_logical_size(tablet, reds->monitor_mode.x_res, reds->monitor_mode.y_res);
     }
 }
 
@@ -4097,22 +4105,25 @@ __visible__ int spice_server_add_interface(SpiceServer *s,
         qxl->st->qif = SPICE_CONTAINEROF(interface, QXLInterface, base);
         qxl->st->dispatcher = red_dispatcher_init(qxl);
 
-    } else if (strcmp(interface->type, VD_INTERFACE_TABLET) == 0) {
-        red_printf("VD_INTERFACE_TABLET");
+    } else if (strcmp(interface->type, SPICE_INTERFACE_TABLET) == 0) {
+        red_printf("SPICE_INTERFACE_TABLET");
         if (tablet) {
             red_printf("already have tablet");
             return -1;
         }
-        if (interface->major_version != VD_INTERFACE_TABLET_MAJOR ||
-            interface->minor_version < VD_INTERFACE_TABLET_MINOR) {
+        if (interface->major_version != SPICE_INTERFACE_TABLET_MAJOR ||
+            interface->minor_version < SPICE_INTERFACE_TABLET_MINOR) {
             red_printf("unsuported tablet interface");
             return -1;
         }
-        tablet = (TabletInterface *)interface;
+        tablet = SPICE_CONTAINEROF(sin, SpiceTabletInstance, base);
+        tablet->st = spice_new0(SpiceTabletState, 1);
         reds_update_mouse_mode();
         if (reds->is_client_mouse_allowed) {
-            tablet->set_logical_size(tablet, reds->monitor_mode.x_res,
-                                     reds->monitor_mode.y_res);
+            SpiceTabletInterface *sif;
+            sif = SPICE_CONTAINEROF(tablet->base.sif, SpiceTabletInterface, base);
+            sif->set_logical_size(tablet, reds->monitor_mode.x_res,
+                                  reds->monitor_mode.y_res);
         }
 
     } else if (strcmp(interface->type, VD_INTERFACE_PLAYBACK) == 0) {
@@ -4172,9 +4183,9 @@ __visible__ int spice_server_remove_interface(SpiceBaseInstance *sin)
 {
     SpiceBaseInterface *interface = sin->sif;
 
-    if (strcmp(interface->type, VD_INTERFACE_TABLET) == 0) {
-        red_printf("remove VD_INTERFACE_TABLET");
-        if (interface == (SpiceBaseInterface *)tablet) {
+    if (strcmp(interface->type, SPICE_INTERFACE_TABLET) == 0) {
+        red_printf("remove SPICE_INTERFACE_TABLET");
+        if (sin == &tablet->base) {
             tablet = NULL;
             reds_update_mouse_mode();
         }
diff --git a/server/reds.h b/server/reds.h
index b3dcd4b..78581f8 100644
--- a/server/reds.h
+++ b/server/reds.h
@@ -66,6 +66,10 @@ struct SpiceMouseState {
     int dummy;
 };
 
+struct SpiceTabletState {
+    int dummy;
+};
+
 struct QXLState {
     QXLInterface          *qif;
     struct RedDispatcher  *dispatcher;
diff --git a/server/vd_interface.h b/server/vd_interface.h
index bbe8436..6b1315a 100644
--- a/server/vd_interface.h
+++ b/server/vd_interface.h
@@ -246,18 +246,25 @@ struct SpiceMouseInstance {
     SpiceMouseState   *st;
 };
 
-#define VD_INTERFACE_TABLET "tablet"
-#define VD_INTERFACE_TABLET_MAJOR 1
-#define VD_INTERFACE_TABLET_MINOR 1
-typedef struct TabletInterface TabletInterface;
-
-struct TabletInterface {
+#define SPICE_INTERFACE_TABLET "tablet"
+#define SPICE_INTERFACE_TABLET_MAJOR 1
+#define SPICE_INTERFACE_TABLET_MINOR 1
+typedef struct SpiceTabletInterface SpiceTabletInterface;
+typedef struct SpiceTabletInstance SpiceTabletInstance;
+typedef struct SpiceTabletState SpiceTabletState;
+
+struct SpiceTabletInterface {
     SpiceBaseInterface base;
 
-    void (*set_logical_size)(TabletInterface* tablet, int width, int height);
-    void (*position)(TabletInterface* tablet, int x, int y, uint32_t buttons_state);
-    void (*wheel)(TabletInterface* tablet, int wheel_moution, uint32_t buttons_state);
-    void (*buttons)(TabletInterface* tablet, uint32_t buttons_state);
+    void (*set_logical_size)(SpiceTabletInstance* tablet, int width, int height);
+    void (*position)(SpiceTabletInstance* tablet, int x, int y, uint32_t buttons_state);
+    void (*wheel)(SpiceTabletInstance* tablet, int wheel_moution, uint32_t buttons_state);
+    void (*buttons)(SpiceTabletInstance* tablet, uint32_t buttons_state);
+};
+
+struct SpiceTabletInstance {
+    SpiceBaseInstance base;
+    SpiceTabletState  *st;
 };
 
 #define VD_INTERFACE_MIGRATION "migration"
-- 
1.6.6.1



More information about the Spice-devel mailing list