Sway uses Wayland, so any XKB files will be parsed by Sway, not X.

  • I want to add a layer on the keyboard (probably using Hyper)
  • I want to shuffle some modifier keys around

I've looked at a lot of sites, but I still don't know how to accomplish this. There are so many parts to XKB, and I'm not sure what goes where. I want an example file (or files) and an explanation.


Let's say your xkb configuration file is named custom-xkb, and is stored in ~/.config. Then you include this in your sway configuration file:

input "type:keyboard" {           # or input <identifier> 
  xkb_file ~/.config/xkb/custom-xkb

You probably already know that part -- the hard part is creating the custom-xkb file. I'm no specialist, but here's what I'd do:

  1. I'd do a web search for "xkb specification", and that brings to you all kinds of information, from wikipedia to the x.org's full specification. You probably have a collection of resources like those already.
  2. Then I'd find in my system the default keyboard configuration files, maybe in \etc\X11\xdg\ or something (you may have to look around a bit: in my weird distribution, the path is /nix/store/n1mlvwrkdlm77b4ai9s26kwji89jjb65-xkeyboard-config-2.27/share/X11/xkb/).
  3. In that path, I'd look for two sub-directories: symbols and types. The first is where the key-maps for all the different languages are, and within each file, the key-map variations for that language. The second sub-directory is where the virtual keys are defined (such as Mod1, Control, etc.).
  4. Then I would copy the contents of those files to my ~/.config/xkb/custom-xkb and experiment different edits to see what happens. And try to clear out my doubts using the internet resources I'd have collected. If anything catastrophic happened, I'd hit Control+Alt+F1, then do a nox login, comment the line xkb_file ~/.config/xkb/custom-xkb and restart the X server...
  5. I wouldn't tamper with the contents of the sub-directories rules, geometry and keycodes. But you need to, take a look into those too.

I haven't actually done none of that, but maybe it works. I think that looking at the actual configuration files helps to figure out what the tutorials and guides are actually saying...

Gook luck

  • Notice also that in sway's input {...} structure, there are separate commands to set rules, symbols... – Cássio Tavares Aug 19 '20 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.