Create a new keyboard layout

In the system settings, it is possible to change the keyboard layout, but as far as I can see, it is only possible to select from an existing selection of layouts.

Is there any way to create a new layout, preferably on the basis of an existing layout?

My specific use case is that I have a British English keyboard, and I would like to assign the en- and em-dash to the standard layout (preferably as alt-values of - and _). In the future, I may have further things that I want to tweak.

there are other ways to change intercept and change inputs from one of the standard keyboard layouts.

input remapper

are two GUI friendly ways.

Thank you for those suggestions. But that would overrule whatever keyboard layout one chooses, right? I also have an external keyboard with a different layout. So I would want to switch between layouts depending on which keyboard I am using.

Aren’t keyboard layouts stored somewhere in plain text, where I could modify them / add my own?

Keyboard layouts come from XKB data provided by the xkeyboard-config package, the British English layouts are at /usr/share/X11/xkb/symbols/gb.

An alternative to messing with layouts would be to enable a Compose key (aka Multi_key) on the advanced tab of keyboard configuration and then use:

<Multi_key> <minus> <minus> <period> for en-dash

<Multi_key> <minus> <minus> <minus> for em-dash

which come from /usr/share/X11/locale/en_US.UTF-8/Compose

1 Like

Thank you! I’ve gone down the compose key-route for now, since it requires only a minimal intervention.

Thank you also for pointing out where keyboard layouts are stored. If I want further modifications, I will probably add something there. The biggest issue is that any changes may get overwritten by an update. I think the following feature request describes it well (even though it’s not really Ubuntu-specific):

Note that for things using xkbcommon to access XKB data, you can override that data on .config/xkb for user configuration or /etc/xkb for system configuration, see:

Could you elaborate a bit more? Are you saying that xkbcommon allows the system to see keyboard layouts specified in user space?

And could you say something in general terms about which systems do and which don’t use xkbcommon? Its website lists Wayland, does that mean that its automatically used under Wayland, but not under X.Org?

One way to make it work is through careful editing of .config/kxkbrc. Another option is through the KWIN_XKB_DEFAULT_KEYMAP and XKB_DEFAULT_KEYMAP environment variables, as described on 447206 – kwin_wayland ignores $XDG_CONFIG_HOME/xkb

I just tried the kxkbrc method to enable the example “banana” layout in libxkbcommon: User-configuration and it works under kwin_wayland, but not under kwin_x11.

So I guess adding support for these additional XKB paths to the keyboard KCM in system settings would need either first support for them in X11, or ugly wayland conditionals on the KCM.