Xubuntu: Easily Switch Keyboard Layout

Xubuntu (Ubuntu Linux’s XFCE based flavor) does not come with any graphical utility to switch keyboard layouts. There is a little XKB plugin that you can add to your XFCE panel but it only shows the layout in use. It does not provide an interface to add keyboard layouts neither it allows you to set keyboard shortcuts for switching between layouts. It doesn’t mean that you can not use different keyboard layouts in Xubuntu; the functionality is there waiting for someone to build a tool around it. Untill then, we will have to manually set our keyboard layouts and here is how to do this.

Create a file in /usr/bin/

gksudo "mousepad /usr/bin/fixkeyboard"

Add following lines in this file. I am using US and PK layouts in this example, please change it to the keyboard layouts you want to use. Also note that this example sets xkb option to change groups when both alt keys are pressed together.

#!/bin/bash
setxkbmap -option grp:switch,grp:alts_toggle us,pk

Save the file and exit.

Go to Applications > Settings > Autostarted Applications and click the Add button. In the Name feild type fixkeyboard and in the Command feild type /usr/bin/fixkeyboard press OK and then Close.

You are done. Now whenever you log on to your XFCE session you will be able to switch keyboard layouts by pressing both Alt keys together. If you don’t like the both Alt keys combination then you can try other group switch combinations. Replace alts_toggle in fixkeyboard file with one of the following options:

alt_shift_toggle
ctrl_shift_toggle
ctrls_toggle

Country flags for XFCE xkb plugin are located in /usr/share/xfce4/xkb/flags/. If your country’s flag is missing you can add it there, the file should be in png format and 60 x 40 pixels.

Published by Noumaan Yaqoob

I am a full-time WordPress blogger, I write tutorials about using WordPress, WordPress themes and plugins. Need help with your website? Feel free to contact me.

Comments

  1. There is another way to fix it:
    1. Open /etc/X11/xorg.conf or XF86Config.
    2. Find lines Section “InputDevice”
    Identifier “Keyboard0” …
    3. Add into this keyboard section this line:
    Option “XkbOptions” “grp:alt_shift_toggle”
    4. Also you can add additional languages into line: Option “XkbLayout” “us,ru,lt”. just separate them with comma.

    For Example my keyboard section.

    Section “InputDevice”
    # generated from default
    Identifier “Keyboard0”
    Driver “kbd”
    Option “XkbModel” “pc105”
    Option “XkbLayout” “lt,us,ru”
    Option “XkbOptions” “grp:alt_shift_toggle”
    EndSection

    By the way, yuo can use:
    ctrl_shift_toggle,
    ctrls_toggle.

  2. There is another way to fix it:
    1. Open /etc/X11/xorg.conf or XF86Config.
    2. Find lines Section “InputDevice”
    Identifier “Keyboard0” …
    3. Add into this keyboard section this line:
    Option “XkbOptions” “grp:alt_shift_toggle”
    4. Also you can add additional languages into line: Option “XkbLayout” “us,ru,lt”. just separate them with comma.

    For Example my keyboard section.

    Section “InputDevice”
    # generated from default
    Identifier “Keyboard0”
    Driver “kbd”
    Option “XkbModel” “pc105”
    Option “XkbLayout” “lt,us,ru”
    Option “XkbOptions” “grp:alt_shift_toggle”
    EndSection

    By the way, yuo can use:
    ctrl_shift_toggle
    ctrls_toggle

  3. oops, my previous post – found the problem: there is no such thing – “us” variant of “us” layout. Leaving variant blank for us layout resolved everything.

    But it took me couple of hours to figure that out…

  4. Still curious: in xubuntu /etc/X11/xorg.conf seems to recognize either keyboard toggle option or keyboard variant:

    XkbLayout us,ru
    XkbOptions grp:alts_toggle

    works (I can switch layouts)

    XkbLayout us,ru
    XkbVariant us,winkeys

    works (I can see correct variant in keyboard settings window)

    XkbLayout us,ru
    XkbVariant us,winkeys
    XkbOptions grp:alts_toggle

    does not work (cannot switch layouts but can see variant in keybosrd settings).

    All I need is winkey variant or russian keyboard, cannot get it in xubuntu…

    Any suggestions?

  5. And why is editing /etc/X11/xorg.conf not considered an option? You can just easily add the same line there and won’t have to bother with any autostart items…

  6. You forgot to mention that the file has to be set executable. Thanks for the tip. I now need to swap my control and Win keys to have this machine behaving correctly…

Leave a Reply

Your email address will not be published. Required fields are marked *