RFR: 8278924: [Linux] Robot key test can fail if multiple keyboard layouts are installed
Thiago Milczarek Sayao
tsayao at openjdk.org
Fri Apr 7 23:25:53 UTC 2023
On Sun, 2 Apr 2023 23:36:27 GMT, Martin Fox <duke at openjdk.org> wrote:
>> @beldenfox Could you point out which tests were failing?
>> `test.robot.javafx.embed.swing.SwingNodeJDialogTest` is getting stuck for me.
>
> @tsayao The best place to start is with the manual test that I added to PR #425 (KeyboardTest.java). That test works on Windows, Mac, and Linux and uses a Robot to throw a whole slew of platform key events at the system and then verify that the right JavaFX KeyEvents come through on the other side.
>
> The primary motivation for this PR is to pave the way for future PR's. Accelerators involving punctuation and symbols aren't working at all well on Linux (see [JDK-8273743](https://bugs.openjdk.org/browse/JDK-8273743)) and having a working Robot in hand will be extremely helpful in testing the fixes. The manual test in #425 can also be configured to test KeyCharacterCombinations (the component that's broken) but for now you can ignore all that.
>
> Unfortunately the manual test itself is a big chunk of code that needs to be reviewed but it is the first comprehensive test written for JavaFX keyboard handling. I wish I could make it shorter (it looks more complicated than it is) but the only way to test the keyboard system is to press a lot of keys.
>
> BTW, the bot that kicked this PR has lousy timing. I'll be out of town for most of the coming week and will be away from my Linux box.
@beldenfox I've done some research to understand your code. It seems `gdk_keymap_get_entries_for_keyval` will return multiple entries for hardware keys (as many as the layouts installed). So your change queries which one corresponds to the current layout. It seems correct to me, but I'll leave some suggestions.
To observe the problem using pure gdk:
#include <gdk/gdk.h>
int main(int argc, char *argv[]) {
GdkKeymap *keymap;
guint keyval = GDK_KEY_a; // Example keyval
guint upper_keyval = gdk_keyval_to_upper(keyval);
GdkKeymapKey *keys;
gint n_keys;
gint group;
// Initialize GDK
gdk_init(&argc, &argv);
// Get the default keymap
keymap = gdk_keymap_get_for_display(gdk_display_get_default());
// Get the keycodes for the uppercase character
gdk_keymap_get_entries_for_keyval(keymap, upper_keyval, &keys, &n_keys);
// Print the keycodes
for (int i = 0; i < n_keys; i++) {
printf("Keycode: %d\n", keys[i].keycode);
}
// Free resources
g_free(keys);
g_object_unref(keymap);
return 0;
}
gcc -o testkey testkey.c `pkg-config --cflags --libs gdk-3.0`
-------------
PR Comment: https://git.openjdk.org/jfx/pull/718#issuecomment-1500719003
More information about the openjfx-dev
mailing list