Martin Frost

Add a custom keyboard layout in KDE using rcm

Published:

For a bunch of years, I've been using a slightly modified version of the standard "US dvorak" keyboard layout on my Linux installations.

A few years ago, I wrote an article on how to configure this layout in Ubuntu using ansible.

I have since then stopped using Ubuntu, and regardless of distro I've moved to using the KDE Plasma desktop environment, and I have discovered an easier way to add a custom layout.

This approach uses the same layout as my previous article. It looks like this:

// This is basically a US Dvorak with some (mostly) Swedish accented characters added
// å -> alt-gr a
// ä -> alt-gr e
// ö -> alt-gr o
// é -> alt-gr u
// ü -> alt-gr y

default partial alphanumeric_keys
xkb_symbols "dvorak" {
    include "us(dvorak)"
    include "level3(caps_switch)"
    include "level3(ralt_switch)"

    name[Group1] = "Swedish (Frost Dvorak)";

    //             Unmodified       Shift           AltGr            Shift+AltGr

    // // symbols row, left side
    key <AD05> { [ y,               Y,              udiaeresis,      Udiaeresis ] };

    // home row, left side
    key <AC01> { [ a,               A,              aring,           Aring      ] };
    key <AC02> { [ o,               O,              odiaeresis,      Odiaeresis ] };
    key <AC03> { [ e,               E,              adiaeresis,      Adiaeresis ] };
    key <AC04> { [ u,               U,              eacute,          Eacute     ] };
};

RCM

rcm is a small piece of cli software for managing rc files. I use it for my dotfiles and to some extent for my machine setup. More on that another time, though.

I found out that there is now support for having a custom XKB layout living locally under your home directory, in $HOME/.config/xkb/symbols. So if I just put the above layout in $HOME/.config/xkb/symbols/frost and run mkrc $HOME/.config/xkb/symbols/frost, that means I should be able to select that keyboard layout to use. The mkrc command means it moves that file over to my dotfiles repo, and places a symlink to the file on the supplied path instead, so that I can commit the layout file in my dotfiles repo, and then sync that to my other machines.

kxkbrc

The second piece of the puzzle is the config file for setting the xkb layout in KDE, and that is a file called $HOME/.config/kxkbrc.

Mine has the following in it:

[$Version]
update_info=kxkb.upd:remove-empty-lists,kxkb.upd:add-back-resetoptions,kxkb_variants.upd:split-variants

[Layout]
DisplayNames=,
LayoutList=frost,se
Use=true
VariantList=dvorak,

So, of course I also ran mkrc $HOME/.config/kxkbrc, committed that change to my dotfiles repo, and then the next time I need to set up a newly installed machine, I can just clone my dotfiles repo, run rcup, and then my keyboard layout will be there and work as I expect it to.