kivy / kivy

Open source UI framework written in Python, running on Windows, Linux, macOS, Android and iOS
https://kivy.org
MIT License
17.51k stars 3.06k forks source link

Respect keyboard layout changes in X11 #7507

Open nandoflorestan opened 3 years ago

nandoflorestan commented 3 years ago

(On Linux) if I change the keyboard layout, the Kivy app doesn't realize it. But it should. Almost all (non-Kivy) apps respond to keyboard layout changes immediately.

matham commented 3 years ago

It's not clear what you mean by "change the keyboard layout". Please provide an example.

nandoflorestan commented 3 years ago

Example:

  1. I have 2 keyboard layouts installed on the Gnome desktop -- or on Windows (doesn't matter).
  2. I start with the Dvorak keyboard layout active.
  3. I start the game I am developing with Kivy.
  4. I realize I would prefer the game to run with the QWERTY keyboard layout. So I change it in the OS.
  5. Although pretty much every other application in the system immediately responds to the keyboard layout change, the Kivy app continues to detect keystrokes with the initial keyboard layout, therefore every key I press has the wrong effect.
  6. I need to restart the Kivy app for it to see the keyboard as QWERTY.

If this is still not clear, please ask a more specific question.

matham commented 3 years ago

Oh, I see what you mean. I thought you were referencing the layout of a widget.

I imagine this is either and SDL2 issue, where it doesn't process the keyboard layout change, or kivy is ignoring some keyboard event. You may want to look at the sdl loop and see if we're not handling an event and submit a PR to fix if you can.

nandoflorestan commented 3 years ago

I should clarify that I am incompetent in Cython, C++ and SDL2.

I did find this ticket in the SDL2 bug tracker. Apparently, Kivy needs to handle the SDL_KEYMAPCHANGED event, and as far as I can see, it does not.

Personally I do not know enough to submit a PR.

matham commented 3 years ago

Using the demo app from the other issue I just tried this on Windows and could not replicate.

I started with qwerty and hit the s key. Then with app open I changed layout to dvorak, hit the same key again and the output was different:

Window: keycode=115, scancode=22, modifiers=['numlock']
Keyboard: keycode=(115, 's'), text=s, modifiers=['numlock']
Window: keycode=111, scancode=22, modifiers=['numlock']
Keyboard: keycode=(111, 'o'), text=o, modifiers=['numlock']
nandoflorestan commented 3 years ago

Interesting.

I am on Manjaro Linux, which uses X11 (not Wayland).

https://github.com/libsdl-org/SDL/issues?q=keyboard+layout+change+X11

matham commented 3 years ago

Sounds like our x11 implementation is missing handling of some events. Specifically here we need to handle these events, but we don't.