diff --git a/nixos/doc/manual/configuration/x-windows.xml b/nixos/doc/manual/configuration/x-windows.xml index 798d1fbdfd85..6928a977a9ea 100644 --- a/nixos/doc/manual/configuration/x-windows.xml +++ b/nixos/doc/manual/configuration/x-windows.xml @@ -157,4 +157,134 @@ versions. + + Custom XKB layouts + + It is possible to install custom + + XKB + + keyboard layouts using the option + . + As a first example, we are going to create a layout based on the basic US + layout, with an additional layer to type some greek symbols by pressing the + right-alt key. + + + To do this we are going to create a us-greek file + with a xkb_symbols section. + + +xkb_symbols "us-greek" +{ + include "us(basic)" // includes the base US keys + include "level3(ralt_switch)" // configures right alt as a third level switch + + key <LatA> { [ a, A, Greek_alpha ] }; + key <LatB> { [ b, B, Greek_beta ] }; + key <LatG> { [ g, G, Greek_gamma ] }; + key <LatD> { [ d, D, Greek_delta ] }; + key <LatZ> { [ z, Z, Greek_zeta ] }; +}; + + + To install the layout, the filepath, a description and the list of + languages must be given: + + +.us-greek = { + description = "US layout with alt-gr greek"; + languages = [ "eng" ]; + symbolsFile = /path/to/us-greek; +} + + + + The name should match the one given to the + xkb_symbols block. + + + + The layout should now be installed and ready to use: try it by + running setxkbmap us-greek and type + <alt>+a. To change the default the usual + + option can still be used. + + + A layout can have several other components besides + xkb_symbols, for example we will define new + keycodes for some multimedia key and bind these to some symbol. + + + Use the xev utility from + pkgs.xorg.xev to find the codes of the keys of + interest, then create a media-key file to hold + the keycodes definitions + + +xkb_keycodes "media" +{ + <volUp> = 123; + <volDown> = 456; +} + + + Now use the newly define keycodes in media-sym: + + +xkb_symbols "media" +{ + key.type = "ONE_LEVEL"; + key <volUp> { [ XF86AudioLowerVolume ] }; + key <volDown> { [ XF86AudioRaiseVolume ] }; +} + + + As before, to install the layout do + + +.media = { + description = "Multimedia keys remapping"; + languages = [ "eng" ]; + symbolsFile = /path/to/media-key; + keycodesFile = /path/to/media-sym; +}; + + + + The function pkgs.writeText <filename> <content> + can be useful if you prefer to keep the layout definitions + inside the NixOS configuration. + + + + Unfortunately, the Xorg server does not (currently) support setting a + keymap directly but relies instead on XKB rules to select the matching + components (keycodes, types, ...) of a layout. This means that components + other than symbols won't be loaded by default. As a workaround, you + can set the keymap using setxkbmap at the start of the + session with: + + + = "setxkbmap -keycodes media"; + + + To learn how to write layouts take a look at the XKB + + documentation + . More example layouts can also be found + + here + . + +