Autoselecting keyboard map based on current locale. Re-implementation of patch #1068995.

git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@961 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Peter Åstrand 2005-08-03 09:56:17 +00:00
parent 92df92615c
commit 5e5d52ccf4
4 changed files with 73 additions and 6 deletions

View File

@ -41,7 +41,11 @@ client.
Keyboard layout to emulate. This requires a corresponding keymap file to be Keyboard layout to emulate. This requires a corresponding keymap file to be
installed. The standard keymaps provided with rdesktop follow the RFC1766 installed. The standard keymaps provided with rdesktop follow the RFC1766
naming scheme: a language code followed by a country code if necessary - e.g. naming scheme: a language code followed by a country code if necessary - e.g.
en-us, en-gb, de, fr, sv, etc. The default is en-us (a US keyboard). en-us, en-gb, de, fr, sv, etc.
The default keyboard map depends on the current locale (LC_* and LANG
environment variables). If no valid locale is specified, the default
keyboard map is en-us (a US keyboard).
The keyboard maps are file names, which means that they are case The keyboard maps are file names, which means that they are case
sensitive. The standard keymaps are all in lowercase. sensitive. The standard keymaps are all in lowercase.

View File

@ -166,6 +166,7 @@ void ui_clip_request_data(uint32 format);
void ui_clip_sync(void); void ui_clip_sync(void);
void xclip_init(void); void xclip_init(void);
/* xkeymap.c */ /* xkeymap.c */
void xkeymap_from_locale(const char *locale);
FILE *xkeymap_open(const char *filename); FILE *xkeymap_open(const char *filename);
void xkeymap_init(void); void xkeymap_init(void);
BOOL handle_special_keys(uint32 keysym, unsigned int state, uint32 ev_time, BOOL pressed); BOOL handle_special_keys(uint32 keysym, unsigned int state, uint32 ev_time, BOOL pressed);

View File

@ -30,10 +30,10 @@
#include <errno.h> #include <errno.h>
#include "rdesktop.h" #include "rdesktop.h"
#ifdef HAVE_ICONV
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
#include <locale.h> #include <locale.h>
#endif #endif
#ifdef HAVE_ICONV
#ifdef HAVE_LANGINFO_H #ifdef HAVE_LANGINFO_H
#include <langinfo.h> #include <langinfo.h>
#endif #endif
@ -50,7 +50,7 @@
char g_title[64] = ""; char g_title[64] = "";
char g_username[64]; char g_username[64];
char g_hostname[16]; char g_hostname[16];
char keymapname[PATH_MAX]; char keymapname[PATH_MAX] = "en-us";
int g_keylayout = 0x409; /* Defaults to US keyboard layout */ int g_keylayout = 0x409; /* Defaults to US keyboard layout */
int g_width = 800; /* width is special: If 0, the int g_width = 800; /* width is special: If 0, the
@ -370,13 +370,19 @@ main(int argc, char *argv[])
uint32 flags, ext_disc_reason = 0; uint32 flags, ext_disc_reason = 0;
char *p; char *p;
int c; int c;
char *locale;
int username_option = 0; int username_option = 0;
/* Set locale according to environment */
locale = setlocale(LC_ALL, "");
if (locale)
{
xkeymap_from_locale(locale);
}
flags = RDP_LOGON_NORMAL; flags = RDP_LOGON_NORMAL;
prompt_password = False; prompt_password = False;
domain[0] = password[0] = shell[0] = directory[0] = 0; domain[0] = password[0] = shell[0] = directory[0] = 0;
strcpy(keymapname, "en-us");
g_embed_wnd = 0; g_embed_wnd = 0;
g_num_devices = 0; g_num_devices = 0;

View File

@ -156,6 +156,63 @@ add_sequence(char *rest, char *mapname)
DEBUG_KBD(("\n")); DEBUG_KBD(("\n"));
} }
void
xkeymap_from_locale(const char *locale)
{
char *str, *ptr;
FILE *fp;
/* Create a working copy */
str = strdup(locale);
if (str == NULL)
{
perror("strdup");
exit(1);
}
/* 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));
fprintf(stderr, "Autoselected keyboard map %s.\n", keymapname);
}
}
/* Joins two path components. The result should be freed with /* Joins two path components. The result should be freed with
xfree(). */ xfree(). */
static char * static char *
@ -359,7 +416,6 @@ void
xkeymap_init(void) xkeymap_init(void)
{ {
unsigned int max_keycode; unsigned int max_keycode;
char *mapname_ptr;
if (strcmp(keymapname, "none")) if (strcmp(keymapname, "none"))
{ {