From a366c189c52613a055437f89a48bb3673bb82bf7 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Tue, 20 Mar 2012 15:33:08 -0700 Subject: [PATCH] Simplified mapping and lookups, added required structuring for future selectable keymaps. --- protocols/rdp/Makefile.am | 3 +- protocols/rdp/include/client.h | 4 +++ protocols/rdp/include/rdp_keymap.h | 31 ++++++++++++++----- protocols/rdp/src/client.c | 1 + protocols/rdp/src/guac_handlers.c | 12 +++---- .../src/{rdp_keymap.c => rdp_keymap_en_us.c} | 2 +- 6 files changed, 37 insertions(+), 16 deletions(-) rename protocols/rdp/src/{rdp_keymap.c => rdp_keymap_en_us.c} (99%) diff --git a/protocols/rdp/Makefile.am b/protocols/rdp/Makefile.am index d4f143bb..c5cdeff6 100644 --- a/protocols/rdp/Makefile.am +++ b/protocols/rdp/Makefile.am @@ -41,7 +41,8 @@ AM_CFLAGS = -Werror -Wall -pedantic -Iinclude lib_LTLIBRARIES = libguac-client-rdp.la -libguac_client_rdp_la_SOURCES = src/client.c src/rdp_keymap.c src/rdp_bitmap.c src/rdp_glyph.c src/rdp_pointer.c src/rdp_gdi.c src/guac_handlers.c +libguac_client_rdp_la_SOURCES = src/client.c src/rdp_bitmap.c src/rdp_glyph.c src/rdp_pointer.c src/rdp_gdi.c src/guac_handlers.c \ + src/rdp_keymap_en_us.c libguac_client_rdp_la_LDFLAGS = -version-info 0:0:0 diff --git a/protocols/rdp/include/client.h b/protocols/rdp/include/client.h index 27500a63..e56dbb6a 100644 --- a/protocols/rdp/include/client.h +++ b/protocols/rdp/include/client.h @@ -43,6 +43,8 @@ #include +#include "rdp_keymap.h" + #define RDP_DEFAULT_PORT 3389 typedef struct guac_rdp_color { @@ -63,6 +65,8 @@ typedef struct rdp_guac_client_data { const guac_layer* current_surface; + const guac_rdp_keysym_scancode_map* keysym_scancodes; + } rdp_guac_client_data; typedef struct rdp_freerdp_context { diff --git a/protocols/rdp/include/rdp_keymap.h b/protocols/rdp/include/rdp_keymap.h index 60fde703..99dfb8a6 100644 --- a/protocols/rdp/include/rdp_keymap.h +++ b/protocols/rdp/include/rdp_keymap.h @@ -42,7 +42,7 @@ * Represents a keysym-to-scancode mapping for RDP, with extra information * about the state of prerequisite keysyms. */ -typedef struct guac_rdp_keymap { +typedef struct guac_rdp_scancode_map { /** * The scancode this keysym maps to. @@ -66,7 +66,7 @@ typedef struct guac_rdp_keymap { */ int* clear_keysyms; -} guac_rdp_keymap; +} guac_rdp_scancode_map; /** * Represents the Alt-code which types a given keysym. This is used as a @@ -74,24 +74,39 @@ typedef struct guac_rdp_keymap { * * See: http://en.wikipedia.org/wiki/Alt_code */ -typedef struct guac_rdp_alt_keymap { +typedef struct guac_rdp_altcode_map { /** * The 4-digit Alt-code which types this keysym. */ - char alt_code[4]; + char altcode[4]; -} guac_rdp_alt_keymap; +} guac_rdp_altcode_map; /** - * Map of X11 keysyms to RDP scancodes. + * Static mapping from keysyms to scancodes. */ -extern const guac_rdp_keymap guac_rdp_keysym_scancode[256][256]; +typedef guac_rdp_scancode_map guac_rdp_keysym_scancode_map[256][256]; + +/** + * Static mapping from keysyms to Alt-codes. + */ +typedef guac_rdp_altcode_map guac_rdp_keysym_altcode_map[256][256]; + +/** + * Map of X11 keysyms to RDP scancodes (US English). + */ +extern const guac_rdp_keysym_scancode_map guac_rdp_keysym_scancode_en_us; /** * Map of X11 keysyms to Windows Alt-codes. */ -extern const guac_rdp_alt_keymap guac_rdp_keysym_altcode[256][256]; +extern const guac_rdp_keysym_altcode_map guac_rdp_keysym_altcode; + +/** + * Simple macro for referencing the mapped value of an altcode or scancode for a given keysym. + */ +#define GUAC_RDP_KEYSYM_LOOKUP(keysym_mapping, keysym) (&((keysym_mapping)[((keysym) & 0xFF00) >> 8][(keysym) & 0xFF])) #endif diff --git a/protocols/rdp/src/client.c b/protocols/rdp/src/client.c index 6109297f..dc6a081a 100644 --- a/protocols/rdp/src/client.c +++ b/protocols/rdp/src/client.c @@ -323,6 +323,7 @@ int guac_client_init(guac_client* client, int argc, char** argv) { guac_client_data->rdp_inst = rdp_inst; guac_client_data->mouse_button_mask = 0; guac_client_data->current_surface = GUAC_DEFAULT_LAYER; + guac_client_data->keysym_scancodes = &guac_rdp_keysym_scancode_en_us; ((rdp_freerdp_context*) rdp_inst->context)->client = client; client->data = guac_client_data; diff --git a/protocols/rdp/src/guac_handlers.c b/protocols/rdp/src/guac_handlers.c index 73d19302..3236c8a2 100644 --- a/protocols/rdp/src/guac_handlers.c +++ b/protocols/rdp/src/guac_handlers.c @@ -227,21 +227,21 @@ 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; freerdp* rdp_inst = guac_client_data->rdp_inst; + const guac_rdp_keysym_scancode_map* keysym_scancodes = guac_client_data->keysym_scancodes; /* If keysym can be in lookup table */ if (keysym <= 0xFFFF) { - /* Look up scancode */ - const guac_rdp_keymap* keymap = - &guac_rdp_keysym_scancode[(keysym & 0xFF00) >> 8][keysym & 0xFF]; + /* Look up scancode mapping */ + const guac_rdp_scancode_map* scancode_map = GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, keysym); /* If defined, send event */ - if (keymap->scancode != 0) + if (scancode_map->scancode != 0) rdp_inst->input->KeyboardEvent( rdp_inst->input, - keymap->flags + scancode_map->flags | (pressed ? KBD_FLAGS_DOWN : KBD_FLAGS_RELEASE), - keymap->scancode); + scancode_map->scancode); else guac_client_log_info(client, "unmapped keysym: 0x%x", keysym); diff --git a/protocols/rdp/src/rdp_keymap.c b/protocols/rdp/src/rdp_keymap_en_us.c similarity index 99% rename from protocols/rdp/src/rdp_keymap.c rename to protocols/rdp/src/rdp_keymap_en_us.c index 0a568f69..d91faf74 100644 --- a/protocols/rdp/src/rdp_keymap.c +++ b/protocols/rdp/src/rdp_keymap_en_us.c @@ -40,7 +40,7 @@ #include "rdp_keymap.h" -const guac_rdp_keymap guac_rdp_keysym_scancode[256][256] = { +const guac_rdp_scancode_map guac_rdp_keysym_scancode_en_us[256][256] = { { /* 0x00?? */ { .scancode = 0x00, .flags = 0x00 }, /* 0x0000 */ { .scancode = 0x00, .flags = 0x00 }, /* 0x0001 */