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:
parent
92df92615c
commit
5e5d52ccf4
@ -41,7 +41,11 @@ client.
|
||||
Keyboard layout to emulate. This requires a corresponding keymap file to be
|
||||
installed. The standard keymaps provided with rdesktop follow the RFC1766
|
||||
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
|
||||
sensitive. The standard keymaps are all in lowercase.
|
||||
|
1
proto.h
1
proto.h
@ -166,6 +166,7 @@ void ui_clip_request_data(uint32 format);
|
||||
void ui_clip_sync(void);
|
||||
void xclip_init(void);
|
||||
/* xkeymap.c */
|
||||
void xkeymap_from_locale(const char *locale);
|
||||
FILE *xkeymap_open(const char *filename);
|
||||
void xkeymap_init(void);
|
||||
BOOL handle_special_keys(uint32 keysym, unsigned int state, uint32 ev_time, BOOL pressed);
|
||||
|
14
rdesktop.c
14
rdesktop.c
@ -30,10 +30,10 @@
|
||||
#include <errno.h>
|
||||
#include "rdesktop.h"
|
||||
|
||||
#ifdef HAVE_ICONV
|
||||
#ifdef HAVE_LOCALE_H
|
||||
#include <locale.h>
|
||||
#endif
|
||||
#ifdef HAVE_ICONV
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
@ -50,7 +50,7 @@
|
||||
char g_title[64] = "";
|
||||
char g_username[64];
|
||||
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_width = 800; /* width is special: If 0, the
|
||||
@ -370,13 +370,19 @@ main(int argc, char *argv[])
|
||||
uint32 flags, ext_disc_reason = 0;
|
||||
char *p;
|
||||
int c;
|
||||
|
||||
char *locale;
|
||||
int username_option = 0;
|
||||
|
||||
/* Set locale according to environment */
|
||||
locale = setlocale(LC_ALL, "");
|
||||
if (locale)
|
||||
{
|
||||
xkeymap_from_locale(locale);
|
||||
}
|
||||
|
||||
flags = RDP_LOGON_NORMAL;
|
||||
prompt_password = False;
|
||||
domain[0] = password[0] = shell[0] = directory[0] = 0;
|
||||
strcpy(keymapname, "en-us");
|
||||
g_embed_wnd = 0;
|
||||
|
||||
g_num_devices = 0;
|
||||
|
58
xkeymap.c
58
xkeymap.c
@ -156,6 +156,63 @@ add_sequence(char *rest, char *mapname)
|
||||
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
|
||||
xfree(). */
|
||||
static char *
|
||||
@ -359,7 +416,6 @@ void
|
||||
xkeymap_init(void)
|
||||
{
|
||||
unsigned int max_keycode;
|
||||
char *mapname_ptr;
|
||||
|
||||
if (strcmp(keymapname, "none"))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user