2026-03-31

custom keyboard layout under linux X11

only requires a file like /usr/share/X11/xkb/symbols/mylayout. you can look at other files in the directory for examples, particularly for the character identifiers to use. layouts can be applied with "setxkbmap mylayout", manually from a terminal, from .xinitrc or alternatively with a configuration file under /etc/X11/xorg.conf.d.

contents could look like the following, where the "key " prefixes correspond to keys in rows on the keyboard:

default
partial alphanumeric_keys modifier_keys
xkb_symbols "mylayout" {
    name[Group1]= "myshortdescription";
    key  { [ asciitilde, dead_diaeresis, asciitilde ] };
    key  { [ 1, exclam, backtick ] };
    key  { [ 2, at ] };
    key  { [ 3, numbersign ] };
    key  { [ 4, dollar ] };
    key  { [ 5, percent ] };
    key  { [ 6, asciicircum ] };
    key  { [ 7, ampersand ] };
    key  { [ 8, asterisk ] };
    key  { [ 9, less ] };
    key  { [ 0, greater ] };
    key  { [ braceleft, bracketleft ] };
    key  { [ braceright, bracketright ] };
    key  { [ q, Q ] };
    key  { [ g, G ] };
    key  { [ m, M ] };
    key  { [ l, L ] };
    key  { [ w, W ] };
    key  { [ b, B ] };
    key  { [ y, Y ] };
    key  { [ u, U ] };
    key  { [ v, V ] };
    key  { [ colon, semicolon ] };
    key  { [ question, apostrophe ] };
    key  { [ equal, plus ] };
    key  { [ bar, parenright ] };
    key  { [ d, D ] };
    key  { [ s, S ] };
    key  { [ t, T ] };
    key  { [ n, N ] };
    key  { [ r, R ] };
    key  { [ i, I ] };
    key  { [ a, A ] };
    key  { [ e, E ] };
    key  { [ o, O ] };
    key  { [ h, H ] };
    key  { [ slash, backslash ] };
    key  { [ z, Z ] };
    key  { [ x, X ] };
    key  { [ c, C ] };
    key  { [ f, F ] };
    key  { [ j, J ] };
    key  { [ k, K ] };
    key  { [ p, P ] };
    key  { [ comma, quotedbl ] };
    key  { [ period, parenleft ] };
    key  { [ minus, underscore ] };
};

custom keyboard layouts and fcitx

the language input method system fcitx reloads detected keyboard layouts when switching input methods. it does not detect customized x-server keyboard layouts unless they are registered in additional files. replace "mylayout" with the name of the keyboard layout you want to add.

add to /usr/share/X11/xkb/rules/evdev.xml inside


  
    
      mylayout
      myshortdescription
      mydescription
      
        eng
      
    
  

add to /usr/share/X11/xkb/rules/evdev.lst after "! layout"

! layout
  mylayout          myshortdescription

fcitx may need to be restarted for changes to take effect