Ubuntu: Stateless layout switching in Ubuntu 14.04



I use extensively two keyboard layouts (latin for English, and cyrillic for Ukrainian and Russian), and it bothers me to experience my mode errors because of the additional bit of UI state: the current layout.

I used to eliminate them completely by using stateless layout switching, whereby one has no next layout action (as such an action is based on the current state, which is easy to forget for the user, and so leads to errors), rather only two actions:

  1. enable latin layout;
  2. enable cyrillic layout.

This was trivially accomplishable in pre-Saucy releases. As illustrated on the screenshot above.

However, that settings window was destroyed in Saucy.

How do I get my stateless switching now?


This command will set layout to the first one (It works nicely with Unity/Gnome Indicator, Ubuntu 13.10/14.04):

gsettings set org.gnome.desktop.input-sources current 0  

You can use tweak tools, gnome action, compiz action plugin..etc to create a keyboard shortcut for it.

Layouts are indexed starting from 0. So you can make shortcut for any layout in the list.

You can use this to create complex script for last layout without giving an index:

 gsettings get org.gnome.desktop.input-sources sources  


 gsettings set org.gnome.desktop.input-sources current $(($(gsettings get org.gnome.desktop.input-sources sources | grep -Po "'[[:alpha:]]+'\)" | wc -l)-1))  


The keyboard options in Ubuntu and GNOME are nothing but a frontend to the X keyboard extension (XKB). If you are fine with configuring things manually you can easily reenable all of the now-missing options with a setxkbmap command line.

For instance, to set a non-modal switch between Russian and English keyboard layouts you can use the following command:

setxkbmap -layout us,ru -option grp:shift_caps_switch  

This will enable these XKB settings for the current session. If you want to make the change permanent you will have to add the command above to your startup applications.

If you are interested in the various other settings you can control with setxkbmap, I recommend going though the manual (man setxkbmap) and taking a look at /usr/share/X11/xkb/rules/base.lst. The latter documents all different ways to configure the compose key, keyboard layout toggle, etc.

The following is the base.lst section on keyboard layout switching:

! option    grp                  Key(s) to change layout    grp:switch           Right Alt (while pressed)    grp:lswitch          Left Alt (while pressed)    grp:lwin_switch      Left Win (while pressed)    grp:rwin_switch      Right Win (while pressed)    grp:win_switch       Any Win key (while pressed)    grp:caps_switch      Caps Lock (while pressed), Alt+Caps Lock does the original capslock action    grp:rctrl_switch     Right Ctrl (while pressed)    grp:toggle           Right Alt    grp:lalt_toggle      Left Alt    grp:caps_toggle      Caps Lock    grp:shift_caps_toggle Shift+Caps Lock    grp:shift_caps_switch Caps Lock (to first layout), Shift+Caps Lock (to last layout)    grp:win_menu_switch  Left Win (to first layout), Right Win/Menu (to last layout)    grp:lctrl_rctrl_switch Left Ctrl (to first layout), Right Ctrl (to last layout)    grp:alt_caps_toggle  Alt+Caps Lock    grp:shifts_toggle    Both Shift keys together    grp:alts_toggle      Both Alt keys together    grp:ctrls_toggle     Both Ctrl keys together    grp:ctrl_shift_toggle Ctrl+Shift    grp:lctrl_lshift_toggle Left Ctrl+Left Shift    grp:rctrl_rshift_toggle Right Ctrl+Right Shift    grp:ctrl_alt_toggle  Alt+Ctrl    grp:alt_shift_toggle Alt+Shift    grp:lalt_lshift_toggle Left Alt+Left Shift    grp:alt_space_toggle Alt+Space    grp:menu_toggle      Menu    grp:lwin_toggle      Left Win    grp:rwin_toggle      Right Win    grp:lshift_toggle    Left Shift    grp:rshift_toggle    Right Shift    grp:lctrl_toggle     Left Ctrl    grp:rctrl_toggle     Right Ctrl    grp:sclk_toggle      Scroll Lock    grp:lctrl_lwin_rctrl_menu LeftCtrl+LeftWin (to first layout), RightCtrl+Menu (to second layout)  

The various XKB settings are also documented under man 7 xkeyboard-config.

If setxkbmap doesn't work for you you can try setting the XKB options through dconf instead:

  1. Install dconf-editor (sudo apt-get install dconf-editor)
  2. Open dconf editor from your dash and navigate to org â†' gnome â†' desktop â†' input-sources
  3. Add your XKB settings to xkb-options in form of an array. E.g.: ['grp:shift_caps_switch']

Source: Make setxkbmap preferences being set at startup


Maybe just using the Tweak Tool:

enter image description here



Turns out Cinnamon desktop has that option still! Nice.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »