I am looking to tweak the keyboard map slightly from the default.
In particular, I’d like to make the left Alt key default to Super (i.e. as if Fn+LeftAlt was pressed). And I’d like to make Control, Alt, and Super “sticky” keys, so that I don’t have to hold them, and they’ll apply to the next keystroke.
I suspect this will improve the experience with emacs, and sway.
Do I need to customize the keyboard firmware for this, or can it all be done in the keyboard map?
There are a few ways to enable sticky keys on X. xkbset sticky -twokey -latchlock
Would enable sticky, but not disable it if you pressed multiple keys, and would not latch the sticky key (like a caps lock key) if you press it twice. And xkbset -sticky would undo the above. Setting it as default is possible too with the xkboptions. But I forget how.
There are also ways to do more complex sticky key behavior with background programs. Sometimes XKB can be a little limited on behavior unless you are really clever with how you use the shift layers.
Remapping Alt as Super and Super as Alt is very straight forwrad. You just change what scan code maps to what. You can get the code by running the ‘xev’ program and look at the logs for events. Or copy it from another file in /usr/share/X11/xkb/…
You can work on your own custom remapping layouts by defining one in $HOME/.xkb/
You can use this utility to generate a generate template with the proper file layout to make it easier on yourself
git clone https://gitlab.freedesktop.org/whot/xkblayout
cd xkblayout
xkblayout --layout 'us(orangetide)'
Name your variant whatever you like. And you’ll then select that variant in order to use your new mapping. (it’s even possible to have multiple keyboard layouts and cycle through them). The README on that gitlab repo will describe a bit of the process. But there is some more general advice on how to deal with XKB and keyboards at Who-T: No user-specific XKB configuration in X
Also, for those of us on Wayland, most of this advice works there too but there is a little extra work depending on the compositor you’re using. Tutorial · WayfireWM/wayfire Wiki · GitHub is the one I used to get myself setup on Wayfire. (default WM on newer versions of Raspbian)
I had some limited success with sticky keys via xkb – I could get shift, control, and super to be sticky, but not alt for some reason.
Also, my friend and I have been trying to swap alt and super without success for some time: via hwdb and via setkeycodes, and oddly this has had no effect.
I’ve swapped alt and super with xmodmap on PCs before, many many years ago (actually for an iBook running Linux PPC). I don’t know if it still works, but that used to be a very easy way to deal with a simple substitution of keys on X11 (doesn’t work on Wayland)
setkeycodes only remaps the Linux console keymap and doesn’t alter what X11/Wayland see. You definitely can swap Alt and Super on the console with it. Things get a little confusing if you expect Alt-Fkey to swap virtual consoles when X11 has control, since it against has its own mapping. Default is Alt+Ctrl+Fkey for the current mapping, you can see it buried in the XKB symbol files.
After messing around with it for a while, I decided that I actually prefer the stock keyboard map.
What I did for sway was use the Super_R with sway’s “modes” in order to emulate a sticky modifier key. Bonus points is that there’s some feedback that the modifier has been set. So, it takes two hands to activate sway functions, but at least you don’t have to keep holding them down. I only needed a few teaks to my pocketCHIP config to get this to work.
The only thing I’d really like to change is to bind the select / start / and Y X B A pad to regular keyboard keys, so they could be used more easily for window manager functions. But I’m fairly certain the best way to handle this is to hack on the keyboard firmware, which I don’t have time for.
On X11, there are some software hacks that can convert gamepad input to a keyboard events, but they don’t seem to work on sway. If there’s a way to do this in sway – in particular – and wayland, in general, I’d love to hear about it. But I’ve done arduino stuff in the past, and so if it comes to it, I will modify the firmware and post up about it.