It can be done with a script.
Now you can switch layout by running for instance
mylayouts us
mylayouts ro_std
And that in turn allows you to create custom shortcuts for the purpose.
This is the example script:
#!/bin/bash -e
# layouts
us="('xkb', 'us')"
ro_std="('xkb', 'ro+std')"
latam="('xkb', 'latam')"
es="('xkb', 'es')"
case $1 in
us) NEW=us
;;
ro_std) NEW=ro_std
;;
latam) NEW=latam
;;
es) NEW=es
;;
*) echo "Invalid argument"
exit 1
;;
esac
NEWLIST="[${!NEW}"
for L in 'us' 'ro_std' 'latam' 'es'; do
if [ "$L" = "$NEW" ]; then
continue
else
NEWLIST="$NEWLIST, ${!L}"
fi
done
NEWLIST="$NEWLIST]"
gsettings set org.gnome.desktop.input-sources sources "[${!NEW}]"
gsettings set org.gnome.desktop.input-sources sources "$NEWLIST"
If you adapt the script to your needs, you can now from Ubuntu Settings
create custom shortcut like:
name: us_colemak
command: mylayouts.sh us_colemak
shortcut: Ctrl + Shift + 5
Caveat:
Using numerical keys as part of the shortcut is a bit tricky. If you for instance use the English (US) layout when creating a shortcut by pressing Ctrl+Shift+2, the shortcut actually created is Ctrl + Shift + @ (since Shift+2 results in the @ character with the English (US) layout). Then, if you for instance are on a latin layout, where Shift+2 results in the " character, the shortcut Ctrl+Shift+2 won't give you the expected result.
Probably it's less error prone to use letters instead of numbers.
In any case, this answer is not a perfect solution. There is apparently room for improvement.