Set On Fire

About Mxzcabel's dreams and nightmares

How to remap a keymap using Wayland

Probably quite everyone knows switching keymaps in Wayland depends purely on compositor settings. Even with a lack in standards, it's relatively easy to set existing map modifiers. Unfortunately, in Wayland you can't use the well know and comfy X11's tool xmodmap to customize map inputs.

By now I found three feasible ways to do the task.

1.The hand labour way: Change symbols inputs manually

Although I consider this method as the most time consuming one, I think is pretty fun, not hard at all and the knowledge you get is relevant for further tunes you may desire to try with multiple maps. It involves creating a new layout based directly on what is already settle.

  1. Make a copy of the default keymap you wish to tweak and preferably place it inside your home directory (https://xkbcommon.org/doc/current/user-configuration.html).

    # keymap_name can be us, de, ru, etc.
    cp /usr/share/X11/xkb/symbols/keymap_name \ 
    $HOME/.config/xkb/symbols/keymap_name-custom
  2. To learn which chars you can define in this file, I recommend taking a look in all available characters within /usr/include/X11/keysymdef.h. Another way is using the libxkbcommon provided tool:

    # You will see in real time what keys you're pressing and how your xkb is naming each key.
    xkbcli interactive-x11
    xkbcli interactive-wayland
    # Both commands behaved the same way in wayland during my tests.
  3. Refer to the Romano Giannetti's blog for a practical example and further details. Yes, I get it... is old, from 2014. This detail however doesn't take the charm away. That source only matured like wine as time passed by and it proved to be extensively useful with Xorg statements.

  4. Explore your custom keymap as you like with your favorite text editor. When your configuration is done, use the file name keymap_name-custom into compositor settings.

Tip: Deep dive at xkb layouts is nice, but your compositor may default to another keymap and your custom map unused in result of some error while editing, due to some code that could not be parsed right. I suggest reading XKB Docs and the libxkbcommon Docs for advanced debug.

2.The fast way: Use a sideroad to remap keys

I have found out two years ago there's multiple projects that can be used in both X11 and Wayland. They have such flexibility thanks to other methods to remap keys through kernel input manipulation or by intercepting xkb events directly, which therefore can implement a lot of features besides the remapping as hybrid modifiers, key overloading, macros and more. The only overall drawback using those tools is the mandatory daemon running full-time in order to the changes taking effect. I suggest you to read carefully and taste a bit of all of them at the list bellow:

— https://github.com/rvaiya/keyd

— https://github.com/xremap/xremap

— https://github.com/philipl/evdevremapkeys

— https://github.com/kmonad/kmonad

3.The good balance, but with costs: Use a open-source firmware for your keyboard

I don't have much experience on this path, I have to admit is something I need to try yet. It represents no more struggles with keymaps. Your customized firmware works everywhere despite the OS and you have full control of it. You can tinker your keyboard as you wish while connecting it everywhere, no matter the system. Definitely the most fulfillment one.

● The QMK firmware have this intention in mind, sadly is only for Atmel AVR and ARM USB families. See how to port your keyboard here.

● Nevertheless, along with the obvious QMK documentation, if you just want to take a quick look, I found one tutorial alternative for setting this firmware. You might want to try QMK's forks as well, as the Vial and the Via alternatives.

Tip: Consider using kmonad as an alternative that can behave like a firmware for your keyboard with no costs whatsoever.

journal, tech, informational, wayland, linux, keymap