I am using gnome 3.22.1 but problem exists since 3.18.
Before that (don't remember the exact version) I was able to switch keyboard layout using xkb-witch, simple application that uses X.org bindings under the hood.
After 3.18 if you run xkb-switch, the keyboard layout won't be switched in gnome. Further investigation have shown that layout switching is working, but for a very short amount of time.
If you run this script:
for i in $(seq 1000); do
lang=$(xkb-switch -s ru; xkb-switch);
if [[ "$lang" == "ru" ]]; then
echo $lang;
fi;
done
You will get from 3 to 20 "successfull" layout switchings, depending on how lucky you are.
After googling this problem I the following advice:
gsettings set org.gnome.desktop.input-sources current 0
The setting is being changed, but the layout stays the same.
I have found one "hacky" method to change the layout:
setxkbmap us,ru
setxkbmap ru,us
but the gnome shell isn't aware of that change, and shows wrong language in layout indicator.
I've posted about this problem (sorry, not enough reputation, https ://bbs.archlinux.org/viewtopic.php?pid=1657582 https ://github.com/ierton/xkb-switch/issues/15), but had no luck getting any good answers.
And at this point I'm stuck. I'm not skilled enough to identify the problem in gnome shell code. I'm not even sure it is it's(gnome shell's) problem.
What I want is a gnome-aware way to switch keyboard layout from terminal. Can someone point me in the right direction? Should I file this as a bug (especially the fact that keyboard layout cannot be changed through gsettings)?