I'm trying to figure what keys are handled by:
- XCB_MOD_MASK_1
- XCB_MOD_MASK_2
- XCB_MOD_MASK_3
- XCB_MOD_MASK_4
- XCB_MOD_MASK_5
in xcb, for XCB_MOD_MASK_1 it seems to be Alt (i'm correct?), but for others button i cannot find the mapping anywhere (i tried to google them before posting, but with no success).
So what are the usual key associated to these masks?
You can actually configure what those keys (or any keys) are mapped to, with a utility like
xmodmap
. Under the X server there's eight modifiers. The 8 modifiers areshift
lock
control
mod1
mod2
mod3
mod4
mod5
To see what keys are currently mapped to these modifiers you can run
xmodmap -pm
, which prints the modifier map. Eg. for me the output isSo
Alt
generatesmod1
, for instance.Now to change
mod1
throughmod5
withxmodmap
, open~/.Xmodmap
and write something like:Then run
xmodmap ~/.Xmodmap
.And as of now, for instance,
ISO_Level3_Shift
is what gives youmod3
. How you can actually get a key from your keyboard to generate the keycode that corresponds toISO_Level3_Shift
is another challenge.Eg. to get keycode
100
to generateISO_Level3_Shift
(which is nowmod3
), add the following to your~/.Xmodmap
file and runxmodmap ~/.Xmodmap
.You might hear that
xmodmap
is deprecated, and that you should mess with XKB config files and stuff, but using XKB is much, much, much worse.In the X protocol, the 8 modifiers (
shift
, ...,mod1
, ...,mod5
) have a bitmask associated to them. This is the bitmask that XCB implements using a C enum, and its precise values are:These values aren't XCB's choice, but they're prescribed by the X protocol specification and you can use them when talking to the X server through the X protocol. Eg. when the X server sends you an
XCB_KEY_PRESS
event, this event is a 32-byte struct, and one of its fields is a bitmask where the bits are set according to the modifiers that were pressed during that key press event. Eg. if the 3rd bit is set, it meansXCB_MOD_MASK_CONTROL
is set, meaning theControl
modifier was help down.Usually Mask1 is Alt or Meta, Mask2 is Num lock, Mask3 is AltGr, Mask4 is Win, and Mask5 is Scroll lock, but this varies between X implementations and/or keyboard models.
Source: my own computer running X11, and various bits and pieces of code lying around on the 'net. Not all of them are consistent, e.g. some say Mod1 is Alt and Mod4 is Meta.
X11 programs normally let users configure actions corresponding to Mask1 ... Mask5, and have them sort out which key sets which mask.