We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3094

Summary: SDL should fall back to old Xkeysym handling if server doesn't support XKB extension
Product: SDL Reporter: Bill Lash <william.lash>
Component: eventsAssignee: Alex Baines <alex>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz
Version: 2.0.3   
Hardware: x86_64   
OS: Linux   
Attachments: Patch to fall back to old method if server does not support XKB extension
Patch to map number and letter keys correctly and add some other keys
Patch for XKB fallback and xvnc scancode set

Description Bill Lash 2015-08-15 00:00:20 UTC
Created attachment 2240 [details]
Patch to fall back to old method if server does not support XKB extension

I occasionally run mame over VNC to test out a few things.  Since it has upgraded to SDL2.0, this no longer works, because VNC does not support the XKB extension. 

SDL keyboard handling should fall back to the old XKeysym handling if the server does not support XKB.  I am attaching a patch that works for me.  It probably needs to be cleaned up a bit though.
Comment 1 Bill Lash 2015-08-15 00:15:17 UTC
Should probably have shown the messages that mame prints that led me to the conclusion that this was an SDL issue:

lash@mamecab1:/arcade2/mameupdate$ ./mame64 -rp roms -renderdriver software -videodriver x11 dkong
Xlib:  extension "RANDR" missing on display ":44".
Keyboard layout unknown, please send the following to the SDL mailing list (sdl@libsdl.org):
Value 1 not supported for option sound - falling back to auto
The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode 76 (68), X11 KeySym 0x0 ((null)).
The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode 75 (67), X11 KeySym 0x0 ((null)).
The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode 74 (66), X11 KeySym 0x0 ((null)).
The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode 75 (67), X11 KeySym 0x0 ((null)).
The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode 73 (65), X11 KeySym 0x0 ((null)).
Comment 2 Bill Lash 2015-08-15 06:00:12 UTC
Created attachment 2241 [details]
Patch to map number and letter keys correctly and add some other keys
Comment 3 Bill Lash 2015-08-15 06:01:08 UTC
After applying the above patch, while many keys work, I found several the didn't register, and some that didn't work correctly (the number keys, 1 acted as return and 2 as escape).  Looking at the output, I found:

