4

screenshot

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?

  • 2
    It seems to me I will have to write this menu as an application soon as I need it for my users. Задолбали с такими "улучшениями" – Barafu Albino Aug 18 '14 at 11:33
  • @BarafuAlbino this menu is more or less completely available as part of gnome-tweak-tool. Alas, settings there didn't quite work for me in 14.04. – ulidtko Aug 18 '14 at 11:40
  • @ulidtko, what did you end up with? – zuba May 22 '15 at 12:53
5

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

Like:

 gsettings set org.gnome.desktop.input-sources current $(($(gsettings get org.gnome.desktop.input-sources sources | grep -Po "'[[:alpha:]]+'\)" | wc -l)-1))
  • 2
    This is something, but based on my previous experience with "command" shortcuts I have a suspicion that spawning processes will not be the most pleasant way of switching keyboard layout. Especially during those loaded moments of the system, when it frantically swaps memory back and forth; having seconds of latency for layout switching is not going to be acceptable. I'd definitely prefer something which persists in memory and reacts quickly. – ulidtko Aug 18 '14 at 11:11
  • why don't you give it a try? I don't think that you will have seconds of latency, even when the system is under heavy load. It is a system call nonetheless, but as I've inspected the gsettings source code in the past, it really does harmless things and once it changes the value some corresponding (already running) application takes care of the rest. – hytromo Aug 19 '14 at 16:01
  • 1
    @hakermania at dark times when pulseaudio didn't work well on my system, I've been using pure alsa, plus a custom volume regulator built on the same approach (spawning scripts via hotkeys). Mostly it worked fine, but at times it reacted so dreadfully late, that this caused not only annoyment but also embarassment (imagine not being able to timely turn off, say, an adult video soundtrack, etc). Now I'm soft of reluctant to this approach. – ulidtko Aug 20 '14 at 8:39
4
+250

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 orggnomedesktopinput-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

  • setxkbmap has no effect on my system (probably because they use xim input method instead of xinput). – ulidtko Aug 18 '14 at 11:42
  • @ulidtko I added a section on configuring XKB settings via dconf. Might yield better results on your system. – Glutanimate Aug 18 '14 at 11:59
  • 2
    This a good optiop for gnome. AFAIK xkb-options works only with Gnome, Unity doesn't care about. I've tested setxkbmap before with unity I does work for short period then it reset to Unity settings. It does work well by uninstalling indicator-keyboard and disabling unity layout change shortcut. – user.dz Aug 24 '14 at 17:36
1

Maybe just using the Tweak Tool:

enter image description here

HTH

0

Turns out Cinnamon desktop has that option still! Nice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.