Remapping Capslock on Wayland
Here’s how to setup remapping CAPSLOCK on Arch/Wayland/Sway using the Dual Function Keys plugin from the Interception Tools library.
More specifically, I’m remapping CAPSLOCK to act as
- ESC when pressed/tapped by itself
- and as the Windows key if in combination with another key
I have the windows key setup as a modifier in the Sway window manager, to be able to position any application.
And I use ESC in vim to exit insert mode.
Previously, I used xcape
on X11, however this won’t work on Wayland, and probably won’t be in the near future as per this discussion.
Thankfully by intercepting udevmon
you can create a mapping that works on both X11 and Wayland.
Setup Dual-function-keys
Installation
- First install the plugin
sudo pacman -S interception-dual-function-keys
Configuration
- Create the mapping file i.e in
sudo nvim /etc/interception/dual-function-keys/capslock.yaml
- find available keycodes in https://raw.githubusercontent.com/torvalds/linux/master/include/uapi/linux/input-event-codes.h
- Create the udevmon configuration
sudo nvim /etc/interception/udevmon.d/capslock.yaml
- you can the
NAME
of your keyboard withsudo libinput list-devices | grep "^Device" | grep -i keyboard
- Setup
udevmon
to boot with your system
Now your keypresses should be remapped.
I got the gist of working with interception-tools
from this blog A Guide to Switching From i3 to Sway - by Scott Gilbertson