From 1a96c5b41506b67aad556f885ad4a424812e2930 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Fri, 10 Mar 2017 12:27:24 -0800 Subject: [PATCH] GUACAMOLE-231: Add "mouse" instruction for server reporting of mouse position. --- src/libguac/guacamole/protocol.h | 20 ++++++++++++++++++++ src/libguac/protocol.c | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/libguac/guacamole/protocol.h b/src/libguac/guacamole/protocol.h index 638d7b28..88a0a185 100644 --- a/src/libguac/guacamole/protocol.h +++ b/src/libguac/guacamole/protocol.h @@ -144,6 +144,26 @@ int guac_protocol_send_log(guac_socket* socket, const char* format, ...); int vguac_protocol_send_log(guac_socket* socket, const char* format, va_list args); +/** + * Sends a mouse instruction over the given guac_socket connection. + * + * If an error occurs sending the instruction, a non-zero value is + * returned, and guac_error is set appropriately. + * + * @param socket + * The guac_socket connection to use. + * + * @param x + * The X coordinate of the current mouse position. + * + * @param y + * The Y coordinate of the current mouse position. + * + * @return + * Zero on success, non-zero on error. + */ +int guac_protocol_send_mouse(guac_socket* socket, int x, int y); + /** * Sends a nest instruction over the given guac_socket connection. * diff --git a/src/libguac/protocol.c b/src/libguac/protocol.c index 1040fb1d..8da18249 100644 --- a/src/libguac/protocol.c +++ b/src/libguac/protocol.c @@ -684,6 +684,23 @@ int guac_protocol_send_lstroke(guac_socket* socket, } +int guac_protocol_send_mouse(guac_socket* socket, int x, int y) { + + int ret_val; + + guac_socket_instruction_begin(socket); + ret_val = + guac_socket_write_string(socket, "5.mouse,") + || __guac_socket_write_length_int(socket, x) + || guac_socket_write_string(socket, ",") + || __guac_socket_write_length_int(socket, y) + || guac_socket_write_string(socket, ";"); + + guac_socket_instruction_end(socket); + return ret_val; + +} + int guac_protocol_send_move(guac_socket* socket, const guac_layer* layer, const guac_layer* parent, int x, int y, int z) {