lash@mamecab1:/arcade2/mameupdate$ ./mame64 -rp roms -renderdriver software -videodriver x11 dkong
Xlib:  extension "RANDR" missing on display ":44".
Keyboard layout unknown, please send the following to the SDL mailing list (sdl@libsdl.org):
code = 0, sym = 0xFFE3 (Control_L) scancode = 224 (Left Ctrl)
code = 1, sym = 0xFFE4 (Control_R) scancode = 228 (Right Ctrl)
code = 2, sym = 0xFFE1 (Shift_L) scancode = 225 (Left Shift)
code = 3, sym = 0xFFE2 (Shift_R) scancode = 229 (Right Shift)
code = 4, sym = 0xFFE7 (Meta_L) scancode = 227 (Left GUI)
code = 5, sym = 0xFFE8 (Meta_R) scancode = 231 (Right GUI)
code = 6, sym = 0xFFE9 (Alt_L) scancode = 226 (Left Alt)
code = 7, sym = 0xFFEA (Alt_R) scancode = 230 (Right Alt)
code = 8, sym = 0x20 (space) scancode not found
code = 9, sym = 0x30 (0) scancode = 39 (0)
code = 10, sym = 0x31 (1) scancode = 40 (Return)
code = 11, sym = 0x32 (2) scancode = 41 (Escape)
code = 12, sym = 0x33 (3) scancode = 42 (Backspace)
code = 13, sym = 0x34 (4) scancode = 43 (Tab)
code = 14, sym = 0x35 (5) scancode = 44 (Space)
code = 15, sym = 0x36 (6) scancode = 45 (-)
code = 16, sym = 0x37 (7) scancode = 46 (=)
code = 17, sym = 0x38 (8) scancode = 47 ([)
code = 18, sym = 0x39 (9) scancode = 48 (])
code = 19, sym = 0x2D (minus) scancode not found
code = 20, sym = 0x3D (equal) scancode not found
code = 21, sym = 0x5B (bracketleft) scancode not found
code = 22, sym = 0x5D (bracketright) scancode not found
code = 23, sym = 0x3B (semicolon) scancode not found
code = 24, sym = 0x27 (apostrophe) scancode not found
code = 25, sym = 0x60 (grave) scancode not found
code = 26, sym = 0x2C (comma) scancode not found
code = 27, sym = 0x2E (period) scancode not found
code = 28, sym = 0x2F (slash) scancode not found
code = 29, sym = 0x5C (backslash) scancode not found
code = 30, sym = 0x61 (a) scancode not found
code = 31, sym = 0x62 (b) scancode not found
code = 32, sym = 0x63 (c) scancode not found
code = 33, sym = 0x64 (d) scancode not found
code = 34, sym = 0x65 (e) scancode not found
code = 35, sym = 0x66 (f) scancode not found
code = 36, sym = 0x67 (g) scancode not found
code = 37, sym = 0x68 (h) scancode not found
code = 38, sym = 0x69 (i) scancode not found
code = 39, sym = 0x6A (j) scancode not found
code = 40, sym = 0x6B (k) scancode not found
code = 41, sym = 0x6C (l) scancode not found
code = 42, sym = 0x6D (m) scancode not found
code = 43, sym = 0x6E (n) scancode not found
code = 44, sym = 0x6F (o) scancode not found
code = 45, sym = 0x70 (p) scancode not found
code = 46, sym = 0x71 (q) scancode not found
code = 47, sym = 0x72 (r) scancode not found
code = 48, sym = 0x73 (s) scancode not found
code = 49, sym = 0x74 (t) scancode not found
code = 50, sym = 0x75 (u) scancode not found
code = 51, sym = 0x76 (v) scancode not found
code = 52, sym = 0x77 (w) scancode not found
code = 53, sym = 0x78 (x) scancode not found
code = 54, sym = 0x79 (y) scancode not found
code = 55, sym = 0x7A (z) scancode not found
code = 56, sym = 0xFF08 (BackSpace) scancode = 42 (Backspace)
code = 57, sym = 0xFF0D (Return) scancode = 40 (Return)
code = 58, sym = 0xFF09 (Tab) scancode = 43 (Tab)
code = 59, sym = 0xFF1B (Escape) scancode = 41 (Escape)
code = 60, sym = 0xFFFF (Delete) scancode = 76 (Delete)
code = 61, sym = 0xFF50 (Home) scancode = 74 (Home)
code = 62, sym = 0xFF57 (End) scancode = 77 (End)
code = 63, sym = 0xFF55 (Prior) scancode = 75 (PageUp)
code = 64, sym = 0xFF56 (Next) scancode = 78 (PageDown)
code = 65, sym = 0xFF52 (Up) scancode = 82 (Up)
code = 66, sym = 0xFF54 (Down) scancode = 81 (Down)
code = 67, sym = 0xFF51 (Left) scancode = 80 (Left)
code = 68, sym = 0xFF53 (Right) scancode = 79 (Right)
code = 69, sym = 0xFFBE (F1) scancode = 58 (F1)
code = 70, sym = 0xFFBF (F2) scancode = 59 (F2)
code = 71, sym = 0xFFC0 (F3) scancode = 60 (F3)
code = 72, sym = 0xFFC1 (F4) scancode = 61 (F4)
code = 73, sym = 0xFFC2 (F5) scancode = 62 (F5)
code = 74, sym = 0xFFC3 (F6) scancode = 63 (F6)
code = 75, sym = 0xFFC4 (F7) scancode = 64 (F7)
code = 76, sym = 0xFFC5 (F8) scancode = 65 (F8)
code = 77, sym = 0xFFC6 (F9) scancode = 66 (F9)
code = 78, sym = 0xFFC7 (F10) scancode = 67 (F10)
code = 79, sym = 0xFFC8 (F11) scancode = 68 (F11)
code = 80, sym = 0xFFC9 (F12) scancode = 69 (F12)
code = 81, sym = 0xFF8D (KP_Enter) scancode = 88 (Keypad Enter)

Note that all of the letter keys are not found, and the number keys, other than 0 are all strange.  There are also some other codes, SPACE, comma, period ... that aren't set up correctly.

For the number keys, I found the the SDL_SCANCODE_0 is defined as 39 and SDL_SCANCODE_1 - 9 are defined as 30 through 38.  The code was changing the XK_0 through 9, and setting the scancode to SDL_SCANCODE_0 + keycode - XK_0.  I changed this so that all of the codes for numbers are mapped correctly.  The code was also only handling XK_A through XK_Z, and not XK_a through XK_z.  I also added some codes to the table for things like space, comma, period, ...

I am attaching a second patch that resolves this issue.  Now the output looks like:

