How to bind AltGr to +

keyboard-layoutxkbxorg

I am trying to create a linux equivalent of Ergonomic Telugu Keyboard layout called Sarala (Hard la). I have been able to map all the keys so far. The layout uses the following key combinations for various levels.

None (Base): Level1
Shift: Level2
Ctrl + Alt: Level3
Ctrl + Alt + Shift:Level4

Where as linux uses the following for various levels.

None (Base): Level1
Shift: Level2
RAlt: Level3
RAlt + Shift:Level4

To be able to match the key combinations with my layout, I would have to map AltGr with a Ctrl + Alt. I have unsuccessfully searched though various files in /usr/share/X11/xkb/. Does any body know how I can bind the ISO_Level3_Shift with Ctrl + Alt ?

key <RALT>  {
    symbols[Group1]= [ Mode_switch, Multi_key  ],
    virtualMods= AltGr
};

If you want to look at the layout, it's here

Best Answer

You need to define a new xkb type. You can see examples in your xkb/types directory (usually /usr/share/X11/xkb/types). There you can define arbitrary combinations of modifiers to get different levels of shifting. For your problem, you can use something like this:

type "C_A_to_L3" {
    modifiers = Control+Alt+Shift;
    map[None] = Level1;
    map[Shift] = Level2;
    map[Control+Alt] = Level3;
    map[Control+Alt+Shift] = Level4;
    level_name[Level1] = "Base";
    level_name[Level2] = "Shift";
    level_name[Level3] = "Alt Base";
    level_name[Level4] = "Shift Alt";
};

Then in your symbols file you can set that type as the default, or set on a per-key basis what type it is. Note that you need the type to be in a file in the types directory, and the key definition in a file in the symbols directory -- xkb uses a strict filesystem hierarchy to find each component.

I've done a fair bit of hacking on keyboard layouts myself to build my custom layout (https://github.com/willghatch/hatchak), which has gone through various iterations where I've experimented with weird things. XKB can be pretty finnicky and strange at times, but it is still the most configurable keyboard system I've seen by far. The best references if you have more troubles are:

[edit: original links are currently down, but thankfully archive.org exists]

https://web.archive.org/web/20150722164820/http://www.charvolant.org/~doug/xkb/html/index.html

and

https://web.archive.org/web/20190419170426/http://pascal.tsu.ru/en/xkb/

Beware -- while that's the best documentation I've found, it leaves plenty of murky edge cases. Good luck.

Related Question