-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds cross-platform compatible virtual-key codes to vm-display-x11 plugin #599
base: Cog
Are you sure you want to change the base?
Adds cross-platform compatible virtual-key codes to vm-display-x11 plugin #599
Conversation
… the virtual keys on other platforms because no information about locale.
…ing issues: keyCode -> ascii, codes -> keyNameEntries, nameForKeycode -> nameForKeysym
…- that event's not-localized KeyCode.
Virtual key codes are per se fine with me. Or if we are interested in the physical ones, USB HID Usage IDs or SDL scancodes. |
Sure. This here is a fix that does not require touching all other platforms. Since both macOS and Windows are fine and supported in Squeak, only X11 seems to be the current issue. |
what keycodes are we using in the other worlds? |
SDL does in C what Squeak 6.0alpha already does in Smalltalk. Looking at "SDL_x11keyboard.c" or "scancodes_windows.h", we have in Now, SDL has its own Also, SDL uses a similar "hack" for alpha-numeric keys. See SDL_x11keyboard.c function "X11_KeyCodeToSDLScancode". This PR is als complete as in can get for X11. I am currently fixing up some modifier issues when pressing only modifier keys. |
My issue is that we migh be introducing some new code here without having them mean anything anywhere else… Also, what does "virtual" mean here? are we trying to map to the thing printed on the keyborard or to the position of the key pressed? |
Yes. It would be better if we had access to both the "keysym" and the "keycode" in the Smalltalk image. Unfortunately, there is only a single value reserved for this in our event structure. So, we have to merge both value ranges in a meaningful way. I just did that. You can restore the "keysym" in the image by setting 0xff__ again. Do you have a better Idea on merging "keysym" (special keys and alpha-num latin-1) and "keycode" (for shifted alpha-num keys) into a single value? That single-byte lookup table in Squeak is quite handy ... and fast. :-) And what the other two platforms provide.
The concept stems from the MSDN documentation. I elaborated on this topic several times on squeak-dev already:
The code reads |
…es. That is, replace 8-space-tabs with up to 8 actual spaces because the file's indent is 2 spaces.
…ts. Reuse the side-effects in translateCode(), even though its actual job is to translate selected KeySyms into the ASCII range such as for XK_Left or XK_Insert. Thanks to the UCS4 mapping in xkeysym2ucs4(), there is almost no use for x2sqKeyPlain() and translateCode() anymore. Especially now that xkey2sqVirtualKeyCode() provides the required (virtual) key codes for EventKeyDown and EventKeyUp.
… true ] on method [ markAndShouldScan: ]
…true ] on method [ markAndShouldScan: ] KILLED by 1/10 test cases.
…emantics. VM mutation. ] on method [ unlinkSolitaryFreeTreeNode: ] 152 test cases.
…mantics. VM mutation. ] on method [ unlinkSolitaryFreeTreeNode: ] 1/152 Test Cases are NOT EQUIVALENT
Since X11 does not provide a localized version of virtual keys, I mapped the X11 event's
KeySym
to such a "virtual-key code", usingevt.keycode
only as a fall back. It's not perfect but close to what Windows and macOS have.Here is the mapping schema:
Here is the new mapping table for Squeak:
new-x11-virtual-keys.1.cs.txtnew-x11-virtual-keys.6.cs.txt (updated 2021-10-06 14:00 UTC)
See /usr/include/X11/keysymdef.h to understand the "SPECIAL KEYS" (masked 0xff00).
The biggest remaining issue is all those "OEM keys", which means the ones you push for "+" or "/" or "~" and so on.
Note that the idea of having a localized version of the virtual key is that you can print it in an application's user interface. Would be really annoying if an app insists on, e.g., Z while you actionally pushed Y.
You can try out the changes in the
KeyboardExerciser
in Squeak 6.0alpha. The test is that the tool shows the labels of your physical keyboard while you keep on pressing keys or key combinations. Note that you need a physical keyboard that matches your keyboard layout. That is, US keyboard for US key layout.