lash@mamecab1:/arcade2/mameupdate$ ./mame64 -rp roms -renderdriver software -videodriver x11 dkong
Xlib:  extension "RANDR" missing on display ":44".
Keyboard layout unknown, please send the following to the SDL mailing list (sdl@libsdl.org):
code = 0, sym = 0xFFE3 (Control_L) scancode = 224 (Left Ctrl)
code = 1, sym = 0xFFE4 (Control_R) scancode = 228 (Right Ctrl)
code = 2, sym = 0xFFE1 (Shift_L) scancode = 225 (Left Shift)
code = 3, sym = 0xFFE2 (Shift_R) scancode = 229 (Right Shift)
code = 4, sym = 0xFFE7 (Meta_L) scancode = 227 (Left GUI)
code = 5, sym = 0xFFE8 (Meta_R) scancode = 231 (Right GUI)
code = 6, sym = 0xFFE9 (Alt_L) scancode = 226 (Left Alt)
code = 7, sym = 0xFFEA (Alt_R) scancode = 230 (Right Alt)
code = 8, sym = 0x20 (space) scancode = 44 (Space)
code = 9, sym = 0x30 (0) scancode = 39 (0)
code = 10, sym = 0x31 (1) scancode = 30 (1)
code = 11, sym = 0x32 (2) scancode = 31 (2)
code = 12, sym = 0x33 (3) scancode = 32 (3)
code = 13, sym = 0x34 (4) scancode = 33 (4)
code = 14, sym = 0x35 (5) scancode = 34 (5)
code = 15, sym = 0x36 (6) scancode = 35 (6)
code = 16, sym = 0x37 (7) scancode = 36 (7)
code = 17, sym = 0x38 (8) scancode = 37 (8)
code = 18, sym = 0x39 (9) scancode = 38 (9)
code = 19, sym = 0x2D (minus) scancode = 45 (-)
code = 20, sym = 0x3D (equal) scancode = 46 (=)
code = 21, sym = 0x5B (bracketleft) scancode = 47 ([)
code = 22, sym = 0x5D (bracketright) scancode = 48 (])
code = 23, sym = 0x3B (semicolon) scancode not found
code = 24, sym = 0x27 (apostrophe) scancode = 52 (')
code = 25, sym = 0x60 (grave) scancode = 53 (`)
code = 26, sym = 0x2C (comma) scancode = 54 (,)
code = 27, sym = 0x2E (period) scancode = 55 (.)
code = 28, sym = 0x2F (slash) scancode = 56 (/)
code = 29, sym = 0x5C (backslash) scancode = 49 (\)
code = 30, sym = 0x61 (a) scancode = 4 (A)
code = 31, sym = 0x62 (b) scancode = 5 (B)
code = 32, sym = 0x63 (c) scancode = 6 (C)
code = 33, sym = 0x64 (d) scancode = 7 (D)
code = 34, sym = 0x65 (e) scancode = 8 (E)
code = 35, sym = 0x66 (f) scancode = 9 (F)
code = 36, sym = 0x67 (g) scancode = 10 (G)
code = 37, sym = 0x68 (h) scancode = 11 (H)
code = 38, sym = 0x69 (i) scancode = 12 (I)
code = 39, sym = 0x6A (j) scancode = 13 (J)
code = 40, sym = 0x6B (k) scancode = 14 (K)
code = 41, sym = 0x6C (l) scancode = 15 (L)
code = 42, sym = 0x6D (m) scancode = 16 (M)
code = 43, sym = 0x6E (n) scancode = 17 (N)
code = 44, sym = 0x6F (o) scancode = 18 (O)
code = 45, sym = 0x70 (p) scancode = 19 (P)
code = 46, sym = 0x71 (q) scancode = 20 (Q)
code = 47, sym = 0x72 (r) scancode = 21 (R)
code = 48, sym = 0x73 (s) scancode = 22 (S)
code = 49, sym = 0x74 (t) scancode = 23 (T)
code = 50, sym = 0x75 (u) scancode = 24 (U)
code = 51, sym = 0x76 (v) scancode = 25 (V)
code = 52, sym = 0x77 (w) scancode = 26 (W)
code = 53, sym = 0x78 (x) scancode = 27 (X)
code = 54, sym = 0x79 (y) scancode = 28 (Y)
code = 55, sym = 0x7A (z) scancode = 29 (Z)
code = 56, sym = 0xFF08 (BackSpace) scancode = 42 (Backspace)
code = 57, sym = 0xFF0D (Return) scancode = 40 (Return)
code = 58, sym = 0xFF09 (Tab) scancode = 43 (Tab)
code = 59, sym = 0xFF1B (Escape) scancode = 41 (Escape)
code = 60, sym = 0xFFFF (Delete) scancode = 76 (Delete)
code = 61, sym = 0xFF50 (Home) scancode = 74 (Home)
code = 62, sym = 0xFF57 (End) scancode = 77 (End)
code = 63, sym = 0xFF55 (Prior) scancode = 75 (PageUp)
code = 64, sym = 0xFF56 (Next) scancode = 78 (PageDown)
code = 65, sym = 0xFF52 (Up) scancode = 82 (Up)
code = 66, sym = 0xFF54 (Down) scancode = 81 (Down)
code = 67, sym = 0xFF51 (Left) scancode = 80 (Left)
code = 68, sym = 0xFF53 (Right) scancode = 79 (Right)
code = 69, sym = 0xFFBE (F1) scancode = 58 (F1)
code = 70, sym = 0xFFBF (F2) scancode = 59 (F2)
code = 71, sym = 0xFFC0 (F3) scancode = 60 (F3)
code = 72, sym = 0xFFC1 (F4) scancode = 61 (F4)
code = 73, sym = 0xFFC2 (F5) scancode = 62 (F5)
code = 74, sym = 0xFFC3 (F6) scancode = 63 (F6)
code = 75, sym = 0xFFC4 (F7) scancode = 64 (F7)
code = 76, sym = 0xFFC5 (F8) scancode = 65 (F8)
code = 77, sym = 0xFFC6 (F9) scancode = 66 (F9)
code = 78, sym = 0xFFC7 (F10) scancode = 67 (F10)
code = 79, sym = 0xFFC8 (F11) scancode = 68 (F11)
code = 80, sym = 0xFFC9 (F12) scancode = 69 (F12)
code = 81, sym = 0xFF8D (KP_Enter) scancode = 88 (Keypad Enter)
Comment 4 Sam Lantinga 2016-10-01 22:05:50 UTC
Alex, can you update SDL code and check to see if this is still relevant?

Thanks!
Comment 5 Alex Baines 2016-10-02 15:30:01 UTC
For the first patch, I tried using MAME over x11vnc with and without the -noxkb option, but wasn't able to reproduce this issue with SDL 2.0.4, or current hg.
It looks like an improvement, but I think I'd need to know more about what VNC software Bill was using to test it.

For the second patch, I think it would only work on Bill's specific set up.
As I understand it, the keys added to the KeySymToSDLScancode table in this patch are intentionally left out, since they have printable UCS4 representations and are handled differently.

Looking at SDL's X11 scancode detection code in general, it seems to be using a heuristic to determine the layout, and it fails for whatever layout this specific VNC software is presenting. I recently blogged about a nicer way of getting this sort of info without heuristics, but it requires XKB so I'm not sure if it'd help here.

Also I can't see a mapping in /usr/share/X11/xkb/keycodes that would match the list of codes being printed out in the unknown layout message, so I am not sure what to make of it, but these codes could be added to another scancode set if it's common software with a known layout.
Comment 6 Bill Lash 2016-10-02 18:08:17 UTC
Thanks for looking into this.  I just checked, and the vncserver I am using is Xtightvnc.  I think I had tried with the Xvnc  server app with the same results, but I doubt I tried using x11vnc. 

 Here is the version:

lash@mamecab1:~$ Xtightvnc -version
Xvnc version TightVNC-1.3.9
Comment 7 Alex Baines 2016-10-03 10:52:48 UTC
Created attachment 2572 [details]
Patch for XKB fallback and xvnc scancode set

Ok, I tested Xtightvnc and could reproduce the issue. Both of your patches worked well, but the first doesn't apply cleanly any more.

I've made an updated first patch that falls back if Xkb isn't available anymore, and should be compatible with the Xkb group changes I made for bug 3130.

It also adds a new scancode set for xvnc / xtightvnc, so the "unknown" message isn't printed anymore. It seems that after F12 the keys are assigned dynamically though, so a few of the lesser known keys will still generate the message under xvnc, but most will work.

I was wrong about your second patch only working for you, after looking over the code again I think it should be fine to add as well as this one.
Comment 8 Bill Lash 2016-10-03 15:52:57 UTC
Thanks Alex.  I've got to admit that I don't remember all of the details of this issue.  I don't use mame over vnc too often, it is just easier to sit on the couch on my laptop to do a few configuration things instead of standing in front of my mame cabinet balancing a keyboard and mouse.  I'm glad you were able to reproduce it and were able to follow my patches/description to understand what the issue was.
Comment 9 Sam Lantinga 2016-10-08 01:20:17 UTC
Patches are in, thanks!
https://hg.libsdl.org/SDL/rev/30155a7426c4
https://hg.libsdl.org/SDL/rev/c54de4000f9f
Comment 10 Sam Lantinga 2017-08-12 23:26:25 UTC
This is resolved.