Getting Xcape functionality in Wayland

The thing I’ve missed most since switching to Wayland is definitely Xcape, but more on that later. The solution is to use the Interception Tools plugin caps2esc and in fact this is a display-server agnostic solution because it’s at a much lower level, so it also works for X11 and even in the virtual consoles! 😮

Luckily Arch Linux actually has this plugin in the official package repos, so installation is easy:

$ pacman -S interception-caps2esc

This also installs interception-tools as a dependency, including udevmon which is a program that associates a job with any current and new devices (e.g. keyboards). In our case the “job” we want is a shell script piping intercepted keyboard output through the caps2esc plugin.

To do this, you copy this snippet, literally as-is from the plugin README file:

- JOB: intercept -g $DEVNODE | caps2esc | uinput -d $DEVNODE
  DEVICE:
    EVENTS:
      EV_KEY: [KEY_CAPSLOCK, KEY_ESC]

Paste that into a new file under udevmon.d, for example /etc/interception/udevmon.d/caps2esc.yaml to associate this plugin with the CapsLock and Esc keys on all devices.

Lastly, start up the udevmon service. Despite the README talking about running commands manually, the Arch Linux package includes a systemd unit file with the recommend defaults pre-configured, you just need to turn it on:

sudo systemctl enable --now udevmon.service

That’s it! Now Esc and CapsLock are swapped and holding down Esc functions as Ctlr, in Wayland, in X and even in the TTY!!!


So… why did I want to do this? Well, the caps2esc project documentation says it best:

transforming the most useless key ever in the most useful one

I spend a lot of my computer-time editing code and text in Vim where the Esc key is really frequently used because it’s how you change to “normal mode”. Lots of other programs also let you use Escape to do things like dismissing windows or stepping out of form fields. In GNOME settings there’s an option to swap the CapsLock and Escape keys and that made it a much smaller reach to get the Esc key with my pinky.

Reading up a bit more on this I stumbled upon Xcape which lets you set up CapsLock so that it’ll send Esc if you press it briefly, but act as Ctrl if you hold it down together with other keys. Amazing. The Control key is another annoying pinky-reach and its position varies between my work and personal computers. It’s used in loads of keyboard shortcuts across all apps, and it’s part of most key combinations in readline shortcuts used in the shell. As a power user, having both this and Escape close at hand on this really big, easy-to-hit CapsLock key in the home row is fantastic! Until I switched to macOS.

The old work laptop got replaced with a newer MacBook that brought exciting new hardware compatibility issues. In this case, the built-in keyboard refused to work at all, and after a few weekends of trying to fix it I gave up and accepted the challenge of using the other OS. I was happy to learn this dual Ctrl-Esc functionality was something Mac users were after too and using Karabiner-Elements I was able to set this up pretty easily, as well as the compose key. I ended up using this for a several years and it worked well. I might write a bit about my personal experiences with macOS compared to Linux at some point but eventually this laptop got old too and the next machine was Linux-compatible.

Meanwhile in Linux-land support for Wayland is stable with GNOME desktop and so I switched from X11 to Wayland to get better scaling between the laptop’s HiDPI screen and the HD external monitor. The issue of being able to share my desktop got fixed upstream but the last thing I was missing from X11 was some alternative to Xcape. The X in Xcape alludes to X11, and if an X server isn’t running Xcape can’t start and anyway there wouldn’t be any X input events to handle without X. Pretty annoying. I tolerated this for about a year because the solutions I found looked a bit less out-of-the box than Xcape and I didn’t want to spend so much time tweaking a computer. Xcape issue #67 wayland support lists some alternatives, ranging between pretty hacky to “just use X”.

It was in this list that I came across caps2esc, bookmarked it for later, and later is today. I’ll be honest, I struggled a bit to make heads or tails of the Interception Tools documentation. On one hand it seems the way to write custom “plugin” functionality was written in C, and the code looked short and readable enough, but on the other hand it’s talking about configuring things with YAML files. The YAML config didn’t seem to be input to the plugin itself though. After some back-and-forth between the main docs and the plugin docs it became obvious: The plugin itself is written in C. If you have it installed, you can use the interception tools intercept and udevmon to send keyboard events through the caps2esc plugin. Using udevmon you can configure to which devices to apply this rule (called a job) and the way to do that is to write some udevmon config in YAML. The puzzle pieces all fit together and the result is the condensed set of instructions at the top of this post.

