Skip to content
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

Map function keys independently of key group #1598

Open
wants to merge 3 commits into
base: master
from

Conversation

@ZenulAbidin
Copy link

ZenulAbidin commented Nov 21, 2019

XkbKeycodeToKeysym in function translateKeyCode in x11_init.c is returning keySym value of -1 when called with the key's scancode. This causes all function and numpad keys to be mapped to GLFW_KEY_UNKNOWN.

Printable keys register correctly because they are mapped explicitly, so I mapped the other keys like that too. There is no reason to use translateKeyCode now.

ZenulAbidin added 2 commits Nov 21, 2019
X11: Fix bug that mapped all function keys to GLFW_KEY_UNKNOWN
@ZenulAbidin ZenulAbidin requested a review from elmindreda as a code owner Nov 21, 2019
@ZenulAbidin

This comment has been minimized.

Copy link
Author

ZenulAbidin commented Nov 21, 2019

Also, this bug is not present in the latest release.

@elmindreda elmindreda added the X11 label Dec 19, 2019
@elmindreda

This comment has been minimized.

Copy link
Member

elmindreda commented Dec 23, 2019

Also, this bug is not present in the latest release.

Do you mean that this bug is present in master but not in 3.3?

@elmindreda elmindreda changed the title X11: Fix bug that mapped all function keys to GLFW_KEY_UNKNOWN Fix bug that mapped all function keys to GLFW_KEY_UNKNOWN Dec 23, 2019
@elmindreda elmindreda self-assigned this Dec 23, 2019
@elmindreda elmindreda added this to In progress in elmindreda Dec 23, 2019
Syncing with upstream glfw
@elmindreda elmindreda removed this from In progress in elmindreda Jan 2, 2020
@ZenulAbidin

This comment has been minimized.

Copy link
Author

ZenulAbidin commented Jan 2, 2020

After running git bisect, I have discovered that this regression was introduced in commit b3eb6dd. The problem is triggered here:

glfw/src/x11_init.c

Lines 670 to 676 in fe57e3c

_glfw.x11.xkb.group = 0;
XkbStateRec state;
if (XkbGetState(_glfw.x11.display, XkbUseCoreKbd, &state) == Success)
{
XkbSelectEventDetails(_glfw.x11.display, XkbUseCoreKbd, XkbStateNotify, XkbAllStateComponentsMask, XkbGroupStateMask);
_glfw.x11.xkb.group = (unsigned int)state.group;
}

This is related to issue #1462, because I have an English QWERTY keyboard layout and also an Arabic QWERTY layout on my system (this may be why you couldn't reproduce it). The issue is the function keys are only on group 0. My Arabic layout is group 0 while my English layout is group 1. So the function keys only work if I start the program in Arabic layout. If I then switch to English layout while the program is running, it still works, but it's very inconvenient.

This bug is reproducible in master as well as in GLFW 3.3.1.

Over here:

glfw/src/x11_init.c

Lines 256 to 262 in fe57e3c

// Map the key name to a GLFW key code. Note: We only map printable
// keys here, and we use the US keyboard layout. The rest of the
// keys (function keys) are mapped using traditional KeySym
// translations.
if (strcmp(name, "TLDE") == 0) key = GLFW_KEY_GRAVE_ACCENT;
else if (strcmp(name, "AE01") == 0) key = GLFW_KEY_1;
else if (strcmp(name, "AE02") == 0) key = GLFW_KEY_2;

Since it's assigning ASCII keys here and they return the native character in the current keyboard layout, it would be simpler to assign the function keys there too. The function key names I added in my PR were taken from the evdev key-codes list and I tested all of them.

@elmindreda elmindreda added this to the 3.3.2 milestone Jan 2, 2020
@ZenulAbidin ZenulAbidin changed the title Fix bug that mapped all function keys to GLFW_KEY_UNKNOWN Map function keys independently of key group Jan 2, 2020
@elmindreda elmindreda added this to Work queue in elmindreda Jan 2, 2020
@elmindreda elmindreda added verified and removed cannot reproduce labels Jan 2, 2020
@elmindreda

This comment has been minimized.

Copy link
Member

elmindreda commented Jan 2, 2020

Successfully reproduced on Cygwin/X running MATE with the default Arabic layout.

@elmindreda elmindreda modified the milestones: 3.3.2, 3.3.3 Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
elmindreda
Work queue
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.