keyboard-layout
pools all the needed files to set up my custom
XKB
keyboard layout (takbl
) on Linux Ubuntu.
You can install takbl
following the step describe in
Installation section.
In Learning a new keyboard layout section I answer to the questions:
In My understanding of XKB section,
you can read about how does XKB
work and how can you make your own XKB
keyboard layout.
- I want a keyboard layout that fits my needs (I mostly use my keyboard to write CODE).
- After typing all day long, my hands and fingers use to hurt me.
This is principaly due to the use of the PINKY on the keys
Backspace
,Control
,Enter
,Shift
andTab
. TypeMatrix does a great job in this area puttingBackspace
andEnter
in the center of the keyboard. But It's not enougth when you're writing code because you want theTab
key in the center (is there anyone who writes code without code completion or snippet expansion almost always bound to theTab
key?). Moreover,TypeMatrix
put the symbols[
]
(
)
{
}
in the edges, which is bad when you write code. - When you write code, you use the symbols
[
]
(
)
{
}
constantly, SO they CAN'T be at the edges of your keyboard layout. This is why I discarded the keyboard layouts QWERTY and DVORAK (also due to the PINKY problem of the keysBackspace
,Control
, ... described above). - As I'm French, I had a look on
BÉPO. Two things are
good in the layout: 1) the symbols
[
]
(
)
{
}
are not at the edges (accessible with key-chords usingAlt Gr
key), and 2) the punctuation symbols.
:
,
;
are at the center of the keyboard. However I discarded it because of the PINKY problem of the keysBackspace
,Control
... described above. - In addition, I want to access to the symbols
_
'
"
/
|
\
%
@
#
=
$
~
<
>
+
*
-
^
!
?
without moving my hands.
In that section I'm talking to programmers but I'm sure that those thoughts can be applied to anyone that works in an area that involves a heavy use of the keyboard.
I imagine that there is a lot of literature on how to learn a new keyboard layout. For sure, there exists a lot more literature about how to learn anything. At the end of the day, I think the only truth about learning is: the more you practice the better you'll get.
So if you want to learn a new keyboard layout, don't hesitate too much, just spend time on it with passion and that will pay off.
To be clearer, these are the rules I follow that you can apply, if you want, whatever keyboard layout you choose to adopt:
- be clear on the reasons you choose this layout and not another,
- pick any application that helps you practice your typing (accuracy, speed and fluidity). I use klavaro. It is simple and customizable. As they said in the home page: Klavaro is libre software that intends to be keyboard and language independent...,
- practice everyday as much as you can,
- be patient this will pay off for the rest of your programmer life.
Assuming that you're an average programmer. Usually, you're going to write code:
- 5 days a week,
- 5 hours a day (the rest is for readings and meetings),
- at least during 10 years (if it's not 40 or more).
You're going to use your keyboard 13,000 HOURS (5 x 5 x 52 x 10) during those 10 years of programming. This corresponds to 541 DAYS (13000 / 24).
THINK ABOUT THAT!
When I did the math a couple of years ago, I thought it was worth spending a few days to think about my keyboard layout and worth spending a couple of weeks to learn it. This is a ridiculous amount of time compare to 541 DAYS.
This configuration works on Ubuntu 22.04 LTS.
Note that we have to use Xorg
instead of the default Wayland
.
To install takbl
keyboard layout, run the following commands:
git clone https://github.com/tonyaldon/keyboard-layout
cd keyboard-layout
make install
Then you have to RESTART your computer so that Ubuntu 22.04 starts
using Xorg
(instead of Wayland
) which is necessary for this X11
keyboard setup.
If you want to remove takbl
keyboard layout installation, run the
command:
make remove
Note that when you run make install
, 4 things happen:
-
A backup of the files
/usr/share/X11/xkb/rules/evdev.xml
,/etc/default/keyboard
and/etc/gdm3/custom.conf
is made in the directory.backup
, -
Wayland
is disable in order to force the login screen to useXorg
by making the following symbolic link:/etc/gdm3/custom.conf => ./etc/gdm3/custom.conf
-
The keyboard layout
takbl
is installed by making the following hardlinks:/usr/share/X11/xkb/rules/evdev.xml => ./usr/share/X11/xkb/rules/evdev.xml /usr/share/X11/xkb/symbols/takbl => ./usr/share/X11/xkb/symbols/takbl
-
The keyboard layout
takbl
becomes the default keyboard layout by making the following hardlink:/etc/default/keyboard => ./etc/default/keyboard
If you want to know more about XKB
, you can read the section My
understanding of XKB
takbl
is designed to be used to write code. However
sometimes, I write some Spanish or French. For that reason, I
added two variants takbl es
and takbl fr
to the basic layout
takbl.
- For the Spanish layout, I added the following characters:
á
é
í
ó
ú
ü
ñ
¿
¡
. - For the French layout, I added the following characters:
à
â
æ
é
è
ê
ë
î
ï
ô
œ
ù
û
ü
ÿ
ç
.
Not that when you load a variant you lose some characters very useful when you're programming but not when you are writing standard text. It doesn't bother me because:
- I'm neither a French nor a Spanish novel writer, I write code and code documentation and when I write some Spanish or French I'm not writing code.
- I almost always write inside
emacs where I have a key
binding with which I can switch quickly between the keyboard
layout
takbl
and its variantstakbl es
andtakbl fr
. - By the way, there is always a TRADEOFF.
To switch between takbl
and its variants, you can run the following
commands:
setxkbmap -layout takbl # basic
setxkbmap -layout takbl -variant es # Spanish
setxkbmap -layout takbl -variant fr # French
When you load a keyboard layout, for instance by running the command
setxkbmap -rules evdev -layout us
(for the standard US QUERTY),
XKB
load the rules in /usr/share/X11/xkb/rules/evdev.xml
file and
looks for the layout us
. If the layout us
is found in
/usr/share/X11/xkb/rules/evdev.xml
, XKB
seeks the file
/usr/share/X11/xkb/symbols/us
. If this file exist, the keyboard
layout defined in that file is loaded (in our case the US QUERTY
layout is loaded).
The directory /usr/share/X11/xkb/
looks like this:
.
├── compat
│ ├── ...
├── geometry
│ ├── ...
├── keycodes
│ ├── ...
├── rules
│ ├── ...
│ ├── base.xml
│ ├── evdev.xml
│ ├── ...
├── symbols
│ ├── ...
│ ├── fr
│ ├── ...
│ ├── us
│ ├── ...
└── types
├── ...
To see all the available keyboard layouts, list the files in the directory
/usr/share/X11/xkb/symbols/
by running the command:
ls /usr/share/X11/xkb/symbols/
I don't know, but in the documention we can read that On Linux
systems, the evdev
rules are most commonly used, on other systems
the base
rules are used.
So like me if you're running Linux Ubuntu, the rules XKB
loads are
in the file /usr/share/X11/xkb/rules/evdev.xml
. And if you are
using setxkbmap
to load keyboard layouts, running one of those
following command lines leads to the same result (loading the US
QUERTY keyboard layout):
setxkbmap -layout us
setxkbmap -rules evdev -layout us
Setting your keyboard layout with setxkbmap
doesn't last across
sessions and as a consequency is not set when you log into your
session.
Your system load the keyboard layout set in /etc/default/keyboard
file. For instance, if you use the US QUERTY keyboard layout,
/etc/default/keyboard
file should look like this:
# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS=""
BACKSPACE="guess"
Now if you want to set the Spanish QUERTY keyboard layout (that is defined in the file
/usr/share/X11/xkb/symbols/es
) as your default keyboard layout, you
just have to modify the line XKBLAYOUT="us"
by XKBLAYOUT="es"
in
the file /etc/default/keyboard
, which lead to the file:
# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="es"
XKBVARIANT=""
XKBOPTIONS=""
BACKSPACE="guess"
If you want to have some informations on your current XKB
settings ,
run the commands:
setxkbmap -query
setxkbmap -query -verbose 10
In this section, I'll describe how I made takbl
keyboard layout.
-
In the file
/usr/share/X11/xkb/rules/evdev.xml
I added the following snippet as a child of the node<layoutList>
:<layout> <configItem> <name>takbl</name> <shortDescription>TA</shortDescription> <description>Tony Aldon (kbl basic form)</description> <languageList> <iso639Id>fra</iso639Id> </languageList> </configItem> <variantList> <variant> <configItem> <name>es</name> <description>Tony Aldon (kbl Spanish)</description> </configItem> </variant> <variant> <configItem> <name>fr</name> <description>Tony Aldon (kbl French)</description> </configItem> </variant> </variantList> </layout>
This declares a new default keyboard layout named
takbl
(<name>takbl</name>
) and two variantses
(<name>es</name>
) andfr
(<name>fr</name>
). -
Now when
xkb
loadstakbl
, it looks for the file/usr/share/X11/xkb/symbols/takbl
where the default layouttakbl
and its variantses
andfr
are defined by describing the mappings betweenkeycode names
andkeysymbols
:default partial alphanumeric_keys xkb_symbols "basic" { // map keycode names with keysymbols // this is what defined your keyboard layout // Second row key <AD01> { [ w, W ] }; // w W key <AD02> { [ b, B, parenleft ] }; // b B ( key <AD03> { [ n, N, parenright ] }; // n N ) // ... } partial alphanumeric_keys xkb_symbols "es" { include "takbl(basic)" // map keycode names with keysymbols // it uses "basic" layout defined aboved overwriting // with the mappings you define here // Second row key <AD01> { [ w, W, oacute, Oacute ] }; // w W ó Ó key <AD02> { [ b, B, udiaeresis, Udiaeresis ] }; // b B ü Ü key <AD03> { [ n, N, eacute, Eacute ] }; // n N é É // ... } partial alphanumeric_keys xkb_symbols "fr" { include "takbl(basic)" // map keycode names with keysymbols // it uses "basic" layout defined aboved overwriting // with the mappings you define here // Second row key <AD01> { [ w, W, ecircumflex, Ecircumflex ] }; // w W ê Ê key <AD02> { [ b, B, egrave, Egrave ] }; // b B è È key <AD03> { [ n, N, eacute, Eacute ] }; // n N é É // ... }
-
To map
keycode names
andkeysymbols
when you define your keyboard layout, you need to know the mapping betweenkeycode names
andkeycodes
and thekeysymbols
XKB
uses. -
You can find the mapping between
keycode names
andkeycodes
in the directory/usr/share/X11/xkb/keycodes
and in our case, specificaly in the file/usr/share/X11/xkb/keycodes/evdev
:default xkb_keycodes "evdev" { minimum = 8; maximum = 255; // ... <TAB> = 23; <AD01> = 24; <AD02> = 25; <AD03> = 26; <AD04> = 27; <AD05> = 28; <AD06> = 29; <AD07> = 30; <AD08> = 31; <AD09> = 32; <AD10> = 33; <AD11> = 34; <AD12> = 35; <BKSL> = 51; alias <AC12> = <BKSL>; <RTRN> = 36; // ... }
<TAB>
is thekeycode name
of thekeycode 23
. -
You can find the list of all the
keysymbols
in the file/usr/include/X11/keysymdef.h
:/* ... */ #define XK_5 0x0035 /* U+0035 DIGIT FIVE */ #define XK_6 0x0036 /* U+0036 DIGIT SIX */ #define XK_7 0x0037 /* U+0037 DIGIT SEVEN */ #define XK_8 0x0038 /* U+0038 DIGIT EIGHT */ #define XK_9 0x0039 /* U+0039 DIGIT NINE */ #define XK_colon 0x003a /* U+003A COLON */ #define XK_semicolon 0x003b /* U+003B SEMICOLON */ #define XK_less 0x003c /* U+003C LESS-THAN SIGN */ #define XK_equal 0x003d /* U+003D EQUALS SIGN */ #define XK_greater 0x003e /* U+003E GREATER-THAN SIGN */ #define XK_question 0x003f /* U+003F QUESTION MARK */ #define XK_at 0x0040 /* U+0040 COMMERCIAL AT */ #define XK_A 0x0041 /* U+0041 LATIN CAPITAL LETTER A */ #define XK_B 0x0042 /* U+0042 LATIN CAPITAL LETTER B */ #define XK_C 0x0043 /* U+0043 LATIN CAPITAL LETTER C */ #define XK_D 0x0044 /* U+0044 LATIN CAPITAL LETTER D */ #define XK_E 0x0045 /* U+0045 LATIN CAPITAL LETTER E */ /* ... */
-
Normally, with the 5 items above, you should be able to start making your own keyboard layout.
- To understand the basics of
XKB
configuration, read XKB Config from x.org. - Find more information about
keycodes
,keysymbols
andXKB
in this basics part of the article An Unreliable Guide to XKB Configuration description from Doug Palmer. - If you want to modify or to make your own keyboard layout, have a look on X keyboard extension (wiki) part of the ArchWiki.
- If you want a step by step explanation of
XKB
, you can read A simple humble but comprehensive guide to XKB from Damiano Venturin.
Do you have any question or suggestion? Please, feel free to:
- leave me a message on twitter @tonyaldon
- or to email me at [email protected].
Speaking with your computer always starts by typing characters. Speak clearly. Have a better life.