Impossible to switch to the previous keyboard layout (ISO_Prev_Group is ignored)
Affected version
Gentoo, mutter 3.38.3 (should be the same on master), X11.
Bug summary
/usr/share/X11/xkb/symbols/group defines different switching methods, which map modifier keys to the keysyms that switch layouts: ISO_Next_Group, ISO_Prev_Group, ISO_First_Group and ISO_Last_Group. /usr/share/X11/xkb/compat/iso9995 assigns the LockGroup action (with different parameters) to these keysyms. libxkbcommon knows how to handle this action and switch layouts.
The problem is that mutter implements some custom mechanism for switching keyboard layouts, which comes in conflict with the XKB configs under /usr/share/X11/xkb/. If my understanding is right, it grabs the modifiers associated with the ISO_Next_Group keysyms, preventing libxkbcommon from handling them, and tries to replicate the layout switching behavior by emitting the MODIFIERS_ACCELERATOR_ACTIVATED signal on keypress, which is then handled by gnome-shell.
This mechanism has several drawbacks:
- Only ISO_Next_Group is supported. The other three keysyms to switch layouts are ignored. Hence, some switching methods are broken or do not work correctly (shifts_toggle, shift_caps_switch).
- Several well-known switching methods are hardcoded in mutter, which makes it incompatible with any customization (e.g., changing the XKB configs or loading custom keymaps with xkbcomp).
- Some glitches happen, for example, if grp_led:scroll is set, sometimes pressing ISO_Prev_Group lights up the LED without switching the layout (the layout is still never switched with ISO_Prev_Group).
From a quick glance at kwin and sway it looks that they simply rely on libxkbcommon to handle all the shortcuts in a standard way, and it should also work on wayland (though I haven't tested). Why is this mechanism even needed in mutter? What problem does it solve?
Steps to reproduce
- Add three regular (not ibus) keyboard layouts in GNOME settings.
gsettings set org.gnome.desktop.input-sources xkb-options "['grp:shifts_toggle', 'grp_led:scroll']"
- Press LeftShift+RightShift: the layout switches to the next one.
- Press RightShift+LeftShift: the layout doesn't switch to the previous one. Sometimes the Scroll Lock LED lights up (and stays lit).
gsettings set org.gnome.desktop.input-sources xkb-options "['grp:shift_caps_switch', 'grp_led:scroll']"
- Press CapsLock or Shift+CapsLock: nothing happens. Sometimes the Scroll Lock LED lights up (and stays lit).
What happened
The configured hotkey to switch to the next layout worked, while the ones to switch to the previous one, to the first one and to the last one didn't. Sometimes the Scroll Lock LED lights up, even when the current layout is the first one.
What did you expect to happen
All hotkeys work correctly, allowing to switch to the next, previous, first and last layouts. Scroll Lock lights up if and only if the current layout is not the first one.