Ubuntu – How to NOT show keyboard layout chooser popup when changing language in GNOME 3

gnome-shellkeyboard-layoutlanguageshortcut-keys

Since I installed 17.10, when switching language with the assigned keyboard shortcut I get this switcher "window" that obstructs me from typing for a couple of seconds. And yes, a couple of seconds is a huge amount of time when switching languages a lot.

huge focus-grabbing language-switching indicator

This happens both in X11 and Wayland but doesn't happen (the obstructive window will not appear) when I switch language by clicking on the lang indicator on top bar. Is there any way to tell this window "please go away"?

Best Answer

It is possible by querying gnome-shell via its JS interface with gdbus call (src).

The following script will alternate between two configured input sources. Easy to modify if you have more.

#!/usr/bin/env bash

cur_idx=$(
        gdbus call \
                --session \
                --dest org.gnome.Shell \
                --object-path /org/gnome/Shell \
                --method org.gnome.Shell.Eval \
                "imports
                        .ui.status
                        .keyboard
                        .getInputSourceManager()
                        .currentSource
                        .index" |
        cut -d"'" -f2
)

next_idx=$(( 1 - $cur_idx ))

gdbus call \
        --session \
        --dest org.gnome.Shell \
        --object-path /org/gnome/Shell \
        --method org.gnome.Shell.Eval \
        "imports
                .ui
                .status
                .keyboard
                .getInputSourceManager()
                .inputSources[$next_idx]
                .activate()" \
        &> /dev/null

Make it executable with chmod a+x </path/to/script> and you may then bind it to a custom shortcut key:

Open Settings -> Devices -> Keyboard and click the '+' choice-button at the bottom to assign the script to some shortcut

(For Gnome < 3.x: Settings -> Devices -> Keyboard -> Custom Shortcuts).