Declare a new modifier key with XKB

x11xkb

I'm trying to create a one handed keyboard layout and want to use Hyper to produce special keys when I press some keys.

For example, when I press Hyper_L and B, I want XKB to produce XF86AudioRaiseVolume.

Relevant parts from custom_2.kbd
(full code at http://pastebin.com/gm8cggn3)
:

xkb_keycodes {
    <K_36> = 54;        // b B XF86AudioRaiseVolume
    <K_85> = 133;       // Hyper_L
};

xkb_symbols {
    key <K_36> { type = "HYPER_LEVEL", [ b, B, XF86AudioRaiseVolume ] };
    key <K_85> { type = "ONE_LEVEL", [ Hyper_L ] };
};

xkb_compatibility {
    interpret Hyper_L { action = SetMods(modifiers=Hyper); };
};


xkb_types {
type "HYPER_LEVEL" {
    modifiers= Shift+Hyper;
    map[Shift]= Level2;
    map[Hyper]= Level3;
    map[Shift+Hyper]= Level3;
};
};

It seems fine to me, but when I try it:

~$ xkbcomp custom_2.kbd $DISPLAY
Error:            Identifier "Hyper" of type int is unknown
Error:            Key type mask field must be a modifier mask
                  Key type definition ignored
Warning:          Map entry for unused modifiers in HYPER_LEVEL
                  Using none instead of Shift
Error:            Identifier "Hyper" of type int is unknown
Error:            The key type map entry field must be a modifier mask
                  Ignoring illegal assignment in HYPER_LEVEL
Error:            Identifier "Hyper" of type int is unknown
Error:            The key type map entry field must be a modifier mask
                  Ignoring illegal assignment in HYPER_LEVEL
 -> 1

(error code is 1)

And now I'm stuck. Does anyone have an idea how to make this work? A solution without Hyper is OK.

Edit

By changing Super and Hyper to Mod4 and Mod5, that error goes away:

~$ xkbcomp custom_3.kbd
( no output )

~$ diff custom_{2,3}.kbd
188,190c188,190
<         interpret Super_L { action = SetMods(modifiers=Super); };
<         interpret Hyper_L { action = SetMods(modifiers=Hyper); };
<     }c;
---
>         interpret Super_L { action = SetMods(modifiers=Mod4); };
>         interpret Hyper_L { action = SetMods(modifiers=Mod5); };
>     };
204c204
<             modifiers= Shift+Hyper;
---
>             modifiers= Shift+Mod5;
206,207c206,207
<             map[Hyper]= Level3;
<             map[Shift+Hyper]= Level3;
---
>             map[Mod5]= Level3;
>             map[Shift+Mod5]= Level3;

However, it still doesn't work:

~$ xkbcomp custom_3.kbd $DISPLAY 
Error:            success in unknown
                  Couldn't write keyboard description to :0.0
X Error of failed request:  BadValue (integer parameter out of range for operation)
  Major opcode of failed request:  135 (XKEYBOARD)
  Minor opcode of failed request:  9 (XkbSetMap)
  Value in failed request:  0x8010202
  Serial number of failed request:  12
  Current serial number in output stream:  14
 -> 1 

Best Answer

Still having some (I think unrelated) issues with XKB myself, but I do have a Hyper modifier mapped, and I believe the relevant settings are these:

compat:

virtual_modifiers Shift,Control,Meta,Super,Hyper,AltGr;

interpret Hyper_R { action = SetMods(modifiers=Mod4); };

symbols:

modifier_map Mod4 { <DELE> }; // Hyper
key <DELE>  { type="UNMODIFIED", [ Hyper_R ], repeat=no  };

then something like

key <K_36> { type = "SHIFT+HYPER", [ b, B, 
                                XF86AudioRaiseVolume, XF86AudioRaiseVolume ] };

types

virtual_modifiers Meta,AltGr,Super,Hyper,Mod5;

don't need the Mod5 there unless you're using it also; but likewise, omit Shift & Control here…

type "SHIFT+HYPER" {
    modifiers= Shift+Hyper;
    map[Shift]= Level2;
    map[Hyper]= Level3;
    map[Shift+Hyper]= Level4;
};

For what it's worth, I had far, far worse hassles trying to redefing the geometry and key codes than it was worth, and ended up reverting to the pc105 key symbols in <AE01> form, even though many of them are ludicrously mis-named. (e.g. <DELE> for my Hyper key)

PS. For a working example, see https://github.com/brpocock/spacey-cadet-keyboard

Related Question