š

Chapter 2. Using KKBSwitch

The most basic usage is simply to let it sit in the system tray and show you which keyboard layout is currently active. You can also click the KKBSwicth system tray icon to switch keyboard layouts. When right-clicked, the system tray icon displays a menu with the following entries:

Configuring KKBSwitch

In the KKBSwitch configuration dialog (invoked by selecting "Configure Keyboard Switch..." from the tray icon's context menu) you will be able to configure various aspects of KKBSwitch's behavior. The configuration dialog consits of two pages, General and Shortcuts.

The General page

Setting the icons corresponding to the available keyboard layouts

The appearance of the system tray icons that represent keyboard layouts depends on the icon style. KKBSwitch implements the following three styles:

Country flag

This style displays a country flag corresponding to the currently selected layout. Note that this was the only style in version of KKBSwitch prior to 1.3.

Language code

This style displays the two-letter ISO language code corresponding to the currently selected layout. This style mimics Windows® layout indicator.

Flag and code

This style displays the language code against the background of a country flag. This style mimics KDE's kxkb application.

The following table illustrates the look of KKBSwitch tray icon menu with different icon styles.

Country flagLanguage codeFlag and code

The desired style can be selected in the Layout icon style combo box.

Note that KKBSwitch will try hard to guess the correct flag and language code based on the name of the keyboard layout (the names are configured in XKeyboard). For example, it will display the US flag and/or "EN" language code for US/ASCII layout, German flag and/or "DE" language code for German layout, Russian flag and/or "RU" language code for Russian layout, etc. If it cannot guess an icon, it will display a "default" icon, which simply shows the layout's number. Use the configuration dialog to customize flag icons: select a layout in the "Available keyboard layouts" listbox and click "Change icon..." button. You will be presented with "Pick icon" dialog box. There you will be able to select from the list of country flag pixmaps that are shipped with KDE. If you'd like to use a custom image, click the "Browse" button in the bottom of the dialog box and browse for the image file you'd like to use. Note that the preferred size for layout icons is 21 by 14 pixels. If your image has different dimensions, KKBSwitch will scale it appropriately, but the result might look not very good.

Note that changing the icon is not available for the Language Code style, which does not feature a flag.

If you have specified a custom icon for a layout, you can always go back to the standard icon (the one the KKBSwitch has guessed) by clicking "Use Default Icon" button. This button will be enabled only when the layout selected in the "Available keyboard layouts" listbox has a custom icon.

Specifying default layout

You can mark one of the configured keyboard layouts as the default. The default layout will be activated when KKBSwitch starts up. To mark a layout as default, simply select the layout in the "Available keyboard layouts" listbox and click "Set as default" button. The default layout's name is shown in boldface in the "Available keyboard layouts" listbox.

Specifying layout scope

KKBSwitch supports three modes of operation with regards to the scope of the active keyboard layout. Possible settings are:

All windows

In this mode the active layout applies to all windows on your desktop. In other words, at any given time all windows use the same layout.

Windows of one application

In this mode the active layout applies to windows one application[1]. In other words, each application has its own active layout. When a window gets focused, KKBSwitch automatically shows the active layout of this window's application in the system tray. When you change the active layout, either by pressing XKeyboard's group switch key, or by clicking KKBSwitch's tray icon, or by using its context menu, this change affects only the currently active application. Other applications retain their layouts.

One window

In this mode the active layout applies to the focused window only. In other words, each window has its own active layout. When a window gets focused, KKBSwitch automatically shows this window's active layout in the system tray. When you change the active layout, either by pressing XKeyboard's group switch key, or by clicking KKBSwitch's tray icon, or by using its context menu, this change affects only the currently focused window. Other windows retain their layouts.

Pick the mode that you prefer in the "Layout applies to" combo box. The author's opinion is that "Windows of one application" is the most reasonable choice, but opinions vary.

Note that in "Windows of one application" and "One window" modes, all new windows start up with the default layout. In "All windows" mode new windows start with the active (global) layout.

Using "Toggle Mode"

"Toggle mode" is a convenient feature of KKBSwitch, which is useful if you have more than 2 layouts. When "Toggle mode" is on, pressing the XKeyboard's group switch key or clicking KKBSwitch's tray icon will toggle between the two most recently used layouts. To activate the third or the fourth (if available) layout you'll need to right-click KKBSwitch's tray icon and select the desired layout from the menu or use keyboard shortcuts (see the section called “The Shortcuts page”). For example, I have US/ASCII, Russian and Ukrainian layouts configured. Most of the time I use either US/ASCII or Russian layout and switch back and forth between them without activating the rarely needed Ukrainian layout. But sometimes I need to write something in Ukrainian, so I select this layout from the tray icon's menu.

To turn the "Toggle mode" on and off use the Use "Toggle Mode" checkbox in the configuration dialog.

When "Toggle mode" is on, the two most recently used layouts will be marked with an asterisk in the KKBSwitch tray icon's menu.

Starting KKBSwitch automatically when you log in

Use "Autostart" checkbox to enable KKBSwitch autostart feature. When this checkbox is on, KKBSwitch will start automatically each time you log in to KDE. Note that this is independent of KDE's session restoration feature. If you configure KDE to restore the previous session on login (under KDE Components | Session Manager in KDE Control Center), and KKBSwitch was running in your previous session, KDE will restore KKBSwitch in the new session regardless of the autostart setting.

The Shortcuts page

KKBSwitch allows you to quickly activate particular layouts with keyboard shortcuts. This is configured at the Shortcuts page. The "Use shortcuts to activate keyboard layouts" checkbox allows to turns the shortcut feature on and off. Uncheck the checkbox if you don't want to use shortcuts at all. If the checkbox is checked, the shortcuts are enabled. You can configure what key combinations activate which layouts at the key chooser pane under the checkbox. This is a standard KDE key chooser widget that should be familiar to you from other KDE applications. The default shortcuts are: Ctrl+Alt+1 to activate the first layout, Ctrl+Alt+2 the activate the second one, etc.

How KKBSwitch guesses icons for keyboard layouts

KKBSwitch uses the name of the keyboard layout, as defined by XKeyboard, to guess the icon to represent it. The process is entirely automatic; this section is only for those who want to tweak how this guessing works or just are curious. The algorithm is very simple. The KKBSwitch distribution contains a file named group_names, which resides in KKBSwitch's data directory ($KDEDIR/share/apps/kkbswitch). The file is a standard KDE config file. It contains two sections. The secion named "Mapping" contains mappings from XKeyboard group names to country codes. It contains various key=value pairs, key being the name of the XKeyboard layout and value the two-letter country code of the flag to display. The second section, "Language" contains similar mappings from XKeyboard group names to language codes. Note that if a group name is not found in the "Language" section, it is looked up in "Mapping" section, thus only layouts where country code and language code do not coincide need to be listed in "Language" section (e.g. for US/ASCII group the country code would be "us", but the language code would be "en").

Once the country-code has been determined, KKBSwitch will look for an icon named flag.png in the directory $KDEDIR/share/locale/l10n/country code for icons styles that feature a flag and use the language code for styles that feature the a language code.

As I was told, in Red Hat® 9 systems, the KDE default country flag icons are missing. To work around that, if KKBSwitch cannot find country flag icons in the location specified above, it will look for GNOME's gkb icons in /usr/share/pixmaps/gkb. Unfortunately, gkb icons have size 40x60, while KDE ones are 21x14. Thus KKBSwitch rescales gkb icons on the fly, and the quality of the resulting images leaves a lot to be desired. But still it's better than nothing.

Of course, you can override the flag icon selection algorithm by specifying the icon you want to use, as described in the section called “Setting the icons corresponding to the available keyboard layouts”.



[1] A technically inclined user familiar with X Window System® API would be interested to know that KKBSwitch considers windows that have the same Window Class (from WM_CLASS property) as belonging to the same application.