GUACAMOLE-313: Use mouse timestamps for frames as well as sync.

This commit is contained in:
Michael Jumper 2017-11-27 20:18:20 -08:00
parent a74d6a2aaf
commit 7eb4e22515
4 changed files with 49 additions and 35 deletions

View File

@ -21,6 +21,7 @@
#include "cursor.h" #include "cursor.h"
#include "display.h" #include "display.h"
#include "log.h" #include "log.h"
#include "parse.h"
#include <guacamole/client.h> #include <guacamole/client.h>
@ -43,7 +44,13 @@ int guacenc_handle_mouse(guacenc_display* display, int argc, char** argv) {
cursor->x = x; cursor->x = x;
cursor->y = y; 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);
} }

View File

@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "display.h" #include "display.h"
#include "log.h" #include "log.h"
#include "parse.h"
#include <guacamole/client.h> #include <guacamole/client.h>
#include <guacamole/timestamp.h> #include <guacamole/timestamp.h>
@ -27,40 +28,6 @@
#include <inttypes.h> #include <inttypes.h>
#include <stdlib.h> #include <stdlib.h>
/**
* 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) { int guacenc_handle_sync(guacenc_display* display, int argc, char** argv) {
/* Verify argument count */ /* Verify argument count */

View File

@ -19,6 +19,8 @@
#include "config.h" #include "config.h"
#include <guacamole/timestamp.h>
#include <errno.h> #include <errno.h>
#include <limits.h> #include <limits.h>
#include <string.h> #include <string.h>
@ -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);
}

View File

@ -22,6 +22,8 @@
#include "config.h" #include "config.h"
#include <guacamole/timestamp.h>
/** /**
* Parses a string into a single integer. Only positive integers are accepted. * 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 * 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); 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 #endif