The keyboard layout matching algorithm can assign a negative score to a keyboard layout. If the user has a strange keyboard layout, possibly a custom one, it might happen that all keyboard layouts known by Wine get a negative score. This is not an error in itself, and we should still strive to find the best match.
Currently the matching algorithm is broken in such a situation, because it initializes max_score to zero, meaning that if all layouts have negative score, then the first one will be arbitrarily selected. Fixing the initialization to a very negative number the best match will be found, even if with negative score.
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- dlls/winex11.drv/keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/winex11.drv/keyboard.c b/dlls/winex11.drv/keyboard.c index d86f418a64e..5fde07ead31 100644 --- a/dlls/winex11.drv/keyboard.c +++ b/dlls/winex11.drv/keyboard.c @@ -1432,7 +1432,7 @@ X11DRV_KEYBOARD_DetectLayout( Display *display ) KeySym keysym = 0; const char (*lkey)[MAIN_LEN][4]; unsigned max_seq = 0; - int max_score = 0, ismatch = 0; + int max_score = INT_MIN, ismatch = 0; char ckey[256][4];
syms = keysyms_per_keycode;
Key codes returned by X11 need not and in general are not valid ASCII bytes, therefore we should escape them before writing them in the log.
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- dlls/winex11.drv/keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/winex11.drv/keyboard.c b/dlls/winex11.drv/keyboard.c index 5fde07ead31..c6eab6f5cfa 100644 --- a/dlls/winex11.drv/keyboard.c +++ b/dlls/winex11.drv/keyboard.c @@ -1505,7 +1505,7 @@ X11DRV_KEYBOARD_DetectLayout( Display *display ) char str[5]; for (i = 0; i < 4; i++) str[i] = ckey[keyc][i] ? ckey[keyc][i] : ' '; str[4] = 0; - TRACE_(key)("mismatch for keycode %u, got %s\n", keyc, str); + TRACE_(key)("mismatch for keycode %u, got %s\n", keyc, debugstr_a(str)); mismatch++; score -= syms; }