Implement scancode indexing

The mapping from scancodes to the indexes used in xrdp_keymap
is not well designed and contains an implicit dependency on
keycode values.

This mapping is alse slightly different from the index used for
the 'keys' map in the xrdp_wm structure.

This commit introduces support for mapping scancodes directly
to 'scancode indexes' suitable for indexing into both structures.

Some renaming is also done; [MS-RDPBCGR] uses the terms scancode
and keyCode interchangeably. An effort is made to use key_code for a
raw value from a TS_KEYBOARD_EVENT, and scancode for a value which is
produced by the scancode module.
This commit is contained in:
matt335672
2024-06-14 15:57:13 +01:00
parent d82a172b55
commit c91ef80ca9
11 changed files with 298 additions and 144 deletions
+49 -1
View File
@@ -326,9 +326,48 @@ const struct map_settings global_settings[] =
// Default mapping set is "evdev"
const struct map_settings *settings = &global_settings[SI_EVDEV];
/*****************************************************************************/
int
scancode_to_index(unsigned short scancode)
{
if (scancode <= 0x7f)
{
return scancode;
}
if (scancode <= 0xff)
{
// 0x80 - 0xff : Invalid code
return -1;
}
if (scancode <= 0x17f)
{
// 01x100 - 0x17f : Move bit 9 to bit 8
return (scancode & 0x7f) | 0x80;
}
return -1;
}
/*****************************************************************************/
unsigned short
scancode_to_keycode(unsigned short scancode)
scancode_from_index(int index)
{
index &= 0xff;
unsigned short result;
if (index < 0x80)
{
result = index;
}
else
{
result = (index & 0x7f) | 0x100;
}
return result;
}
/*****************************************************************************/
unsigned short
scancode_to_x11_keycode(unsigned short scancode)
{
unsigned int min = 0;
unsigned int max = settings->size;
@@ -419,3 +458,12 @@ scancode_get_keycode_set(void)
{
return settings->name;
}
/*****************************************************************************/
const char *
scancode_get_xkb_rules(void)
{
// Currently supported keycods map directly to the same name for
// the rules which use them.
return settings->name;
}