Do not use addressof in lookup macro. Update keysym state in event handler.
[libguac-client-rdp.git] / src / guac_handlers.c
index 8a7f334..488af41 100644 (file)
 #include "rdp_keymap.h"
 #include "guac_handlers.h"
 
+void __guac_rdp_send_keysym_string(guac_client* client, const int* keysym_string, int pressed);
+int __guac_rdp_send_keysym(guac_client* client, int keysym, int pressed);
+void __guac_rdp_send_altcode(guac_client* client, const char* altcode);
+
 int rdp_guac_client_free_handler(guac_client* client) {
 
     /* STUB */
@@ -230,7 +234,7 @@ void __guac_rdp_send_altcode(guac_client* client, const char* altcode) {
     const guac_rdp_keysym_scancode_map* keysym_scancodes = guac_client_data->keysym_scancodes;
 
     /* Lookup scancode for Alt */
-    int alt = GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, 0xFFE9 /* Alt_L */)->scancode;
+    int alt = GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, 0xFFE9 /* Alt_L */).scancode;
 
     /* Press Alt */
     rdp_inst->input->KeyboardEvent(rdp_inst->input, KBD_FLAGS_DOWN, alt);
@@ -239,7 +243,7 @@ void __guac_rdp_send_altcode(guac_client* client, const char* altcode) {
     while (*altcode != '\0') {
 
         /* Get scancode of keypad digit */
-        int scancode = GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, 0xFFB0 + (*altcode) - '0')->scancode;
+        int scancode = GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, 0xFFB0 + (*altcode) - '0').scancode;
 
         /* Press and release digit */
         rdp_inst->input->KeyboardEvent(rdp_inst->input, KBD_FLAGS_DOWN, scancode);
@@ -254,15 +258,7 @@ void __guac_rdp_send_altcode(guac_client* client, const char* altcode) {
 
 }
 
-void __rdp_guac_client_send_keysym_string(guac_client* client, const int* keysym_string, int pressed) {
-
-    /* Send all keysyms in string, NULL terminated */
-    while (*keysym_string != 0)
-        rdp_guac_client_key_handler(client, *(keysym_string++), pressed);
-
-}
-
-int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
+int __guac_rdp_send_keysym(guac_client* client, int keysym, int pressed) {
 
     rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
     freerdp* rdp_inst = guac_client_data->rdp_inst;
@@ -272,14 +268,14 @@ int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
     if (keysym <= 0xFFFF) {
 
         /* Look up scancode mapping */
-        const guac_rdp_scancode_map* scancode_map = GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, keysym);
+        const guac_rdp_scancode_map* scancode_map = &GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, keysym);
 
         /* If defined, send event */
         if (scancode_map->scancode != 0) {
 
             /* If defined, send any prerequesite keys */
             if (scancode_map->set_keysyms != NULL)
-                __rdp_guac_client_send_keysym_string(client, scancode_map->set_keysyms, 1);
+                __guac_rdp_send_keysym_string(client, scancode_map->set_keysyms, 1);
 
             /* Send actual key */
             rdp_inst->input->KeyboardEvent(
@@ -290,14 +286,14 @@ int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
 
             /* If defined, release any prerequesite keys */
             if (scancode_map->set_keysyms != NULL)
-                __rdp_guac_client_send_keysym_string(client, scancode_map->set_keysyms, 0);
+                __guac_rdp_send_keysym_string(client, scancode_map->set_keysyms, 0);
 
         }
 
         /* If undefined, try to type using Alt-code */
         else {
 
-            const guac_rdp_altcode_map* altcode_map = GUAC_RDP_KEYSYM_LOOKUP(guac_rdp_keysym_altcode, keysym);
+            const guac_rdp_altcode_map* altcode_map = &GUAC_RDP_KEYSYM_LOOKUP(guac_rdp_keysym_altcode, keysym);
             if (altcode_map->altcode != NULL) {
 
                 /* Only send Alt-code on press */
@@ -317,3 +313,22 @@ int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
     return 0;
 }
 
+void __guac_rdp_send_keysym_string(guac_client* client, const int* keysym_string, int pressed) {
+
+    /* Send all keysyms in string, NULL terminated */
+    while (*keysym_string != 0)
+        __guac_rdp_send_keysym(client, *(keysym_string++), pressed);
+
+}
+
+int rdp_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
+
+    rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
+
+    /* Update keysym state */
+    GUAC_RDP_KEYSYM_LOOKUP(guac_client_data->keysym_state, keysym) = pressed;
+
+    return __guac_rdp_send_keysym(client, keysym, pressed);
+
+}
+