--- sourceforge.net/trunk/rdesktop/xkeymap.c 2005/08/03 08:25:32 957 +++ sourceforge.net/trunk/rdesktop/xkeymap.c 2005/08/04 12:50:15 974 @@ -1,4 +1,4 @@ -/* +/* -*- c-basic-offset: 8 -*- rdesktop: A Remote Desktop Protocol client. User interface services - X keyboard mapping @@ -30,6 +30,7 @@ #include #include #include +#include #include "rdesktop.h" #include "scancodes.h" @@ -41,6 +42,9 @@ extern Window g_wnd; extern char keymapname[16]; extern int g_keylayout; +extern int g_keyboard_type; +extern int g_keyboard_subtype; +extern int g_keyboard_functionkeys; extern int g_win_button_size; extern BOOL g_enable_compose; extern BOOL g_use_rdp5; @@ -155,6 +159,60 @@ DEBUG_KBD(("\n")); } +BOOL +xkeymap_from_locale(const char *locale) +{ + char *str, *ptr; + FILE *fp; + + /* Create a working copy */ + str = xstrdup(locale); + + /* Truncate at dot and at */ + ptr = strrchr(str, '.'); + if (ptr) + *ptr = '\0'; + ptr = strrchr(str, '@'); + if (ptr) + *ptr = '\0'; + + /* Replace _ with - */ + ptr = strrchr(str, '_'); + if (ptr) + *ptr = '-'; + + /* Convert to lowercase */ + ptr = str; + while (*ptr) + { + *ptr = tolower((int) *ptr); + ptr++; + } + + /* Try to open this keymap (da-dk) */ + fp = xkeymap_open(str); + if (fp == NULL) + { + /* Truncate at dash */ + ptr = strrchr(str, '-'); + if (ptr) + *ptr = '\0'; + + /* Try the short name (da) */ + fp = xkeymap_open(str); + } + + if (fp) + { + fclose(fp); + STRNCPY(keymapname, str, sizeof(keymapname)); + return True; + } + + return False; +} + + /* Joins two path components. The result should be freed with xfree(). */ static char * @@ -184,13 +242,6 @@ char *home; FILE *fp; - /* Try KEYMAP_PATH */ - path1 = pathjoin(KEYMAP_PATH, filename); - fp = fopen(path1, "r"); - xfree(path1); - if (fp) - return fp; - /* Try ~/.rdesktop/keymaps */ home = getenv("HOME"); if (home) @@ -204,6 +255,13 @@ return fp; } + /* Try KEYMAP_PATH */ + path1 = pathjoin(KEYMAP_PATH, filename); + fp = fopen(path1, "r"); + xfree(path1); + if (fp) + return fp; + /* Try current directory, in case we are running from the source tree */ path1 = pathjoin("keymaps", filename); @@ -253,23 +311,23 @@ } /* Include */ - if (strncmp(line, "include ", 8) == 0) + if (strncmp(line, "include ", sizeof("include ") - 1) == 0) { - if (!xkeymap_read(line + 8)) + if (!xkeymap_read(line + sizeof("include ") - 1)) return False; continue; } /* map */ - if (strncmp(line, "map ", 4) == 0) + if (strncmp(line, "map ", sizeof("map ") - 1) == 0) { - g_keylayout = strtol(line + 4, NULL, 16); + g_keylayout = strtol(line + sizeof("map ") - 1, NULL, 16); DEBUG_KBD(("Keylayout 0x%x\n", g_keylayout)); continue; } /* compose */ - if (strncmp(line, "enable_compose", 15) == 0) + if (strncmp(line, "enable_compose", sizeof("enable_compose") - 1) == 0) { DEBUG_KBD(("Enabling compose handling\n")); g_enable_compose = True; @@ -277,9 +335,36 @@ } /* sequence */ - if (strncmp(line, "sequence", 8) == 0) + if (strncmp(line, "sequence", sizeof("sequence") - 1) == 0) { - add_sequence(line + 8, mapname); + add_sequence(line + sizeof("sequence") - 1, mapname); + continue; + } + + /* keyboard_type */ + if (strncmp(line, "keyboard_type ", sizeof("keyboard_type ") - 1) == 0) + { + g_keyboard_type = strtol(line + sizeof("keyboard_type ") - 1, NULL, 16); + DEBUG_KBD(("keyboard_type 0x%x\n", g_keyboard_type)); + continue; + } + + /* keyboard_subtype */ + if (strncmp(line, "keyboard_subtype ", sizeof("keyboard_subtype ") - 1) == 0) + { + g_keyboard_subtype = + strtol(line + sizeof("keyboard_subtype ") - 1, NULL, 16); + DEBUG_KBD(("keyboard_subtype 0x%x\n", g_keyboard_subtype)); + continue; + } + + /* keyboard_functionkeys */ + if (strncmp(line, "keyboard_functionkeys ", sizeof("keyboard_functionkeys ") - 1) == + 0) + { + g_keyboard_functionkeys = + strtol(line + sizeof("keyboard_functionkeys ") - 1, NULL, 16); + DEBUG_KBD(("keyboard_functionkeys 0x%x\n", g_keyboard_functionkeys)); continue; } @@ -358,15 +443,6 @@ xkeymap_init(void) { unsigned int max_keycode; - char *mapname_ptr; - - /* Make keymapname lowercase */ - mapname_ptr = keymapname; - while (*mapname_ptr) - { - *mapname_ptr = tolower((int) *mapname_ptr); - mapname_ptr++; - } if (strcmp(keymapname, "none")) {