From 7eb4e22515c2e3255e661bf26e27631940d5e231 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 27 Nov 2017 20:18:20 -0800 Subject: [PATCH] GUACAMOLE-313: Use mouse timestamps for frames as well as sync. --- src/guacenc/instruction-mouse.c | 9 ++++++++- src/guacenc/instruction-sync.c | 35 +-------------------------------- src/guacenc/parse.c | 23 ++++++++++++++++++++++ src/guacenc/parse.h | 17 ++++++++++++++++ 4 files changed, 49 insertions(+), 35 deletions(-) diff --git a/src/guacenc/instruction-mouse.c b/src/guacenc/instruction-mouse.c index ac9fd876..50952451 100644 --- a/src/guacenc/instruction-mouse.c +++ b/src/guacenc/instruction-mouse.c @@ -21,6 +21,7 @@ #include "cursor.h" #include "display.h" #include "log.h" +#include "parse.h" #include @@ -43,7 +44,13 @@ int guacenc_handle_mouse(guacenc_display* display, int argc, char** argv) { cursor->x = x; cursor->y = y; - return 0; + /* If no timestamp provided, nothing further to do */ + if (argc < 3) + return 0; + + /* Leverage timestamp to render frame */ + guac_timestamp timestamp = guacenc_parse_timestamp(argv[2]); + return guacenc_display_sync(display, timestamp); } diff --git a/src/guacenc/instruction-sync.c b/src/guacenc/instruction-sync.c index 5dd48444..c27ad145 100644 --- a/src/guacenc/instruction-sync.c +++ b/src/guacenc/instruction-sync.c @@ -20,6 +20,7 @@ #include "config.h" #include "display.h" #include "log.h" +#include "parse.h" #include #include @@ -27,40 +28,6 @@ #include #include -/** - * Parses a guac_timestamp from the given string. The string is assumed to - * consist solely of decimal digits with an optional leading minus sign. If the - * given string contains other characters, the behavior of this function is - * undefined. - * - * @param str - * The string to parse, which must contain only decimal digits and an - * optional leading minus sign. - * - * @return - * A guac_timestamp having the same value as the provided string. - */ -static guac_timestamp guacenc_parse_timestamp(const char* str) { - - int sign = 1; - int64_t num = 0; - - for (; *str != '\0'; str++) { - - /* Flip sign for each '-' encountered */ - if (*str == '-') - sign = -sign; - - /* If not '-', assume the character is a digit */ - else - num = num * 10 + (*str - '0'); - - } - - return (guac_timestamp) (num * sign); - -} - int guacenc_handle_sync(guacenc_display* display, int argc, char** argv) { /* Verify argument count */ diff --git a/src/guacenc/parse.c b/src/guacenc/parse.c index 0eea778e..8f05d38f 100644 --- a/src/guacenc/parse.c +++ b/src/guacenc/parse.c @@ -19,6 +19,8 @@ #include "config.h" +#include + #include #include #include @@ -67,3 +69,24 @@ int guacenc_parse_dimensions(char* arg, int* width, int* height) { } +guac_timestamp guacenc_parse_timestamp(const char* str) { + + int sign = 1; + int64_t num = 0; + + for (; *str != '\0'; str++) { + + /* Flip sign for each '-' encountered */ + if (*str == '-') + sign = -sign; + + /* If not '-', assume the character is a digit */ + else + num = num * 10 + (*str - '0'); + + } + + return (guac_timestamp) (num * sign); + +} + diff --git a/src/guacenc/parse.h b/src/guacenc/parse.h index f888913b..b6e5cd5a 100644 --- a/src/guacenc/parse.h +++ b/src/guacenc/parse.h @@ -22,6 +22,8 @@ #include "config.h" +#include + /** * Parses a string into a single integer. Only positive integers are accepted. * The input string may be modified during parsing. A value will be stored in @@ -63,6 +65,21 @@ int guacenc_parse_int(char* arg, int* i); */ int guacenc_parse_dimensions(char* arg, int* width, int* height); +/** + * Parses a guac_timestamp from the given string. The string is assumed to + * consist solely of decimal digits with an optional leading minus sign. If the + * given string contains other characters, the behavior of this function is + * undefined. + * + * @param str + * The string to parse, which must contain only decimal digits and an + * optional leading minus sign. + * + * @return + * A guac_timestamp having the same value as the provided string. + */ +guac_timestamp guacenc_parse_timestamp(const char* str); + #endif