[Spice-devel] [PATCH 03/10] Add CursorChannelPrivate struct

Jonathon Jongsma jjongsma at redhat.com
Thu Sep 8 16:52:53 UTC 2016


Encapsulate private data of CursorChannel in a private struct. This
isn't very useful at the moment, but it will help prepare the way for
porting the RedChannel heirarchy to GObject.
---
 server/cursor-channel.c | 53 ++++++++++++++++++++++++++++---------------------
 1 file changed, 30 insertions(+), 23 deletions(-)

diff --git a/server/cursor-channel.c b/server/cursor-channel.c
index 080b22b..9b0f493 100644
--- a/server/cursor-channel.c
+++ b/server/cursor-channel.c
@@ -47,9 +47,15 @@ typedef struct RedCursorPipeItem {
     CursorItem *cursor_item;
 } RedCursorPipeItem;
 
+typedef struct CursorChannelPrivate CursorChannelPrivate;
+
 struct CursorChannel {
     CommonGraphicsChannel common; // Must be the first thing
 
+    CursorChannelPrivate *priv;
+};
+
+struct CursorChannelPrivate {
     CursorItem *item;
     int cursor_visible;
     SpicePoint16 cursor_position;
@@ -108,10 +114,10 @@ static void cursor_item_unref(CursorItem *item)
 
 static void cursor_set_item(CursorChannel *cursor, CursorItem *item)
 {
-    if (cursor->item)
-        cursor_item_unref(cursor->item);
+    if (cursor->priv->item)
+        cursor_item_unref(cursor->priv->item);
 
-    cursor->item = item ? cursor_item_ref(item) : NULL;
+    cursor->priv->item = item ? cursor_item_ref(item) : NULL;
 }
 
 static RedPipeItem *new_cursor_pipe_item(RedChannelClient *rcc, void *data, int num)
@@ -202,12 +208,12 @@ static void red_marshall_cursor_init(CursorChannelClient *ccc, SpiceMarshaller *
     cursor_channel = (CursorChannel*)red_channel_client_get_channel(rcc);
 
     red_channel_client_init_send_data(rcc, SPICE_MSG_CURSOR_INIT, NULL);
-    msg.visible = cursor_channel->cursor_visible;
-    msg.position = cursor_channel->cursor_position;
-    msg.trail_length = cursor_channel->cursor_trail_length;
-    msg.trail_frequency = cursor_channel->cursor_trail_frequency;
+    msg.visible = cursor_channel->priv->cursor_visible;
+    msg.position = cursor_channel->priv->cursor_position;
+    msg.trail_length = cursor_channel->priv->cursor_trail_length;
+    msg.trail_frequency = cursor_channel->priv->cursor_trail_frequency;
 
-    cursor_fill(ccc, &msg.cursor, cursor_channel->item, &info);
+    cursor_fill(ccc, &msg.cursor, cursor_channel->priv->item, &info);
     spice_marshall_msg_cursor_init(base_marshaller, &msg);
     add_buf_from_info(base_marshaller, &info);
 }
@@ -242,7 +248,7 @@ static void cursor_marshall(CursorChannelClient *ccc,
 
             red_channel_client_init_send_data(rcc, SPICE_MSG_CURSOR_SET, pipe_item);
             cursor_set.position = cmd->u.set.position;
-            cursor_set.visible = cursor_channel->cursor_visible;
+            cursor_set.visible = cursor_channel->priv->cursor_visible;
 
             cursor_fill(ccc, &cursor_set.cursor, item, &info);
             spice_marshall_msg_cursor_set(m, &cursor_set);
@@ -324,8 +330,9 @@ CursorChannel* cursor_channel_new(RedWorker *worker)
                                      &cbs, red_channel_client_handle_message);
 
     cursor_channel = (CursorChannel *)channel;
-    cursor_channel->cursor_visible = TRUE;
-    cursor_channel->mouse_mode = SPICE_MOUSE_MODE_SERVER;
+    cursor_channel->priv = g_new0(CursorChannelPrivate, 1);
+    cursor_channel->priv->cursor_visible = TRUE;
+    cursor_channel->priv->mouse_mode = SPICE_MOUSE_MODE_SERVER;
 
     return cursor_channel;
 }
@@ -342,20 +349,20 @@ void cursor_channel_process_cmd(CursorChannel *cursor, RedCursorCmd *cursor_cmd)
 
     switch (cursor_cmd->type) {
     case QXL_CURSOR_SET:
-        cursor->cursor_visible = cursor_cmd->u.set.visible;
+        cursor->priv->cursor_visible = cursor_cmd->u.set.visible;
         cursor_set_item(cursor, cursor_item);
         break;
     case QXL_CURSOR_MOVE:
-        cursor_show = !cursor->cursor_visible;
-        cursor->cursor_visible = TRUE;
-        cursor->cursor_position = cursor_cmd->u.position;
+        cursor_show = !cursor->priv->cursor_visible;
+        cursor->priv->cursor_visible = TRUE;
+        cursor->priv->cursor_position = cursor_cmd->u.position;
         break;
     case QXL_CURSOR_HIDE:
-        cursor->cursor_visible = FALSE;
+        cursor->priv->cursor_visible = FALSE;
         break;
     case QXL_CURSOR_TRAIL:
-        cursor->cursor_trail_length = cursor_cmd->u.trail.length;
-        cursor->cursor_trail_frequency = cursor_cmd->u.trail.frequency;
+        cursor->priv->cursor_trail_length = cursor_cmd->u.trail.length;
+        cursor->priv->cursor_trail_frequency = cursor_cmd->u.trail.frequency;
         break;
     default:
         spice_warning("invalid cursor command %u", cursor_cmd->type);
@@ -363,7 +370,7 @@ void cursor_channel_process_cmd(CursorChannel *cursor, RedCursorCmd *cursor_cmd)
     }
 
     if (red_channel_is_connected(&cursor->common.base) &&
-        (cursor->mouse_mode == SPICE_MOUSE_MODE_SERVER
+        (cursor->priv->mouse_mode == SPICE_MOUSE_MODE_SERVER
          || cursor_cmd->type != QXL_CURSOR_MOVE
          || cursor_show)) {
         red_channel_pipes_new_add(&cursor->common.base,
@@ -380,9 +387,9 @@ void cursor_channel_reset(CursorChannel *cursor)
     spice_return_if_fail(cursor);
 
     cursor_set_item(cursor, NULL);
-    cursor->cursor_visible = TRUE;
-    cursor->cursor_position.x = cursor->cursor_position.y = 0;
-    cursor->cursor_trail_length = cursor->cursor_trail_frequency = 0;
+    cursor->priv->cursor_visible = TRUE;
+    cursor->priv->cursor_position.x = cursor->priv->cursor_position.y = 0;
+    cursor->priv->cursor_trail_length = cursor->priv->cursor_trail_frequency = 0;
 
     if (red_channel_is_connected(channel)) {
         red_channel_pipes_add_type(channel, RED_PIPE_ITEM_TYPE_INVAL_CURSOR_CACHE);
@@ -423,7 +430,7 @@ void cursor_channel_set_mouse_mode(CursorChannel *cursor, uint32_t mode)
 {
     spice_return_if_fail(cursor);
 
-    cursor->mouse_mode = mode;
+    cursor->priv->mouse_mode = mode;
 }
 
 void cursor_channel_connect(CursorChannel *cursor, RedClient *client, RedsStream *stream,
-- 
2.7.4



More information about the Spice-devel mailing list