My Dygma Raise

My Dygma Raise Keyboard.

Introduction

This is a continuation blog post to my earlier keyboard related blog post Dygma Raise Keyboard Reflections Part 1 in which I explained how I configured my Linux keyboard using xmodmap and Dygma Bazecor.

In this new blog post I explain how I solved my keyboard issue when migrating from Xorg to Wayland.

The Hassle, the Workaround, and a New Problem

A week ago after office hours, I thought I update my Ubuntu 22 Linux packages. There were quite a few various package updates and one firmware update. I updated them all. Without booting the machine before the firmware update. A big mistake. Or not. Anyway. I saw that e.g., NVIDIA graphics card driver got updated from version 525 to 535. I booted my machine, and my Linux first lagged considerably with my three external monitors, and then completely froze. Then I rebooted Linux, the same thing. And again. Ok, I thought that the new nvidia drivers had something to do with, so I downgraded back to 525. Didn’t help. My machine also has integrated Intel graphics card, I tried it, didn’t help. I spent one day figuring out the issue, but nothing helped. Finally, I completely re-installed Ubuntu 22. Didn’t help. I was pretty frustrated. Then I tried Wayland, and everything worked just fine. Perhaps, it was some issue with Xorg and/or nvidia drivers?

Ok, now I knew a perfectly good workaround: just ignore the Xorg(/nvidia) issue and use Intel graphics card with Wayland.

But. There was one major issue migrating to Wayland: all my Linux keyboard configurations use Xorg.

The Solution

I am a programmer and I have heavily modified my Finnish keyboard layout so that it is as smooth as possible to program using the Finnish keyboard layout (read more about the specific modifications regarding the layout in my previous blog post: Dygma Raise Keyboard Reflections Part 1)

I googled what kind of solutions there are to configure a Linux keyboard with Wayland, and I found some good candidates:

The strongest candidates seemed to be keyd and kmonad.

I kind of liked kmonad, but the installation seemed to be a bit tedious with Ubuntu, and the configuration seemed to be more complex than with keyd. So, I chose keyd.

Keyd - the Installation

The installation of keyd was really easy (just a copy-paste from the keyd website):

git clone https://github.com/rvaiya/keyd
cd keyd
make && sudo make install
sudo systemctl enable keyd && sudo systemctl start keyd

NOTE: I later on realized this piece of instruction: Note: master serves as the development branch, things may occasionally break between releases. Releases are tagged, and should be considered stable. I installed from the master branch, you might want to check out the latest release branch first.

Keyd - the Configuration Process

I had this kind of configuration process:

  • Terminal 1: sudo emacs /etc/keyd/default.conf - i.e., use your choice of editor to write the keyd configuration file.
  • Terminal 2: sudo journalctl -eu keyd -f - keep journalctl keyd messages to flow in one terminal so that you see if there are errors during reload (see terminal #3).
  • Terminal 3: sudo keyd reload - reload the configuration after changes.
  • Terminal 4: sudo keyd monitor - use the monitor to check the keys you need to refer in your keyd configuration.

This way it is pretty easy to experiment with various keyboard layout configurations and reload the new version of your keyboard layout (and immediately see all errors and warnings keyd emits).

You also might want to initialize /etc/keyd directory as a git repo - this way you can add it to version control and see your change history to resolve some issues later on.

Keyd - My Configuration

Let’s see my current keyd configuration:

# NOTE: The panic sequence *<backspace>+<escape>+<enter>* will force keyd to terminate.

### NOTE:
# This file needs to be in:
# /etc/keyd/default.conf
# If you are reading the ~/info/default.conf file, it is a backup file.
# NOTE: Remember to add changes in /etc/keyd to git!

### HELP SECTION BEGIN ###

# Web site: https://github.com/rvaiya/keyd
# See also Finnish keyboard layout:
# https://www.vero.fi/en/About-us/contact-us/efil/information-on-mytax/less-commonly-used-latin-characters-on-a-finnish-pc-keyboard/

##### KEYD #################
# When you edit /etc/keyd/default.conf file:
# cd /etc/keyd
# cn # Open VSCode
# In another terminal:
# sudo journalctl -eu keyd -f
# ... this way you immediately see if there is some error,
# when you load new configuration (after saving the file):
# sudo keyd reload
# Finally when you are ready, in the /etc/keyd: add changes to git.

# Find keys with tool:
# sudo keyd monitor

# List keys that you can use with keyd:
# sudo keyd list-keys

# Modifiers:
# C - Control++
# M - Meta/Super++
# A - Alt++h
# S - Shift++
# G - AltGr

### HELP SECTION END ###


### TODO BEGIN ###

# No issues at the moment.

### TODO END ###


###### KEYBOARD IDENTIFICATIONS #####
# NOTE: Later on if you find out that some configuration does not work on Dygma vs Laptop keyboard,
# you can use separate ids sections.
[ids]

*


###### MAIN #####
[main]
# Special characters.
# Using sudo keyd monitor: tilde key in Finnish layout is: ]
# Tilde (~) (diaresis key (diaresis is next to Å))
# Thanks tkna!
] = macro(G-] space)
# Tick (forward tick) (´)
# Tick is next to backspace button.
= = macro(= =)


###### CAPSLOCK AS ALTGR #####
capslock = layer(capslock)

[capslock:G]

# Navigation.
j = left
k = down
l = right
i = up
h = home
# ; is ö key in the Finnish keyboard.
; = end
u = pageup
o = pagedown

# Functionalities.
d = delete
f = backspace
# Not needed.
# You get @ { [ ] } etc, by capslock+2, capslock+7, etc.
#2 = @


###### SHIFT #####
# NOTE: Shift needs to be here after my navigation configurations!
# (or it breaks navigation configuration above.)
[shift]
# Caret (^)
# So, you get caret (^) by clicking shift+diaresis (diaresis is next to Å)
] = macro(S-] space)
# Backtick
# So, you get backtick (`) by clicking shift+tick (next to backspace)
= = macro(S-= space)


# TESTING AREA
# {[]}\ @£$89[]}\|||
# ~~~¯¯¯^^^
# ´
#

As you can see, most of the stuff is just my personal notes to help me later on to continue configurations (nice to have instructions where the configuration file itself is). If you remove all comments, you get:

[ids]
*
[main]
] = macro(G-] space)
= = macro(= =)
capslock = layer(capslock)
[capslock:G]
j = left
k = down
l = right
i = up
h = home
; = end
u = pageup
o = pagedown
d = delete
f = backspace
[shift]
] = macro(S-] space)
= = macro(S-= space)

… just some 20 lines!

Compared to my previous xmodmap configuration this is really concise!

Some TODOs

I listed in the configuration file for myself some TODOs to figure them out later on. I managed to fix all those issues, so there are no issues at the moment. :-)

Except. VSCode Integrated Terminal. I just couldn’t get it to use the keyd configuration. The workaround is to use the Emacs bindings hotkeys in VSCode Integrated Terminal (e.g., ctrl+p for upArrow for bash history, etc.). Luckily, the VSCode editor area works with keyd configuration just fine. I’m pretty sure this is not a keyd issue per se, but possibly some weird XWayland / VSCode issue. If you know a solution to this issue, send me email.

The Help

I already explained in my previous blog post that with the Finnish layout you get { [ ] } and some other special characters needed in programming, by clicking the so called AltGr key and some other key at the same time. But the really weird design decision is that the AltGr key sits next to the spacebar key (right side), and those other keys are usually in the upper row on the right side of the keyboard. Which makes it pretty unergonomic to emit those keys: you have to press the altGr with the thumb of your right hand and then reach with e.g., your right-hand middle finger to the upper row of the keyboard. If you are a Finnish programmer, you definitely want to change the Capslock key (which is totally useless in programming) to work as the AltGr key. I did this in the Xorg using xmodmap (read my previous blog post about that: Dygma Raise Keyboard Reflections Part 1).

But. When I was experimenting with keyd, I had some issues figuring out how to switch CapsLock to AltGr. I checked the keyd website if there was some keyd community to ask for help. And there is: IRC Channel: #keyd on oftc.

I explained there my issue, and a very nice Japanese guy with nickname tkna helped me a lot. I can’t believe how helpful he was. We spent about an hour together, and he practically solved all my hard issues, or found a good workaround for those issues we couldn’t solve. I was really happy about his help and I donated some money to his tkna91 ko-fi account. So, thanks a lot once more, tkna!

At the same time I also donated some money to the keyd author rvaiya, to his rvaiya ko-fi account.

Conclusions

If you are using Linux and you are migrating from Xorg to Wayland, and you want to ditch your old Xorg xmodmap configuration, I truly recommend trying keyd. The keyd tool is really easy to install, and really easy to configure. Actually, you can use keyd also with Xorg, so you don’t need to migrate to Wayland to ditch xmodmap.

But, remember to donate some money to the keyd author rvaiya to help the author to continue working with this great tool. And if you receive help from other keyd users (like tkna91), remember to donate some money to them as well - it is the right thing to do.

The writer is working at a major international IT corporation building cloud infrastructures and implementing applications on top of those infrastructures.

Kari Marttila

Kari Marttila’s Home Page in LinkedIn: https://www.linkedin.com/in/karimarttila/