KKBSwitch'> ]> The &kkbswitch; Handbook Leonid Zeitlin
lz@europe.com
2002, 2003, 2004, 2005 Leonid Zeitlin &FDLNotice; 23/01/2005 &kkbswitchVersion; &kkbswitch; is a keyboard layout indicator for &kde;. KDE KKBSwitch keyboard layout indicator XKeyboard
Introduction &kkbswitch; is a keyboard layout indicator for &kde; 2 or 3. It is useful when you have configured the XKeyboard extension of your X Server to have more than one keyboard group (layout), for example US/ASCII and Russian. &kkbswitch; displays an icon in the system tray that indicates which layout is currently active. Note that &kkbswitch; does not help you configure XKeyboard, it merely serves as the indicator of the current layout. You still have to configure XKeyboard by editing the XF86Config file. Please report any problems or feature requests to the author, Leonid Zeitlin, at the address lz@europe.com. 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: One or more entries corresponding to the configured keyboard layouts. Note that XKeyboard can have up to 4 layouts configured. The currently active layout will be checked. Selecting a menu entry corresponding to a layout will make that layout active. "Configure Keyboard Switch...". This entry lets you configure &kkbswitch; "Help". Brings up the online help (probably the document you are reading now). "About Keyboard Switch". This entry displays a standard "About" dialog box. "Quit". Quit &kkbswitch;. 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 <guilabel>General</guilabel> 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 flag Language code Flag 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 applicationA technically inclined user familiar with &X-Window; 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.. 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 ). 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 &kcontrolcenter;), and &kkbswitch; was running in your previous session, &kde; will restore &kkbswitch; in the new session regardless of the autostart setting. The <guilabel>Shortcuts</guilabel> 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 &RedHat; 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 . Developer's Guide to &kkbswitch; &kkbswitch; can be manipulated programmatically via DCOP. It exports an interface named KBSwitchIntf. The interface offers the following methods. int getNumKbdGroups This method returns the number of configured keyboard groups (layouts). ASYNC selectNextGroup This method does the same thing as clicking on the &kkbswitch;'s tray icon, i.e. makes the next keyboard layout active. If in "toggle mode", toggles between the two recently used ones, just like clicking on the tray icon does. ASYNC selectGroup int groupno This method makes the layout whose number is groupno active (like selecting a layout from the tray icon popup menu). QStringList getGroupNames This method returns the list of the keyboard layout names, as configured in XKeyboard. Examples The following examples illustrate how one can manipulate &kkbswitch; with the command line tool dcop. Select the next keyboard group (layout): % dcop kkbswitch KBSwitchIntf selectNextGroup Select the group (layout) number 0: % dcop kkbswitch KBSwitchIntf selectGroup 0 Credits and License &kkbswitch; Program copyright 2001-2004 Leonid Zeitlin lz@europe.com Contributors: Mikhail Senin m_senin@mail.ru - implemented configuration for the default layout and per-window layouts Rashid N. Achilov achilov@granch.ru - made a FreeBSD port, suggested "Browse" button in "Pick icon" dialog box. Vadim Kriklivy analitic@vinnitsa.com - suggested "Language code" icon style (a la &Windows;) and shortcuts feature, made Ukrainian translation. Sergey V Turchin zerg@altlinux.org - implemented autostart feature. Stergios Dramis sdramis@egnatia.ee.auth.gr - contributed Greek translation. Michal Šulek reloadshot@atlas.sk - contributed Slovak translation. Shlomi Loubaton shlomister@gmail.com - contributed manpage, Debian package maintainer. Igal aka "Koala" igalfr@netvision.net.il - contributed Hebrew translation, Gentoo ebuild maintainer. Petko Yotov 5ko@free.fr - contributed Bulgarian translation. Michal Bukovský michal@trilogic.cz - contributed Czech translation. Documentation copyright 2001-2005 Leonid Zeitlin lz@europe.com &underFDL; &underGPL; Installation How to obtain &kkbswitch; &kkbswitch; has a home page at SourceForge: http://kkbswitch.sourceforge.net. Check there for the latest news. The latest version is available for download from the project page: http://sourceforge.net/projects/kkbswitch. Requirements &kkbswitch; doesn't require any special environment to compile and run besides the standard &kde; 2 or 3 kdelibs and kdebase. Compilation and Installation In order to compile and install &kkbswitch; on your system, type the following in the base directory of the &kkbswitch; distribution: % ./configure % make % make install Options you may want or need to give to the configure command are: =dir - set the prefix where your &kde; installation is located. Alternatively, you can set $KDEDIR environment variable to the &kde; directory. Under regular circumstances, the configuration script will find the &kde; location automatically; use this option only if you are having problems without it. - install the Russian/Ukrainian layout file (described in ). This option is useful for users of XFree86 prior to version 4.3, who want to use Russian/Ukrainian layout file. Note that with this option it is not possible to install &kkbswitch; without root privileges, because the layout file must go to the system XKB layout directory where ordinary users don't have write access. - do not check for &arts; development headers. &arts; is &kde;'s multimedia framework, which &kkbswitch; does not use. However, since &kkbswitch; uses standard &kde; configuration macros, the configuration script will check for &arts; headers and complain if they are not found. If this happens to you, specify this option to compile &kkbswitch;. Alternatively, install &arts; development headers, you'll need them one day. Since &kkbswitch; uses autoconf and automake you should have not trouble compiling it. &kkbswitch; was tested under several versions of &Linux; and FreeBSD, and a FreeBSD port is available. If you system uses RPM you may want to download &kkbswitch; source RPM package. To build a binary RPM out of source RPM run this command (as root): % rpmbuild kkbswitch-&kkbswitchVersion;-1.src.rpm (You may add option if you need the Russian/Ukrainian layout file, see ). Then, still as root, go to your binary RPM directory (on &RedHat; Intel systems, /usr/src/redhat/RPMS/i386) and install the binary RPM you've just built with this command: % rpm kkbswitch-&kkbswitchVersion;-1.i386.rpm Note that with older versions of RPM you will need to use command rpm instead of rpmbuild The Russian/Ukrainian keyboard layout file For the benefit of Ukrainian users of &kkbswitch; and XFree86 versions before 4.3, a Russian/Ukrainian keyboard layout file is included with the distribution (users of XFree86 4.3 and later, including X.Org server, read the note in the end of this appendix). This file is experimental, so report any problems with it to the author of &kkbswitch;. The file is named ru_ua and by default gets installed to the directory /usr/X11R6/lib/X11/xkb/symbols, where this type of XKeyboard configuation file is supposed to go. The file defines a configuration with 3 keyboard groups (layouts): US/ASCII, Russian and Ukrainian. To use this layout, you can do one of the following. If you feel comfortable editing your XF86Config file and know its structure you can simply edit the file (usually /etc/X11/XF86Config-4 for XFree86 4.x), and in InputDevice section for keyboard set XkbLayout option to "ru_ua". It is recommented to set XkbVariant to "winkeys", since only this variant was tested. If you are using &RedHat; &Linux;, you may create a file named .Xkbmap in your home directory and write the text "ru_ua" (without quotes) in it. The default X session startup script will pick this file and activate the layout named in it. Run the command setxkbmap ru_ua either manually from command prompt our in one of your X session startup script. Users of XFree86 4.3 and later versions, including X.Org server, don't need any additional files if they want a three-language layout. Just specify XkbLayout "us,ru,ua" in your XF86Config (xorg.conf for X.Org server) file. &documentation.index;