[Spice-devel] [PATCH spice-server 1/2] Move CursorChannel definition to header

Jonathon Jongsma jjongsma at redhat.com
Tue Mar 19 15:21:59 UTC 2019


This way, the cursor channel can be subclassed. This will be used in
future commits as I refactor the client callbacks.
---
 server/cursor-channel.c | 62 +++++++++++++++++++----------------------
 server/cursor-channel.h | 12 ++++++++
 2 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/server/cursor-channel.c b/server/cursor-channel.c
index 4220084f5..d751211af 100644
--- a/server/cursor-channel.c
+++ b/server/cursor-channel.c
@@ -32,10 +32,8 @@ typedef struct RedCursorPipeItem {
     RedCursorCmd *red_cursor;
 } RedCursorPipeItem;
 
-struct CursorChannel
+struct CursorChannelPrivate
 {
-    CommonGraphicsChannel parent;
-
     RedCursorPipeItem *item;
     bool cursor_visible;
     SpicePoint16 cursor_position;
@@ -44,12 +42,7 @@ struct CursorChannel
     uint32_t mouse_mode;
 };
 
-struct CursorChannelClass
-{
-    CommonGraphicsChannelClass parent_class;
-};
-
-G_DEFINE_TYPE(CursorChannel, cursor_channel, TYPE_COMMON_GRAPHICS_CHANNEL)
+G_DEFINE_TYPE_WITH_PRIVATE(CursorChannel, cursor_channel, TYPE_COMMON_GRAPHICS_CHANNEL)
 
 static void cursor_pipe_item_free(RedPipeItem *pipe_item);
 
@@ -79,10 +72,10 @@ static void cursor_channel_set_item(CursorChannel *cursor, RedCursorPipeItem *it
     if (item) {
         red_pipe_item_ref(&item->base);
     }
-    if (cursor->item) {
-        red_pipe_item_unref(&cursor->item->base);
+    if (cursor->priv->item) {
+        red_pipe_item_unref(&cursor->priv->item->base);
     }
-    cursor->item = item;
+    cursor->priv->item = item;
 }
 
 static void cursor_fill(CursorChannelClient *ccc, RedCursorPipeItem *cursor,
@@ -128,12 +121,12 @@ static void red_marshall_cursor_init(CursorChannelClient *ccc, SpiceMarshaller *
     cursor_channel = CURSOR_CHANNEL(red_channel_client_get_channel(rcc));
 
     red_channel_client_init_send_data(rcc, SPICE_MSG_CURSOR_INIT);
-    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, cursor_channel->item, &msg.cursor, base_marshaller);
+    cursor_fill(ccc, cursor_channel->priv->item, &msg.cursor, base_marshaller);
     spice_marshall_msg_cursor_init(base_marshaller, &msg);
 }
 
@@ -164,7 +157,7 @@ static void red_marshall_cursor(CursorChannelClient *ccc,
 
             red_channel_client_init_send_data(rcc, SPICE_MSG_CURSOR_SET);
             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, item, &cursor_set.cursor, m);
             spice_marshall_msg_cursor_set(m, &cursor_set);
@@ -253,20 +246,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_channel_set_item(cursor, cursor_pipe_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);
@@ -275,7 +268,7 @@ void cursor_channel_process_cmd(CursorChannel *cursor, RedCursorCmd *cursor_cmd)
     }
 
     if (red_channel_is_connected(RED_CHANNEL(cursor)) &&
-        (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_add(RED_CHANNEL(cursor), &cursor_pipe_item->base);
@@ -291,9 +284,9 @@ void cursor_channel_reset(CursorChannel *cursor)
     spice_return_if_fail(cursor);
 
     cursor_channel_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);
@@ -330,7 +323,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, RedStream *stream,
@@ -359,8 +352,8 @@ cursor_channel_finalize(GObject *object)
 {
     CursorChannel *self = CURSOR_CHANNEL(object);
 
-    if (self->item) {
-        red_pipe_item_unref(&self->item->base);
+    if (self->priv->item) {
+        red_pipe_item_unref(&self->priv->item->base);
     }
 
     G_OBJECT_CLASS(cursor_channel_parent_class)->finalize(object);
@@ -395,6 +388,7 @@ cursor_channel_class_init(CursorChannelClass *klass)
 static void
 cursor_channel_init(CursorChannel *self)
 {
-    self->cursor_visible = true;
-    self->mouse_mode = SPICE_MOUSE_MODE_SERVER;
+    self->priv = cursor_channel_get_instance_private(self);
+    self->priv->cursor_visible = true;
+    self->priv->mouse_mode = SPICE_MOUSE_MODE_SERVER;
 }
diff --git a/server/cursor-channel.h b/server/cursor-channel.h
index 603c2c0ac..598c5801c 100644
--- a/server/cursor-channel.h
+++ b/server/cursor-channel.h
@@ -30,7 +30,19 @@ G_BEGIN_DECLS
  * A pointer to CursorChannel can be converted to a RedChannel.
  */
 typedef struct CursorChannel CursorChannel;
+typedef struct CursorChannelPrivate CursorChannelPrivate;
+struct CursorChannel
+{
+    CommonGraphicsChannel parent;
+    CursorChannelPrivate *priv;
+};
+
 typedef struct CursorChannelClass CursorChannelClass;
+struct CursorChannelClass
+{
+    CommonGraphicsChannelClass parent_class;
+};
+
 
 #define TYPE_CURSOR_CHANNEL cursor_channel_get_type()
 
-- 
2.17.2



More information about the Spice-devel mailing list