Alt+Shift layout switching behaves differently under X11 and Wayland, and differently from Win+Space
Some context: on the PC that I use mostly for work, I am required to use the English locale (en_US.UTF-8), because of screencasts for the English-speaking audience. On a more-personal laptop, I'd rather use a Russian locale (ru_RU.UTF-8). However, on both devices, I need to be able to enter Russian text, and the old habit of using Alt+Shift for switching the layouts is too hard to break. And, both devices should ideally use settings that are as similar as possible.
Steps to reproduce:
- Open GNOME Settings, the Keyboard panel
- Add English (US) and Russian layouts
- Open GNOME Tweaks, go to Additional Layout Options, set Alt+Shift as an additional shortcut for layout switching
Under Xorg, this just works. Layouts can be switched either Win+Space or by Alt+Shift, and the default is English. Exactly what I want. If I press Alt+Shift twice, nothing changes, because it loops through two layouts.
Under Wayland, the results are locale-dependent.
Under the en_US.UTF-8 locale, this setup results in Win+Space switching between English and Russian layouts, with English being the default. However, Alt+Shift switches between three sub-layouts: English (which is the only part of "English (US)"), Russian (which is the first part of the Russian layout), and English (which is the second part of the Russian layout). To go the full cycle, I need to press Alt+Shift three times. This is inconsistent with Win+Space, which needs to be pressed twice and thus does the right job, but is incompatible with my habits.
This is likely because the Russian layout includes the English characters under Wayland and en_US.UTF-8 locale, but not under X11.
If I delete the English layout under Wayland with the en_US.UTF-8 locale, and leave only Russian, then Win+Space no longer works, and Alt+Shift switches between Rissna and English, with Russian being the default.
There is no option to make Alt+Shift switch between English and Russian, with English being the default, and with the full cycle of layout switching consisting of two Alt+Shift steps.
Under the ru_RU.UTF-8 locale, the Russian keyboard layout gets added implicitly to the English one, while English still being the default. Alt+Shift switches between English (part of "English (US)"), Russian (auto-added part of "English (US)"), and Russian (the only part of Russian). Win+Space switches between two layouts, i.e. does the right job.
So the explicit addition of the Russian layout if the locale is ru_RU.UTF-8 is, under Wayland, not necessary and only makes things more confusing. So, if I leave only the English layout under Wayland + ru_RU.UTF-8 locale, I get exactly what I want - except that it is incompatible with the corporate requirement to use the en_US.UTF-8 locale on computers used for customer meetings and screencasts.
A Russian-language forum post describing exactly the same trouble (the need to press Alt+Shift three times, i.e. the illusion that it does not always work): https://www.linux.org.ru/forum/desktop/16915681