Switching keyboard layouts in Lubuntu 11.10

As arno says, try:

setxkbmap -option grp:alt_shift_toggle "us,il"

(for hebrew).

To make this permanent:

 echo '@setxkbmap -option grp:alt_shift_toggle "us,il"' | sudo tee -a /etc/xdg/lxsession/Lubuntu/autostart

You can use Lxkeymap under preferences. There is a Keyboard Layout Switcher under Panel Preferences / Panel Applets.


This is a general solution including solving other possible problems when setting keyboard layouts and changing them with shortcuts. I have tested this in Lubuntu oneiric, precise, and quantal.

- First, using the GUI Keyboard Layout Handler

Right click on the Keyboard Layout Handler button from the LXPanel

enter image description here

Then "Add"

enter image description here

There are different types of layouts for the same language

enter image description here

Also set the shortcut (Change Layout Option).

  • In case the GUI might not work or is not present in 11.10 etc

    or settings are nor respected after logout, or they are not translated in practice etc. (it happened often to me in 11.10, not anymore after 12.04).

Check current xkb parameters with:

setxkbmap -query

I'll give an example with three languages, US Englush, French and Romanian standard. For German it is "de" I think.

So, to set us,fr,ro layout with variants default (us), (fr) and standard (ro) that can be changed with ALT-SHIFT keys:

setxkbmap -layout "us,fr,ro" -variant ",,std" -option "grp:alt_shift_toggle"

To test if all are OK and make all changes permanent (if gedit is the preferred text editor):

gksudo gedit /etc/default/keyboard

See that parameters are according:

XKBMODEL="pc105"
XKBLAYOUT="us,fr,ro"
XKBVARIANT=",,std"
XKBOPTIONS="grp:alt_shift_toggle"

See that the settings in Keyboard Layout Handler are exactly the same regarding also order, subtype and shortcut.

- Other possible issues.

In 12.10 I had a more bizarre problem. In spite of doing the above two steps only the main language was accessible. This was solved by removing and reinstalling all secondary languages (all except the main one) and adding the secondary languages as in the previous steps.


The permanent solution provided by user1112507 worked for me in Lubuntu 12.04, but not in 12.10 where setxkbmap apparently needs to delay before executing.

His solution, modifying /etc/xdg/lxsession/Lubuntu/autostart, is for all users. Here is a workaround for the single-user case:

  1. Install the desired languages.

    $ gnome-language-selector
    
  2. Create a shell script to execute setxkbmap after a delay and save it in a convenient place. Running it in the background may speed up the login process. Increase sleep time if needed. Replace "us, il" with your desired language codes.

    $ echo '(sleep 2; setxkbmap -option grp:alt_shift_toggle -layout "us,il") &' > ~/setxkbmap.sh
    
  3. Make the script executable and verify that it works by toggling the key combination Alt-Shift to switch language.

    $ chmod +x ~/setxkbmap.sh
    $ ~/setxkbmap.sh
    
  4. Create a .desktop file which executes the shell script just created. Replace "username" with your username.

    $ echo '[Desktop Entry]
    Type=Application
    Name=Keyboard Language Switcher
    Exec=/home/username/setxkbmap.sh
    Icon=/usr/share/lxkeymap/media/icon.png
    ' > ~/Desktop/setxkbmap.desktop
    
  5. Logout and login again, then test by clicking on the new icon on your desktop, then toggling Alt-Shift.

  6. Move the .desktop file to ~/.config/autostart

    $ mv ~/Desktop/setxkbmap.desktop ~/.config/autostart
    
  7. Logout and login again, then test by toggling Alt-Shift.