cub-uanic
cub-uanic

Reputation: 141

Right GUI key in XMonad

Is there a possibility to make different bindings for L_GUI+key and R_GUI+key in XMonad, and if yes then how? Same question is for R_CTRL, R_SFT and R_ALT, but they are not so important for me.

Upvotes: 1

Views: 367

Answers (2)

mhwombat
mhwombat

Reputation: 8136

I'm not familiar with the L_GUI key, but in general you can have different mappings for keys provided that they return different codes. An easy way to determine this is to use xev. With xev running, typing a key causes two events, one for the key press and one for the key release.

I have an Irish keyboard. When I run xev and type the left Alt key, the events are:

KeyPress event, serial 33, synthetic NO, window 0xe00001,
    root 0x1dc, subw 0x0, time 4233053053, (748,263), root:(1711,266),
    state 0x10, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 33, synthetic NO, window 0xe00001,
    root 0x1dc, subw 0x0, time 4233053237, (748,263), root:(1711,266),
    state 0x18, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

So the keycode is 64. Note that the keysim is Alt_l. to map this key I would look in Graphics.X11.Types and find that the constant for this key is xK_Alt_L.

When I press the right Alt key (which is labelled Alt Gr) on my keyboard, I get a different keycode, 108. So I can have different bindings.

KeyPress event, serial 33, synthetic NO, window 0xe00001,
    root 0x1dc, subw 0x0, time 4233053813, (748,263), root:(1711,266),
    state 0x10, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
    XKeysymToKeycode returns keycode: 92
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 33, synthetic NO, window 0xe00001,
    root 0x1dc, subw 0x0, time 4233053989, (748,263), root:(1711,266),
    state 0x90, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
    XKeysymToKeycode returns keycode: 92
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

I may be wrong, but I think U.S. keyboards return the same keycode for the left and right Alt keys. In that case, the keys could not have different bindings.

Upvotes: 2

Daniel Wagner
Daniel Wagner

Reputation: 152707

For such questions, one may ask xev what it thinks of your keypress. Here's some example output from me pressing left-control+a and right-control+a:

KeyPress event, serial 36, synthetic NO, window 0x1400001,
    root 0x2a9, subw 0x0, time 4207488563, (419,468), root:(2341,612),
    state 0x0, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 36, synthetic NO, window 0x1400001,
    root 0x2a9, subw 0x0, time 4207489283, (419,468), root:(2341,612),
    state 0x4, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (01) ""
    XmbLookupString gives 1 bytes: (01) ""
    XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x1400001,
    root 0x2a9, subw 0x0, time 4207489403, (419,468), root:(2341,612),
    state 0x4, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (01) ""
    XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x1400001,
    root 0x2a9, subw 0x0, time 4207490035, (419,468), root:(2341,612),
    state 0x4, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 36, synthetic NO, window 0x1400001,
    root 0x2a9, subw 0x0, time 4207538195, (-175,35), root:(1747,179),
    state 0x0, keycode 105 (keysym 0xffe4, Control_R), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 36, synthetic NO, window 0x1400001,
    root 0x2a9, subw 0x0, time 4207538595, (-175,35), root:(1747,179),
    state 0x4, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (01) ""
    XmbLookupString gives 1 bytes: (01) ""
    XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x1400001,
    root 0x2a9, subw 0x0, time 4207538715, (-175,35), root:(1747,179),
    state 0x4, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (01) ""
    XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x1400001,
    root 0x2a9, subw 0x0, time 4207539227, (-175,35), root:(1747,179),
    state 0x4, keycode 105 (keysym 0xffe4, Control_R), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

As you can see, though left-control and right-control produce different keypresses when depressed, they produce the same state when held down during another keypress. So one would not be able to differentiate them in my current setup.

If you would like to have them be different modifiers, that can be arranged with xmodmap; however, there is a limited total number of modifiers -- I think maybe four or so. But see the xmodmap documentation for details.

Upvotes: 1

Related Questions