I am intending to add an additional level to the unconventional 8-level German Neo2 layout for redirecting keys to QWERTY when the control modifer is pressed.

Whilst I don't expect 9 levels to not work, it would be reassuring to know the maximum number of levels.
I read somewhere that the state/level/type information is bitmasked as a 32-bit piece of data (and that's indeed the hex output of xev).

Are all of those 32 bits used for conveying level information?
Edit: I conflated this 2-digit hex — which should be the maximum number of modifier keys — with the maximum number of levels (modifier key combinations). This information should not be relevant to my question.

I.e. something like the following. Because I began learning about XKB yesterday and I have yet to come across a type exceeding 8 levels.

    // [...]
    // + map[Control]= Level0;

    level_name[Level0] = "QWERTY shortcuts"
    level_name[Level1] = "Base";
    level_name[Level2] = "Shift";
    level_name[Level3] = "Alt Base";
    level_name[Level4] = "Shift Alt";
    level_name[Level5] = "X";
    level_name[Level6] = "X Shift";
    level_name[Level7] = "X Alt Base";
    level_name[Level8] = "X Shift Alt";

1 Answer 1


All quotes coming from The X Keyboard Extension : Library Specification

The total number of levels for a given key type is kept in some XkbKeyTypeRec structure as an unsigned char : num_levels (page 140)

typedef struct { /* Key Type */
 unsigned char num_levels; /* total # shift levels, do not modify directly */
} XkbKeyTypeRec, *XkbKeyTypePtr;

The num_levels field holds the total number of shift levels for the key type. Xkb uses num_levels to ensure the array of symbols bound to a key is large enough.

Which theoretically limits the maximum number of levels to 255 (since starting from 1)

However, since the number of symbols per key is, per design, limited to 255 and there can be up to four groups…, the practical limit is divided by four : 63, as we can read on page 127

The core implementation restricts the number of symbols per key to 255. With four groups, this allows for up to 63 symbols (or shift levels) per group.

BTW, if you want to change the number of levels for a given key type, use XkbResizeKeyType (page 145) :

XkbResizeKeyType ( xkb , type_ndx , map_count , want_preserve ,
new_num_lvls )
XkbDescPtr xkb ; /* keyboard description containing client map to update */
int type_ndx ; /* index in xkb->map->types of type to change */
int map_count ; /* total # of map entries needed for the type */
Bool want_preserve ; /* True => list of preserved modifiers is necessary */
int new_num_lvls ; /* new max # of levels for type */

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .