void __guac_rdp_client_load_keymap(guac_client* client, const guac_rdp_keymap* keymap) { rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data; /* Get mapping */ const guac_rdp_keysym_desc* mapping = keymap->mapping; /* If parent exists, load parent first */ if (keymap->parent != NULL) __guac_rdp_client_load_keymap(client, keymap->parent); /* Log load */ guac_client_log_info(client, "Loading keymap \"%s\"", keymap->name); /* Load mapping into keymap */ while (mapping->keysym != 0) { /* Copy mapping */ GUAC_RDP_KEYSYM_LOOKUP(guac_client_data->keymap, mapping->keysym) = *mapping; /* Next keysym */ mapping++; } }
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 */ if (GUAC_RDP_KEYSYM_STORABLE(keysym)) GUAC_RDP_KEYSYM_LOOKUP(guac_client_data->keysym_state, keysym) = pressed; return __guac_rdp_send_keysym(client, keysym, pressed); }
void __guac_rdp_update_keysyms(guac_client* client, const int* keysym_string, int from, int to) { rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data; int keysym; /* Send all keysyms in string, NULL terminated */ while ((keysym = *keysym_string) != 0) { /* Get current keysym state */ int current_state = GUAC_RDP_KEYSYM_LOOKUP(guac_client_data->keysym_state, keysym); /* If key is currently in given state, send event for changing it to specified "to" state */ if (current_state == from) __guac_rdp_send_keysym(client, *keysym_string, to); /* Next keysym */ keysym_string++; } }
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; /* If keysym can be in lookup table */ if (GUAC_RDP_KEYSYM_STORABLE(keysym)) { int pressed_flags; /* Look up scancode mapping */ const guac_rdp_keysym_desc* keysym_desc = &GUAC_RDP_KEYSYM_LOOKUP(guac_client_data->keymap, keysym); /* If defined, send event */ if (keysym_desc->scancode != 0) { pthread_mutex_lock(&(guac_client_data->rdp_lock)); /* If defined, send any prerequesite keys that must be set */ if (keysym_desc->set_keysyms != NULL) __guac_rdp_update_keysyms(client, keysym_desc->set_keysyms, 0, 1); /* If defined, release any keys that must be cleared */ if (keysym_desc->clear_keysyms != NULL) __guac_rdp_update_keysyms(client, keysym_desc->clear_keysyms, 1, 0); /* Determine proper event flag for pressed state */ if (pressed) pressed_flags = KBD_FLAGS_DOWN; else pressed_flags = KBD_FLAGS_RELEASE; /* Send actual key */ rdp_inst->input->KeyboardEvent(rdp_inst->input, keysym_desc->flags | pressed_flags, keysym_desc->scancode); /* If defined, release any keys that were originally released */ if (keysym_desc->set_keysyms != NULL) __guac_rdp_update_keysyms(client, keysym_desc->set_keysyms, 0, 0); /* If defined, send any keys that were originally set */ if (keysym_desc->clear_keysyms != NULL) __guac_rdp_update_keysyms(client, keysym_desc->clear_keysyms, 1, 1); pthread_mutex_unlock(&(guac_client_data->rdp_lock)); return 0; } } /* Fall back to unicode events if undefined inside current keymap */ /* Only send when key pressed - Unicode events do not have * DOWN/RELEASE flags */ if (pressed) { /* Translate keysym into codepoint */ int codepoint; if (keysym <= 0xFF) codepoint = keysym; else if (keysym >= 0x1000000) codepoint = keysym & 0xFFFFFF; else { guac_client_log_info(client, "Unmapped keysym has no equivalent unicode " "value: 0x%x", keysym); return 0; } pthread_mutex_lock(&(guac_client_data->rdp_lock)); /* Send Unicode event */ rdp_inst->input->UnicodeKeyboardEvent( rdp_inst->input, 0, codepoint); pthread_mutex_unlock(&(guac_client_data->rdp_lock)); } return 0; }