Alt-Key not working on Linux


#1

Hey :)

I'm on Arch LInux with Gnome 3.18.

In my mouseDown(), ... functions the Alt-key never gets set as a modifier. I tried to find the error and after searching in the linux windowing code I think I found it. After the Alt-key was pressed and a keyboard event was send everything is fine and the flag for the Alt-key is set properly. But as soon as you move the mouse it gets unset.

The difference between the two cases is that after a keyboard event updateKeyModifiersFromSym() in juce_linux_Windowing.cpp is called and after a mouse event the function updateKeyModifiers() is called.

The updateKeyModifiers() triggered the Alt-key when I pressed Meta on my keyboard. It checks for a flag specified by Keys::AltMask that is set in updateModifierMappings(). The keycode for Alt gets determined by XKeysymToKeycode(display, XK_Alt_L), and this seems to be the source of the whole error. On my system that function call returns the same keycode for XK_Alt_L and XK_Meta_L. Based on that error also the value for Keys::AltMask gets set wrong. With my configuration everything worked correct when I set Keys::AltMask manually to 8, but I'm not sure how to make this work in a dynamic way with false output from XKeysymToKeycode().

(I'm also not 100% sure if the bitshifting "if (mapping->modifiermap [i << 1] == altLeftCode)" is correct that way, according to https://tronche.com/gui/x/xlib/input/keyboard-encoding.html#XModifierKeymap it should be something like modifiermap[i * mapping->max_keypermod])

Already lots of thanks in advance :)


#2

Could anyone reproduce this issue? Or is this a problem with my setup?


#3

I’ve encountered the exact same issue and traced it back to the exact same location. I’ve worked around it in our code but I don’t know enough of X programming to fix it properly.

Regards,
Thomas


#4

I’ve spent some time fixing this. The root problem is indeed how the Modifier mask for the alt key is determined. The code is wrong.

Attached is a patch that fixes the problem.

JUCE_alt_key_windows.txt (1.9 KB)

cheers,
Thomas