Packaging Wakatime CLI for ArchLinux

I’ve decided to give Wakatime a second try. It’s a tool that tracks the time you spend programming on different projects by integrating into your IDE. This works well for typical development work where you open your IDE in the morning and type code in it, do commits with it, and everything else related to the project and Wakatime will track that.

I don’t work like that though, so I had two issues with it last time, both resulting in a lower reported time spent working:

  • I spent most of the day working on different remote servers and it would be a hassle to set it up in the text editor on each of them and it would undoubtedly cause slowdown on the older servers
  • I use the command line tools as my IDE, so the time recorded opening the text editor to make some changes is not representative of the time spent working

This time it’s different because nowadays I virtualise most of the services I work with, using Docker on my local machine, and I’m hoping that using the Wakatime Z Shell integration will give a better record of time spent working on a project. Continue reading

3D Printed Hungarian Cross

The Hungarian coat of arms features an iconic cross with two horizontal beams. In Hungarian it’s called “Kettős Kereszt” which translates to “Double Cross”, usually called the Patriarchal cross in English. This cross is present on other emblems around the area of Central and Eastern Europe too and has been featured on the Hungarian coat of arms at least since the reign of King Saint Stephen of Hungary.

3D model of the patriarchal cross as shown on the Hungarian coat of arms

3D model of the patriarchal cross as shown on the Hungarian coat of arms

Seeing as it’s a Hungarian national holiday today, in memory of the heroes and martyrs of the Hungarian revolution of 1956, everyone has their Hungarian flags out. I decided to do something Hungarian too, while trying out some tools for preparing models for 3D printing. So far I’ve been using Blender, because I have some experience with it, but it’s for creating 3D scenes and although you can use it to design 3D models for printing, it’s not CAD software. This time I tried Autodesk’s web-based program Tinkercad, which although lacking many of the features you’d get in a full-blown CAD program, is plenty enough for me to design simple things like this. Not being a mechanical engineer, I probably wouldn’t even know what features I’m missing!

photo collage of 3D printed "Kettős Kereszt" painted in the colours of the Hungarian flag

3D printed “Kettős Kereszt” painted in the colours of the Hungarian flag

The program is very intuitive to use. I put a few cubes on the workplane, stretched them out into intersecting rectangular boxes and exported an STL file for printing within minutes. You can see a screenshot of the result above. I also made a version with a hole cut out of the top so you could hang it on a key chain. That turned out to be as easy as putting a cylinder in one of the boxes, stretching it out of the top and bottom box faces and marking it as a “hole” in the model.

After scaling the model down to 30% so it fits on my print bed, the final print came out as shown in this photo. It took less than 10 minutes to print at 30% in-fill and seems pretty rigid. I’ve painted on the red, white and green of the Hungarian flag and will hang this up somewhere, who knows, maybe it’ll even be good for a Christmas decoration. If you’d like to print your own Hungarian cross you can download both of my STL files here:

In honour of the heroes! Tisztelet a hősöknek!

Rooting Samsung Galaxy Mini

Samsung Galaxy Mini

Samsung Galaxy Mini

My wife’s phone (Samsung Galaxy Mini GT-S5570I) doesn’t get system updates any more, so I need to manually move Google’s updates into ROM to make space for regular apps. You need root privileges to do this, so I was following these instructions on the XDA Forum which almost work fine. You need to download and apply a file update.zip but the problem is the update script inside doesn’t include S5570I in the list of phone models it checks for, so the script aborts.

All you need to do is edit /META-INF/com/google/android/updater-script inside update.zip and include this phone model in the assertion list, for example, I duplicated lines 15 and 16 and just added an I to the end:

getprop("ro.product.device") == "GT-S5570" ||
getprop("ro.build.product") == "GT-S5570"  ||
getprop("ro.product.device") == "GT-S5570I" ||
getprop("ro.build.product") == "GT-S5570I"  ||

Everything works completely fine after that. Obviously this is not a general solution when rooting, you can’t just blindly add your own phone model into any update.zip not knowing what’s in it, but since this was from a post for specifically this model and it already had several very similar models listed, I thought it was worth the risk and it turned out just fine. Woop! 😎