Fixed reported cases of "Keyboard layout unknown" messages

In all cases they were using SDL_SCANCODE_TABLE_XFREE86_2 with some keycodes remapped or fewer than expected keycodes. This adds a sanity check that catches all of them and gives them the right scancode table.
This commit is contained in:
Sam Lantinga 2022-10-13 23:23:55 -07:00
parent 2c1923859a
commit 139192140c
1 changed files with 13 additions and 4 deletions

View File

@ -605,10 +605,6 @@ X11_InitKeyboard(_THIS)
int table_size; int table_size;
const SDL_Scancode *table = SDL_GetScancodeTable(scancode_set[i], &table_size); const SDL_Scancode *table = SDL_GetScancodeTable(scancode_set[i], &table_size);
/* Make sure the scancode set isn't too big */
if (table_size > (max_keycode - min_keycode + 1)) {
continue;
}
distance = 0; distance = 0;
for (j = 0; j < SDL_arraysize(fingerprint); ++j) { for (j = 0; j < SDL_arraysize(fingerprint); ++j) {
if (fingerprint[j].value < 0 || fingerprint[j].value >= table_size) { if (fingerprint[j].value < 0 || fingerprint[j].value >= table_size) {
@ -622,6 +618,19 @@ X11_InitKeyboard(_THIS)
best_index = i; best_index = i;
} }
} }
if (best_index < 0 || best_distance > 2) {
/* This is likely to be SDL_SCANCODE_TABLE_XFREE86_2 with remapped keys, double check a rarely remapped value */
int fingerprint_value = X11_XKeysymToKeycode(data->display, 0x1008FF5B /* XF86Documents */) - min_keycode;
if (fingerprint_value == 235) {
for (i = 0; i < SDL_arraysize(scancode_set); ++i) {
if (scancode_set[i] == SDL_SCANCODE_TABLE_XFREE86_2) {
best_index = i;
best_distance = 0;
break;
}
}
}
}
if (best_index >= 0 && best_distance <= 2) { if (best_index >= 0 && best_distance <= 2) {
SDL_Keycode default_keymap[SDL_NUM_SCANCODES]; SDL_Keycode default_keymap[SDL_NUM_SCANCODES];
int table_size; int table_size;