Computer graphics, linux, and more from the cyberwitch's hut
There is an unfortunate reality that many of us europeans discover when
shopping for a new cool keyboard: the US american ANSI disposition dominates
the market with its measly 104 keys. Meanwhile the 105 keys ISO disposition is
not quite as available. Problem is, the main french keyboard layouts (fr
,
fr-latin*
, fr-oss
) use that 105th key to host the <
and >
chars, which
gets limiting really fast when doing anything technical.
In order to solve this issue (and keep using an azerty layout), I'm going to
create a custom xkb variant, based an fr-oss, which adds <
and >
on
altgr+w
and altgr+x
respectively.
First, it can be helpful to look at /usr/share/X11/xkb/symbols/fr
to get an
idea of the syntax and layout of an xkb symbols file, for example:
[...]
partial alphanumeric_keys
xkb_symbols "oss" {
include "level3(ralt_switch)"
include "nbsp(level4n)"
include "keypad(oss)"
name[Group1]="French (alt.)";
// First row
key <TLDE> { [ twosuperior, threesuperior, onesuperior, dead_cedilla ] }; // ² ³ ¹ ¸
key <AE01> { [ ampersand, 1, dead_caron, dead_ogonek ] }; // & 1 ˇ ˛
[...]
key <AB10> { [ exclam, section, exclamdown, 0x1002212 ] }; // ! § ¡ −
};
[...]
So, let's write our own in ~/.config/xkb/symbols/custom
(we'll get to why we chose that particular name later):
partial alphanumeric_keys
xkb_symbols "fr_oss_ansi" {
// Brings < and > to ANSI keyboards
include "fr(oss)"
name[Group1]="French (alt., ansi)";
key <AB01> { [w, W, less, guillemotleft ] }; // w W < «
key <AB02> { [x, X, greater, guillemotright ] }; // x X > »
};
By declaring the variant partial
, we are able to reuse everything that was defined in the fr-oss
variant.
Also, each element in [w, W, less, guillemotleft ]
correspond to a different modifier group, respectively: none, shift
, altgr
, shift+altgr
.
Until recently, customizing xkb was just a big mess of playing with system files. Luckily, it seems that three years ago, things got a bit better as xkeyboard-config
, the repo for the X Keyboard Extension, accepted a merge request to add a custom
layout to their config. But crucially, they didn't provide a definition for it, in order to allow users to add their very own layout, with as many variants as needed.
So, on a single user system, we can simply link our config to the system xkb path:
sudo ln -s \
~/.config/xkb/symbols/custom \
/usr/share/X11/xkb/symbols/custom
Another advantage of doing things this way is that some wayland compositors, for example sway, support simply reading your xkb configuration from ~/.config/xkb/
.
Now, if you want to test things out, you can just use xkbcomp
to test for syntax errors before loading the new layout with setxkbmap
:
xkbcomp ~/.config/xkb/symbols/custom && \
setxkbmap -layout custom -variant fr_oss_ansi
If successfull, altgr+w
should give you back a nice <
!
From there, if you're reading this, you should all be grown ups able to set a persistent configuration, either in /etc/X11/xorg.conf.d/
or in ~/.config/sway/config
.
Cheers! =)