mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 21:27:40 +00:00
Working key/mouse input!
This commit is contained in:
@@ -207,6 +207,9 @@ guac_instruction* guac_read_instruction(GUACIO* io) {
|
|||||||
guac_instruction* parsed_instruction;
|
guac_instruction* parsed_instruction;
|
||||||
int retval;
|
int retval;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
int argcount = 0;
|
||||||
|
int j;
|
||||||
|
int current_arg = 0;
|
||||||
|
|
||||||
/* Loop until a instruction is read */
|
/* Loop until a instruction is read */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@@ -214,7 +217,14 @@ guac_instruction* guac_read_instruction(GUACIO* io) {
|
|||||||
/* Search for end of instruction */
|
/* Search for end of instruction */
|
||||||
for (; i < io->instructionbuf_used_length; i++) {
|
for (; i < io->instructionbuf_used_length; i++) {
|
||||||
|
|
||||||
if (io->instructionbuf[i] == ';') {
|
/* Count arguments as we look for the end */
|
||||||
|
if (io->instructionbuf[i] == ',')
|
||||||
|
argcount++;
|
||||||
|
else if (io->instructionbuf[i] == ':' && argcount == 0)
|
||||||
|
argcount++;
|
||||||
|
|
||||||
|
/* End found ... */
|
||||||
|
else if (io->instructionbuf[i] == ';') {
|
||||||
|
|
||||||
/* Parse new instruction */
|
/* Parse new instruction */
|
||||||
char* instruction = malloc(i+1);
|
char* instruction = malloc(i+1);
|
||||||
@@ -222,9 +232,30 @@ guac_instruction* guac_read_instruction(GUACIO* io) {
|
|||||||
instruction[i] = '\0'; /* Replace semicolon with null terminator. */
|
instruction[i] = '\0'; /* Replace semicolon with null terminator. */
|
||||||
|
|
||||||
parsed_instruction = malloc(sizeof(guac_instruction));
|
parsed_instruction = malloc(sizeof(guac_instruction));
|
||||||
parsed_instruction->opcode = instruction;
|
parsed_instruction->opcode = NULL;
|
||||||
parsed_instruction->argc = 0;
|
|
||||||
parsed_instruction->argv = NULL;
|
parsed_instruction->argc = argcount;
|
||||||
|
parsed_instruction->argv = malloc(sizeof(char*) * argcount);
|
||||||
|
|
||||||
|
for (j=0; j<i; j++) {
|
||||||
|
|
||||||
|
/* If encountered a colon, and no opcode parsed yet, set opcode and following argument */
|
||||||
|
if (instruction[j] == ':' && parsed_instruction->opcode == NULL) {
|
||||||
|
instruction[j] = '\0';
|
||||||
|
parsed_instruction->argv[current_arg++] = &(instruction[j+1]);
|
||||||
|
parsed_instruction->opcode = instruction;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If encountered a comma, set following argument */
|
||||||
|
else if (instruction[j] == ',') {
|
||||||
|
instruction[j] = '\0';
|
||||||
|
parsed_instruction->argv[current_arg++] = &(instruction[j+1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If no arguments, set opcode to entire instruction */
|
||||||
|
if (parsed_instruction->opcode == NULL)
|
||||||
|
parsed_instruction->opcode = instruction;
|
||||||
|
|
||||||
/* Found. Reset buffer */
|
/* Found. Reset buffer */
|
||||||
memmove(io->instructionbuf, io->instructionbuf + i + 1, io->instructionbuf_used_length - i - 1);
|
memmove(io->instructionbuf, io->instructionbuf + i + 1, io->instructionbuf_used_length - i - 1);
|
||||||
|
@@ -181,9 +181,27 @@ void proxy(int client_fd) {
|
|||||||
|
|
||||||
wait_result = guac_instructions_waiting(io);
|
wait_result = guac_instructions_waiting(io);
|
||||||
if (wait_result > 0) {
|
if (wait_result > 0) {
|
||||||
guac_instruction* instruction = guac_read_instruction(io);
|
guac_instruction* instruction;
|
||||||
if (instruction) {
|
|
||||||
fprintf(stderr, "NEW READ INSTRUCTION: %s\n", instruction->opcode);
|
while ((instruction = guac_read_instruction(io))) {
|
||||||
|
|
||||||
|
if (strcmp(instruction->opcode, "mouse") == 0) {
|
||||||
|
SendPointerEvent(
|
||||||
|
rfb_client,
|
||||||
|
atoi(instruction->argv[0]), /* x */
|
||||||
|
atoi(instruction->argv[1]), /* y */
|
||||||
|
atoi(instruction->argv[2]) /* mask */
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (strcmp(instruction->opcode, "key") == 0) {
|
||||||
|
SendKeyEvent(
|
||||||
|
rfb_client,
|
||||||
|
atoi(instruction->argv[0]), /* keysym */
|
||||||
|
atoi(instruction->argv[1]) /* pressed */
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
guac_free_instruction(instruction);
|
guac_free_instruction(instruction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user