Simplified mapping and lookups, added required structuring for future selectable keymaps.

This commit is contained in:
Michael Jumper 2012-03-20 15:33:08 -07:00
parent b984832687
commit a366c189c5
6 changed files with 37 additions and 16 deletions

View File

@ -41,7 +41,8 @@ AM_CFLAGS = -Werror -Wall -pedantic -Iinclude
lib_LTLIBRARIES = libguac-client-rdp.la 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 libguac_client_rdp_la_LDFLAGS = -version-info 0:0:0

View File

@ -43,6 +43,8 @@
#include <guacamole/client.h> #include <guacamole/client.h>
#include "rdp_keymap.h"
#define RDP_DEFAULT_PORT 3389 #define RDP_DEFAULT_PORT 3389
typedef struct guac_rdp_color { typedef struct guac_rdp_color {
@ -63,6 +65,8 @@ typedef struct rdp_guac_client_data {
const guac_layer* current_surface; const guac_layer* current_surface;
const guac_rdp_keysym_scancode_map* keysym_scancodes;
} rdp_guac_client_data; } rdp_guac_client_data;
typedef struct rdp_freerdp_context { typedef struct rdp_freerdp_context {

View File

@ -42,7 +42,7 @@
* Represents a keysym-to-scancode mapping for RDP, with extra information * Represents a keysym-to-scancode mapping for RDP, with extra information
* about the state of prerequisite keysyms. * about the state of prerequisite keysyms.
*/ */
typedef struct guac_rdp_keymap { typedef struct guac_rdp_scancode_map {
/** /**
* The scancode this keysym maps to. * The scancode this keysym maps to.
@ -66,7 +66,7 @@ typedef struct guac_rdp_keymap {
*/ */
int* clear_keysyms; int* clear_keysyms;
} guac_rdp_keymap; } guac_rdp_scancode_map;
/** /**
* Represents the Alt-code which types a given keysym. This is used as a * 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 * 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. * 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. * 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 #endif

View File

@ -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->rdp_inst = rdp_inst;
guac_client_data->mouse_button_mask = 0; guac_client_data->mouse_button_mask = 0;
guac_client_data->current_surface = GUAC_DEFAULT_LAYER; 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; ((rdp_freerdp_context*) rdp_inst->context)->client = client;
client->data = guac_client_data; client->data = guac_client_data;

View File

@ -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; rdp_guac_client_data* guac_client_data = (rdp_guac_client_data*) client->data;
freerdp* rdp_inst = guac_client_data->rdp_inst; 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 can be in lookup table */
if (keysym <= 0xFFFF) { if (keysym <= 0xFFFF) {
/* Look up scancode */ /* Look up scancode mapping */
const guac_rdp_keymap* keymap = const guac_rdp_scancode_map* scancode_map = GUAC_RDP_KEYSYM_LOOKUP(*keysym_scancodes, keysym);
&guac_rdp_keysym_scancode[(keysym & 0xFF00) >> 8][keysym & 0xFF];
/* If defined, send event */ /* If defined, send event */
if (keymap->scancode != 0) if (scancode_map->scancode != 0)
rdp_inst->input->KeyboardEvent( rdp_inst->input->KeyboardEvent(
rdp_inst->input, rdp_inst->input,
keymap->flags scancode_map->flags
| (pressed ? KBD_FLAGS_DOWN : KBD_FLAGS_RELEASE), | (pressed ? KBD_FLAGS_DOWN : KBD_FLAGS_RELEASE),
keymap->scancode); scancode_map->scancode);
else else
guac_client_log_info(client, "unmapped keysym: 0x%x", keysym); guac_client_log_info(client, "unmapped keysym: 0x%x", keysym);

View File

@ -40,7 +40,7 @@
#include "rdp_keymap.h" #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?? */ { /* 0x00?? */
{ .scancode = 0x00, .flags = 0x00 }, /* 0x0000 */ { .scancode = 0x00, .flags = 0x00 }, /* 0x0000 */
{ .scancode = 0x00, .flags = 0x00 }, /* 0x0001 */ { .scancode = 0x00, .flags = 0x00 }, /* 0x0001 */