Merge pull request #2587 from metalefty/keymap_load
[refactoring] xrdp: enable loading any keymap files
This commit is contained in:
commit
7bf95fc1d2
71
xrdp/lang.c
71
xrdp/lang.c
@ -231,7 +231,6 @@ km_read_section(int fd, const char *section_name, struct xrdp_key_info *keymap)
|
|||||||
int
|
int
|
||||||
get_keymaps(int keylayout, struct xrdp_keymap *keymap)
|
get_keymaps(int keylayout, struct xrdp_keymap *keymap)
|
||||||
{
|
{
|
||||||
int fd;
|
|
||||||
int basic_key_layout = keylayout & 0x0000ffff;
|
int basic_key_layout = keylayout & 0x0000ffff;
|
||||||
char *filename;
|
char *filename;
|
||||||
struct xrdp_keymap *lkeymap;
|
struct xrdp_keymap *lkeymap;
|
||||||
@ -258,36 +257,21 @@ get_keymaps(int keylayout, struct xrdp_keymap *keymap)
|
|||||||
|
|
||||||
if (g_file_exist(filename))
|
if (g_file_exist(filename))
|
||||||
{
|
{
|
||||||
fd = g_file_open(filename);
|
|
||||||
LOG(LOG_LEVEL_INFO, "Loading keymap file %s", filename);
|
|
||||||
|
|
||||||
if (fd != -1)
|
lkeymap = (struct xrdp_keymap *)g_malloc(sizeof(struct xrdp_keymap), 0);
|
||||||
|
/* make a copy of the built-in keymap */
|
||||||
|
g_memcpy(lkeymap, keymap, sizeof(struct xrdp_keymap));
|
||||||
|
|
||||||
|
km_load_file(filename, keymap);
|
||||||
|
|
||||||
|
if (g_memcmp(lkeymap, keymap, sizeof(struct xrdp_keymap)) != 0)
|
||||||
{
|
{
|
||||||
lkeymap = (struct xrdp_keymap *)g_malloc(sizeof(struct xrdp_keymap), 0);
|
LOG(LOG_LEVEL_WARNING,
|
||||||
/* make a copy of the built-in keymap */
|
"local keymap file for 0x%08x found and doesn't match "
|
||||||
g_memcpy(lkeymap, keymap, sizeof(struct xrdp_keymap));
|
"built in keymap, using local keymap file", keylayout);
|
||||||
/* clear the keymaps */
|
|
||||||
g_memset(keymap, 0, sizeof(struct xrdp_keymap));
|
|
||||||
/* read the keymaps */
|
|
||||||
km_read_section(fd, "noshift", keymap->keys_noshift);
|
|
||||||
km_read_section(fd, "shift", keymap->keys_shift);
|
|
||||||
km_read_section(fd, "altgr", keymap->keys_altgr);
|
|
||||||
km_read_section(fd, "shiftaltgr", keymap->keys_shiftaltgr);
|
|
||||||
km_read_section(fd, "capslock", keymap->keys_capslock);
|
|
||||||
km_read_section(fd, "capslockaltgr", keymap->keys_capslockaltgr);
|
|
||||||
km_read_section(fd, "shiftcapslock", keymap->keys_shiftcapslock);
|
|
||||||
km_read_section(fd, "shiftcapslockaltgr", keymap->keys_shiftcapslockaltgr);
|
|
||||||
|
|
||||||
if (g_memcmp(lkeymap, keymap, sizeof(struct xrdp_keymap)) != 0)
|
|
||||||
{
|
|
||||||
LOG(LOG_LEVEL_WARNING,
|
|
||||||
"local keymap file for 0x%08x found and doesn't match "
|
|
||||||
"built in keymap, using local keymap file", keylayout);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free(lkeymap);
|
|
||||||
g_file_close(fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free(lkeymap);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -297,3 +281,34 @@ get_keymaps(int keylayout, struct xrdp_keymap *keymap)
|
|||||||
g_free(filename);
|
g_free(filename);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
int km_load_file(const char *filename, struct xrdp_keymap *keymap)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
LOG(LOG_LEVEL_INFO, "Loading keymap file %s", filename);
|
||||||
|
fd = g_file_open(filename);
|
||||||
|
|
||||||
|
if (fd != -1)
|
||||||
|
{
|
||||||
|
/* read the keymaps */
|
||||||
|
km_read_section(fd, "noshift", keymap->keys_noshift);
|
||||||
|
km_read_section(fd, "shift", keymap->keys_shift);
|
||||||
|
km_read_section(fd, "altgr", keymap->keys_altgr);
|
||||||
|
km_read_section(fd, "shiftaltgr", keymap->keys_shiftaltgr);
|
||||||
|
km_read_section(fd, "capslock", keymap->keys_capslock);
|
||||||
|
km_read_section(fd, "capslockaltgr", keymap->keys_capslockaltgr);
|
||||||
|
km_read_section(fd, "shiftcapslock", keymap->keys_shiftcapslock);
|
||||||
|
km_read_section(fd, "shiftcapslockaltgr", keymap->keys_shiftcapslockaltgr);
|
||||||
|
|
||||||
|
g_file_close(fd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG(LOG_LEVEL_ERROR, "Error loading keymap file %s (%s)", filename, g_get_strerror());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -411,6 +411,9 @@ get_char_from_scan_code(int device_flags, int scan_code, int *keys,
|
|||||||
int
|
int
|
||||||
get_keymaps(int keylayout, struct xrdp_keymap *keymap);
|
get_keymaps(int keylayout, struct xrdp_keymap *keymap);
|
||||||
|
|
||||||
|
int
|
||||||
|
km_load_file(const char *filename, struct xrdp_keymap *keymap);
|
||||||
|
|
||||||
/* xrdp_login_wnd.c */
|
/* xrdp_login_wnd.c */
|
||||||
/**
|
/**
|
||||||
* Gets the DPI of the login (primary) monitor
|
* Gets the DPI of the login (primary) monitor
|
||||||
|
Loading…
Reference in New Issue
Block a user