l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2007 Oct 26 12:20

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] Keyboard switching with xkb
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] Keyboard switching with xkb

Having found my keyboard misbehaving over the past few days, I started
looking again at my xkb settings. I had been using a custom layout
living in my home directory to define a phonetic hebrew keyboard map,
but the old version of the file was dependent on certain aspects of
keyboard layouts that would periodically change underneath me.

The old layout was forced to redefine the US keyboard and overwrite all
of the keys in it to work, in addition to including other information
about the keyboard geometry (which changes between my laptop and
desktop). I'm proud to announce that I've found a more portable way
where one can combine any two (or more) keyboard layouts and switch
between them easily.

$setxkbmap -layout us,il

will set up a keyboard where group 1 (the default keypresses) are
american, and group 2 are hebrew. We still haven't specified a way of
switching between these groups yet, but we very simply can string
together a bunch of layouts with commas, and they'll all be put into
different groups in the order specified.

$setxkbmap -layout us,il,fr

will give you group 1 american, group 2 israeli, group 3 french.

Now we need to determine how to switch between these groups. This is as
simple as adding a -option clause:

$setxkbmap -layout us,il -option grp:toggle

grp:toggle switches to the next group whenever you hit right-alt.the
options available are specified in /usr/share/X11/xkb/rules/base,
including a whole bunch of different ways to switch between groups.
There are lots of other options you can pick, like ctrl:nocaps or
ctrl:swapcaps if that's what floats your boat.

I also found the option grp_led:scroll to be useful. This lights up the
scroll-lock led whenever I switch to hebrew.

Now I've customized my own phonetic hebrew keyboard layout that lives
in my home directory (~/.hebrew), and I wanted to use that rather than
the built-in hebrew layout. For this I needed to set the search path
for layout files, and break up the command into two:

$ setxkbmap -I$HOME -layout us,.hebrew -option \
  grp:toggle,grp_led:scroll -print \
  | xkbcomp -I$HOME - :0

The -print option of setxkbmap prints out something along the lines of
xkb_keymap {
	xkb_keycodes  { include "xfree86+aliases(qwerty)"	};
	xkb_types     { include "complete"	};
	xkb_compat    { include "complete+ledscroll(group_lock)"	};
	xkb_symbols   { include "pc+us+.hebrew:2+group(toggle)"	};
	xkb_geometry  { include "pc(pc105)"	};

and xkbcomp reads that from stdin, compiles it using the search path
and tells the X server to use the compiled definition as the keyboard

The layout file .hebrew is just an ordinary xkb symbols file -- no special group dependent stuff is needed

partial hidden alphanumeric_keys modifier_keys
xkb_symbols "basic" { 
         name[Group1]= "Hebrew";

         key  <AC01> { [ hebrew_aleph,  U05B8            ]  };
         key  <AB05> { [ hebrew_bet,    U05C0            ]  };
         key  <AB03> { [ hebrew_zade,   hebrew_finalzade ]  };
         key  <AC03> { [ hebrew_dalet,  U05B5            ]  };
         key  <AC11> { [ U05F3 , U05F4   ] };
         key  <AE11> { [U05BE,U05BE]       };
         key  <CAPS> { [Shift_Lock] };
         //caps-lock in hebrew mode puts you into a vowel mode

Now you as a user can easily set up your own keyboard layout in a platform independent way.

Work complete: שלום


Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.

Attachment: signature.asc
Description: PGP signature

vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!