[Spice-devel] [PATCH spice-server v6 18/19] stream-device: Implement mouse movement

Frediano Ziglio fziglio at redhat.com
Thu Oct 12 14:52:14 UTC 2017


Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Jonathon Jongsma <jjongsma at redhat.com>
---
 server/stream-device.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/server/stream-device.c b/server/stream-device.c
index 6210cb5a5..3c3d35dcb 100644
--- a/server/stream-device.c
+++ b/server/stream-device.c
@@ -64,7 +64,8 @@ G_DEFINE_TYPE(StreamDevice, stream_device, RED_TYPE_CHAR_DEVICE)
 typedef bool StreamMsgHandler(StreamDevice *dev, SpiceCharDeviceInstance *sin)
     SPICE_GNUC_WARN_UNUSED_RESULT;
 
-static StreamMsgHandler handle_msg_format, handle_msg_data, handle_msg_cursor_set;
+static StreamMsgHandler handle_msg_format, handle_msg_data, handle_msg_cursor_set,
+    handle_msg_cursor_move;
 
 static bool handle_msg_invalid(StreamDevice *dev, SpiceCharDeviceInstance *sin,
                                const char *error_msg) SPICE_GNUC_WARN_UNUSED_RESULT;
@@ -115,6 +116,13 @@ stream_device_read_msg_from_dev(RedCharDevice *self, SpiceCharDeviceInstance *si
     case STREAM_TYPE_CURSOR_SET:
         handled = handle_msg_cursor_set(dev, sin);
         break;
+    case STREAM_TYPE_CURSOR_MOVE:
+        if (dev->hdr.size != sizeof(StreamMsgCursorMove)) {
+            handled = handle_msg_invalid(dev, sin, "Wrong size for StreamMsgCursorMove");
+        } else {
+            handled = handle_msg_cursor_move(dev, sin);
+        }
+        break;
     case STREAM_TYPE_CAPABILITIES:
         /* FIXME */
     default:
@@ -304,6 +312,31 @@ handle_msg_cursor_set(StreamDevice *dev, SpiceCharDeviceInstance *sin)
     return true;
 }
 
+static bool
+handle_msg_cursor_move(StreamDevice *dev, SpiceCharDeviceInstance *sin)
+{
+    StreamMsgCursorMove move;
+    SpiceCharDeviceInterface *sif = spice_char_device_get_interface(sin);
+    int n = sif->read(sin, (uint8_t *) &move, sizeof(move));
+    if (n == 0) {
+        return false;
+    }
+    if (n != sizeof(move)) {
+        return handle_msg_invalid(dev, sin, NULL);
+    }
+    move.x = GINT32_FROM_LE(move.x);
+    move.y = GINT32_FROM_LE(move.y);
+
+    RedCursorCmd *cmd = g_new0(RedCursorCmd, 1);
+    cmd->type = QXL_CURSOR_MOVE;
+    cmd->u.position.x = move.x;
+    cmd->u.position.y = move.y;
+
+    cursor_channel_process_cmd(dev->cursor_channel, cmd);
+
+    return true;
+}
+
 static void
 stream_device_send_msg_to_client(RedCharDevice *self, RedPipeItem *msg, RedClient *client)
 {
-- 
2.13.6



More information about the Spice-devel mailing list