Ubuntu – Multiple modifier layers with XKB (on a japanese keyboard)

lubuntulxdexkb

I have the following keyboard (HHKB JP).

image

I'm using Lubuntu 14.04, and I've edited /usr/share/X11/xkb/symbols/us to implement a custom layout.

Now, I want to use the following keys as 5th, 6th, 7th, …, and 20th level modifiers. (On Windows, I accomplish this with AutoHotkey, and now I can't live without (at least some of) them.)

enter image description here

I have 2 problems.

  1. I don't know what the "names" for some of the non-standard keys on the keyboard (in order to add them to /usr/share/X11/xkb/symbols/us).
  2. I don't know how to add extra modifiers with xkb (I understand xmodmap is deprecated), specially "normal" keys like 9.

My questions are:

  1. How do I figure out the names/codes for the mystery keys (eg. key <AC01>)?
  2. How do I add an arbitrary number of modifier layers to any given key?

Note: perhaps this cannot be accomplished with XKB. I'd be delighted to know of some scripting tool that can implement this.

Best Answer

XKB layouts are defined in a model called RMLVO: Rules, Model, Layout, Variant, Options. The system XKB database is usually in /usr/share/X11/xkb:

/usr/share/X11/xkb/
├── compat       # ??? dark magic here, avoid
├── geometry     # as in physical, eg for generating layout maps
├── keycodes     # helpful for translating keycodes (from xev) to <FOO>
├── rules        # "evdev" is the important one; *.lst & *.xml are descriptions
├── symbols      # main layouts, variants, optional overrides
└── types        # ??? dark magic here, avoid

The keycodes directory will define keynames like <CAPS> or <AC01> from scancodes that the keys are actually generating. setxkbmap -query -verbose 10 will show you exactly what files are accessed to build your current keymap; when it says keycodes: evdev+aliases(qwerty), it's loading the ../keycodes/evdev file and the qwerty stanza from the ../keycodes/aliases file. If you use tools like xev to determine what keycode a key is generating, those files will show what keyname is mapped to that code.


Your modifier question is tougher. I've only seen reference to 8 ISO levels, and I'm not sure if that's an XKB limitation or simply that no common layouts use more than that. (After examining this further, I'm pretty sure you'd have to alter XKB code to add additional

            symbol    press this
level 1       a       key
level 2       A       shift+key
level 3       á       <level3>+key
level 4       Á       <level3>+shift+key
level 5       ??      <level5>+key
level 6       ??      <level5>+shift+key
level 7       ??      <level5>+<level3>+key
level 8       ??      <level5>+<level3>+shift+key

As you can see, in an 8-level layout there's only 2 keys that act as "new modifier" keys. See /usr/share/X11/xkb/compat/level5 and /usr/share/X11/xkb/types/level5, where level5 shift, latch, and lock behaviors are defined; these are then attached to keys by symbol options defined in /usr/share/X11/xkb/symbols/level5.

If you defined your own level9 modifier, then, combining with existing levels would give you 8 more levels before you'd need another level modifier:

            symbol    press this
level 9       ??      <level9>+key
level 10      ??      <level9>+shift+key
level 11      ??      <level9>+<level3>+key
level 12      ??      <level9>+<level3>+shift+key
level 13      ??      <level9>+<level5>+key
level 14      ??      <level9>+<level5>+shift+key
level 15      ??      <level9>+<level5>+<level3>+key
level 16      ??      <level9>+<level5>+<level3>+shift+key

As you can see, this is starting to be a lot of keys pressed at once. Using locks and latches instead of shifts would cut that down, but this would be a very complicated layout, and we've only imagined adding one level chooser. Each additional chooser would double the existing levels.


The "modifiers" you envision are probably selecting one specific level, which is why you think you need so many. You might be able to define selection actions like that, and put them on, say, level3 of those keys, so level3+key9 gives you a level14_latch action, and then whatever key you press next will give you the 14th level of that key.

Edit: Another question asked specifically about making an ISO_Level4_{Shift,Latch,Lock}, and I demonstrated a fake ISO_Level4_Latch using existing XKB keysyms and actions. That method should be effective for levels 4, 6, 7 and 8.

Related Question