TL;DR
Under Wayland, can I somehow bind AltGr + C
to Ctrl + C
?
Details
I basically want to ask this question, but for GNOME on Wayland. This means that answers involving AutoKey and xbindkeys wont work, as neither works under Wayland.
Background
I would like to remap some keys to ultimately make better use of CapsLock
.
My plan is to map CapsLock
to AltGr
, and then follow this to obtain vim-like keybindings. On Wayland, this remapping can be done through XKB files (see the link).
However, I would also like to use CapsLock
for copy/pasting. Currently, I have it mapped to Ctrl
(using XKB files). This makes CapsLock + C
work smoothly throughout the system, and I would like to preserve this.
So: With CapsLock
mapped to AltGr
, I would like Capslock (= AltGr) + C
to act as Ctrl + C
.
My question
Under Wayland, can I somehow bind AltGr + C
to Ctrl + C
?
(Without just rebinding AltGr
to Ctrl
, as that would defeat the purpose)
An alternative example with Q
In the XKB file for latin /usr/share/X11/xkb/symbols/latin
, the following behavior is defined for my Q
key:
key <AD01> { [ q, Q, at, Greek_OMEGA ] };
This states that the key has four possible outputs:
- Pressed alone, it produces
q
. - Pressed with
Shift
, it producesQ
. - Pressed with
AltGr
, it produces@
. - Pressed with
AltGr + Shift
, it producesΩ
.
Essentially what I would like to achieve is that when Q
is pressed with AltGr
, it does not produce @
but Ctrl + Q
.
Several tools exist that may do this, like KMonad, Interception Tools, and keyd.
I've had complete success with
keyd
under Wayland, so I describe what I did with that. I suggest reading the short the README for inspiration. The deamon can do a lot more than what's used here.The present solution does what I want, but circumvents using the
AltGr
detour. It treatsCapsLock
asControl
everywhere, except inh ,j ,k , l
, which it changes to arrow keys.1. INSTALLATION
I build
keyd
from source, as that was easy. The next lines first install dependencies (including C compiler), downloads the source, builds and installs it, and enables it as service, and starts it and runs it at startup.When done, it'll tell you where it installed what so you can delete it for uninstall. You can delete the source code after installation.
2. FIND THE NAME OF THE KEYBOARD YOU WANT TO REMAP
You should find the name of your keyboard, so we can make a remapping just for that. Run
and press some keys. It'll show the name of the keyboard and the keys pressed. Note down the name. Mine was
AT Translated Set 2 keyboard
.3. MAKE A CONFIGURATION FILE
Wherever, make a configuration file called whatever. We'll move it later. Let's say you use
~/my_keyboard.conf
.In it, put the following. The #'ed are comments that explains the behavior defined (the is updated for v2.1.1. I hope I didn't make any mistakes):
4. COPY AND RENAME THE CONFIGURATION FILE AND RESTART KEYD
Next, we copy the configuration to the right location and name it properly, namely according to the keyboard we want to remap.
We then restart
keyd
so it loads the new configuration:You're now up and running :)
5. A TIP: CREATE AN ALIAS TO COPY CONFIG AND RESTART KEYD
I ended up playing a lot with the config files. I edited them in a subdirectory of my home folder, then copied them over and restarted.
To make this less of a hassle, in
~/.bash_aliases
, I added