How to prevent gnome to change the language input order when switching languages?

Here’s my input settings (notice the order of the languages in the list which is my preference.)

enter image description here

Now initially when I invoke the shortcut to switch the input the list looks like that (as expected) :

enter image description here

Now I select Korean input (second item) and invoke the switch shortcut again, here’s how the list looks like :

enter image description here

As you can see the order changed.
And now if I select another input and try to switch again the list is completely shifted.

Is there a way to prevent gnome from rearranging the list all the time ?

I think it’s worth mentioning my job is about languages and I switch languages all the time (searching a chinese character, going back to english keyboard, going back to a korean dictionary to find out a definition, etc …), I found that the brain remembers more easily the location of the languages in the list rather than what’s actually written, and that’s how Windows do.
I wish there’s a way to fix that, if not I would have to report that as an issue on the gnome website.

Thanks in advance.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Since, there is no gnome-shell-extension as of now for the static shifting of keyboard layout using default shortcuts Super+Space and Shift+Super+Space..

and the comments about this link Static ordering of keyboard layout switching in Ubuntu 17.10 and later with GNOME 3 from OP

the problem with the solution proposed in the link (Alt+Shift) is that
it lacks a visual feedback, and can’t use shortcut for previous (like
win+shift+space to go back one input). So it’s not really satisfying.

I could achieve at least one point out of two (Visual Feedback & Switching back to previous layout) with below workaround.

Workaround

OS: Ubuntu 19.10

Reference: Manipulate the Default Shortcut Super+Space for Switching to Next Input Source without Graphical Representation

Create two scripts with below contents, I have named those as “SuSpace.sh” and “ShSuSpace.sh”

SuSpace.sh

#!/bin/bash

totalLang=$(gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager()._mruSources.length" | grep -oP "(?<=').*?(?=')")

currentLang=$(gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().currentSource.index" | grep -oP "(?<=').*?(?=')")

declare -i math=$currentLang+1

if [ "$math" -lt "$totalLang" ]; then
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources["$currentLang+1"].activate()"
else
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources[0].activate()"
fi

ShSuSpace.sh

#!/bin/bash

totalLang=$(gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager()._mruSources.length" | grep -oP "(?<=').*?(?=')")

currentLang=$(gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().currentSource.index" | grep -oP "(?<=').*?(?=')")

declare -i math=$currentLang-1

if [ "$math" -eq -1 ]; then
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources["$totalLang-1"].activate()"
else
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager().inputSources["$currentLang-1"].activate()"
fi

you can create custom shortcuts for these two scripts as per your wish.

enter image description here

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply