(xkb) how to map a key to multiple characters?

Simos Xenitellis simos.lists at googlemail.com
Sun Jan 11 10:52:44 PST 2009


On Sat, Jan 10, 2009 at 10:00 PM, Dominique Pelle
<dominique.pelle at gmail.com> wrote:
> Hi
>
> I'm trying to create a new keyboard layout with xbd for X11 on
> Linux for the C'HWERTY Breton keyboard.
>
> This keyboard is a bit unusual because it has a C'H key and
> pressing this key should result in 3 characters being emitted: C,
> apostrophe and H.  It also has a CH key which should result
> in 2 characters being emitted: C and H.
>
> You can see a photo of this keyboard with the "C'H" and "CH" there:
>
>  http://upload.wikimedia.org/wikipedia/commons/9/9e/Bretona-klavaro.jpg
>
> Notice the C'H key for example near the top left, below the 1 and 2 keys.
>
> C'H and CH are considered as single letters in Breton but Unicode has
> no such code for the C'H trigraph or CH digraph (unlike IJ in Dutch
> for example which is a single character in Unicode).
>
> I'm new to creating keyboard layout with X.  I'm mostly done.
> I have created a file in /usr/share/X11/xkb/symbols/  (Ubuntu-8.10)
> and associated associate keys to characters with a bunch of
> lines like these....
>
>    ...snip...
>    key <AD07> { [               u,              U
>            ] };
>    key <AD08> { [               i,              I
>            ] };
>    key <AD09> { [               o,              O,             oe,
>         OE ] };
>    key <AD10> { [               p,              P
>            ] };
>    ...snip...
>
> It mostly works. However, there is one problem which I have not been
> able to solve yet:
>
> --> How to associate multiple characters to a key? (for the C'H and CH keys)
>
> Hopefully that's possible.  The keyboard works well on Windows, but
> I'd like to add support and use it with Linux.

X.Org already has a few examples of compose sequences that produce
more than one Unicode character. These are for Arabic and Khmer
(search for 'digraph'),
http://gitweb.freedesktop.org/?p=xorg/lib/libX11.git;a=blob_plain;f=nls/en_US.UTF-8/Compose.pre

In your case, you would create a compose sequence that looks like

<something1> : "ch"
<something2> : "CH"

The issue is, which character you are going to press on the keyboard
layout that will be "intercepted" and replaced with 'ch'.
These compose sequences in X.Org (and GTK+) form a global table, so if
you use 'c' in the place of 'somethingX', then it will not be possible
for someone else to type 'c' by itself. It will mess up all other
layouts.

Let's see how to implement and test manually.

1. Create a file ~/.XCompose, with contents
<c>	: "ch"
<C>	: "CH"

2. If you use GNOME, type in a shell
export GTK_IM_MODULE=xim
If you use KDE, it should work out of the box.
If you have SCIM enabled, it might be more complicated.

3. Run an editor such as gedit, then type 'c'. You get 'ch'.

So, what's best to use instead of sacrificing the 'c' letter?

I think it would be good to create new keysyms, let's say

digraph_ch
digraph_CH

(or, shall these be called  ligature_ch, ligature_CH, etc;)
Then, add the compose sequences

<ligature_ch> : "ch"
<ligature_CH> : "CH"

and finally modify your keyboard layout so that it looks something like

    key <AB03> {        [         ligature_ch,    ligature_CH
     ]       };

It is important to make these first in X.Org so that environments such
as KDE will work,
and then GTK+ can pick it up (especially if a new keysym is required).
AFAIK, KDE uses the default X.Org input method, XIM, so it requires this.

The relevant bug report for support of compose sequences that produce
two or more characters, in GTK+, is at
http://bugzilla.gnome.org/show_bug.cgi?id=537457

Simos



More information about the xorg mailing list