[vox-tech] Keyboard switching with xkb
Ken Bloom
kbloom at gmail.com
Fri Oct 26 11:36:52 PDT 2007
(trying again because this came out mangled in the archive.)
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
layout.
The layout file .hebrew is just an ordinary xkb symbols file -- no
special group dependent stuff is needed
default
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.
--Ken
--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/
-------------- next part --------------
_______________________________________________
vox-tech mailing list
vox-tech at lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech
More information about the vox-tech
mailing list