Setting Meta With the XKB Extension

To use the XKB extension to fiddle with keys you can probably use some tool that I don’t have nor remember the name of, but if you don’t have it, here’s a description of using xkbcomp.

First, get a source file of the keyboard map with

    xkbcomp $DISPLAY

which creates a file that probably starts with server_ and ends with .xkb, the actual file name depends on the $DISPLAY variable.

Then edit that file – with emacs of course – and change whatever you like ;-)

I do not have win keys, but something that looks like <> which actually send the same codes as the win keys, apparently. So assuming you have either keys, you would look for lines containing something like:

    <LWIN> = 115;
    <RWIN> = 116;

Now, in case you have neither win, nor <> (diamond) keys (which someone told me were real meta keys), you can use xev to find out the actual codes your keys send and use those numbers, you don’t have to change the names of LWIN nor RWIN, just don’t create name clashes.

Now look for line that defines what these keys do. They look something like:

    key <LWIN> {         [         Meta_L ] };
    key <RWIN> {         [         Meta_R ] };

and make them look like above.

After saving the file, compile it with the following command:

    xkbcomp server_<whatever-here>.xkb

This creates a file called server_<the-same-old-here>.xkm which you can apply to the server with:

    xkbcomp server_<the-same-old-here>.xkm $DISPLAY

Now restart emacs.

Wow, now you have (probably) all of control, alt, shift and meta, and are therefore free to use A- prefix for you own keys!

Enjoy ;-)

Using xkb options to choose the meaning of the Window key

Most modern xorg installations have a bundle of options to set keyboard behaviour; with the xkb tool it’s easy to configure everything on a single command line. Currently I’m using this on a standard PC keyboard:

 setxkbmap -model pc105 -layout us,us -variant dvorak-alt-intl,basic -option "" -option lv3:ralt_switch -option ctrl:nocaps -option grp:shifts_toggle -option grp_led:caps -option altwin:left_meta_win

This rather long line chooses two variants, i.e. ‘normal’ (qwerty) and dvorak, allows me to switch by pressing both shift keys together, use the right alt key to ‘group shift’ (i.e. type accented characters), indicate the alternate variant by turning on the Caps Lock indicator, set the Caps Lock key to function as an extra Ctrl key, and (finally) use the left Windows key as a Meta key. This leaves Alt to the window manager.

You should check out /usr/share/X11/xkb/rules/base to find options you like.

Most desktop environments allow you to configure xkb settings in a GUI, which usually overrides whatever you type on the command line. For my environment, which is xfce4, it is unfortunately not possible to enter options--just layout and variant.