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

XKB groups and layout changes are not supported on Linux #650

Open
nimble0 opened this issue Nov 30, 2016 · 16 comments · May be fixed by #1164
Open

XKB groups and layout changes are not supported on Linux #650

nimble0 opened this issue Nov 30, 2016 · 16 comments · May be fixed by #1164

Comments

@nimble0
Copy link
Contributor

nimble0 commented Nov 30, 2016

Classification: Bug

Reproducibility: Always

Summary

Emulated keystrokes are affected by KDE keyboard layout remapping.

Steps to Reproduce

  1. Set KDE System Settings keyboard layout to Colemak.
  2. Launch and activate Plover.
  3. Press -T

Expected Results

Output string "the".

Actual Results

Output string "ghf".

Version

Plover version 4.0.0.dev0

First appeared in commit 2419313.

Installed via: Git

Notes

The cause seems to be in _send_keycode, specifically the change from target_window.send_event to xtest.fake_input.

Issue #298 is similiar but this bug appeared later.

Standard Qwerty layout behaves correctly.

Configuration

OS: Linux Mint 17, KDE 4.13.3

@benoit-pierre
Copy link
Member

Plover does not handle keyboard layout changes on Linux (and never has). The layout is parsed one time at initialization. The XKB code provided by python-xlib is also a bit of a misnomer, because it does not use the XKB extension, so Plover also does not know anything about XKB groups (and group changes).

@nimble0 nimble0 changed the title XKB keyboard remapping affects output KDE keyboard remapping affects output Dec 1, 2016
@nimble0
Copy link
Contributor Author

nimble0 commented Dec 1, 2016

The layout isn't changed while Plover is running (I've changed the steps so that's clearer).

Looking at this more closely, there seems to be a global keyboard layout and some more local layout. Prior to that commit, the local layout didn't have any affect on Plover's output. After that commit though, it does affect the Plover's output but Plover is only aware of the global keyboard layout, so whenever the layouts are different, there's a problem.

The global keyboard layout can be changed with setxkbmap. The local one can be changed with KDE System Settings, but setxkbmap also changes it.

I suppose injecting the events into the window skips that local layout remapping.

@benoit-pierre
Copy link
Member

FWIU, there's a global server layout. You can also have per device layouts (including one for the fake XTest keyboard device). And then a layout can have XKB groups, which can be switched per application. Usually, DEs will configure a global layout with multiple XKB groups (one per language configured), and change group per application. Plover only has access to the equivalent of xmodmap -pke, and so is not group aware and behave as if the first group was always selected. It also does handle the fact that different devices can have different layouts, so if for example capslock/backspace are swapped on one keyboard and not on the other, things will get weird when you switch keyboard.

@nimble0
Copy link
Contributor Author

nimble0 commented Dec 5, 2016

That makes sense and is quite helpful to know. I do find it a bit strange there was no problem before.

@HenryMarshall
Copy link

@benoit-pierre I have a keyboard with a non-standard arrangement of keys so the keycodes don't map to the expected physical keys. I don't want to alter the global XKB layout as that would mess with my normal ability to type. If I wanted plover to use a different mapping, would my best bet be to directly alter xkeyboardcontrol's KEYCODE_TO_KEY dictionary?

@nimble0
Copy link
Contributor Author

nimble0 commented Dec 26, 2016 via email

@HenryMarshall
Copy link

@nimble0 The configurator seems unwilling to accept modifier keys (namely: shift and control) as bindings. Are you aware of a workaround for that?

@nimble0
Copy link
Contributor Author

nimble0 commented Dec 26, 2016 via email

@HenryMarshall
Copy link

@nimble0 Thanks muchly, I've got my layout working perfectly. One thing of note though, I was unable to get mapping changes to stick in the master (v4.0.0.dev0) branch. Fortunately, as v3 shares the ~/.local/share/plover/plover.cfg file with v4, I was able to edit it in the stable branch and have the changes reflected in v4 when I restarted. Should I open a separate issue for this?

@nimble0
Copy link
Contributor Author

nimble0 commented Dec 31, 2016 via email

@HenryMarshall
Copy link

Logged in [a new issue]. Thanks for all your help.

@benoit-pierre benoit-pierre marked this as a duplicate of #788 Jul 18, 2017
@benoit-pierre benoit-pierre changed the title KDE keyboard remapping affects output XKB groups and layout changes are not supported on Linux Jul 18, 2017
@benoit-pierre benoit-pierre marked this as a duplicate of #298 Jul 18, 2017
@benoit-pierre benoit-pierre added this to the plover-next milestone Mar 2, 2018
@SimonWoodburyForget
Copy link

SimonWoodburyForget commented May 11, 2019

I might be wrong, but Xlib seems to kind of know what the layout currently is, while xtest just assumes completely differently for one reason or another.

When I do display.keysym_to_keycode(Xlib.XK.string_to_keysym("f")) I'm getting the expected Dvorak keycode 29, but when I use that same keycode through xtest.fake_input(display, X.KeyPress, 29) I get the Qwerty character "y".

Looking around for some temporary solution, I've replaced xtest with python-uinput and it seems to act as expected when using it on a gutted down backend. (taking grabbed keycode events with xlib and shoving them back through uinput)

@benoit-pierre
Copy link
Member

A keysym is not a keycode.

@SimonWoodburyForget
Copy link

Sorry I understand that. I fixed a typo, I miss-typed display.keysym_to_keycode to convert the keysym into a keycode, which returns 29 (the Dvorak layout "f" keycode), as supposed to 41 (on Qwerty), but then xtest goes ahead and types a "y" which is different to what display.keysym_to_keycode thought.

@linduxed
Copy link

I have two questions, for those that might know:

  1. Is Update keymap on keymap change #1164 still the only PR/branch that might be addressing the this issue?
  2. Have the Python libraries changed since this issue was opened, so that one can use something else than python-xlib? Is python-xlib still the main library being used?

@user202729
Copy link
Member

  1. As far as I know, yes. (but as I mentioned there, it does not work too well if the input machine is also keyboard, for it causes a key map refresh every stroke.
  2. Yes, python-xlib is still the main library used in the code base.

jladdjr added a commit to jladdjr/steno-dictionaries that referenced this issue Jul 6, 2024
There are a number of tricky issues with running Plover in this
configuration:

- Plover is not fully compatible with Wayland at this point
- Based on the way Plover works at this time [1], setting
  keyboards to use Dvorak in Wayland (via SwayWM) results in Plover's
  output being filtered through the Dvorak layout, which scrambles the
  letters.

This script attempts to workaround these issues by:

- Referencing a version of Plover that is installed in a virtual environment
- Running a console-based version of Plover [2]
  (that is really wonderful)
- Reloading the SwayWM config which effectively resets the keyboard
  layout used by Plover for unknown reasons. This hack may be
  analagous to [3] (as mentioned in [4]).

[1] openstenoproject/plover#650
[2] https://github.com/psethwick/plover_console_ui
[3] https://github.com/benoit-pierre/config-x11/blob/d9a4be44976a96488a9046f2f6cc91649f35d6f0/bin/setxinput.sh#L171
[4] openstenoproject/plover#788 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants