Search code examples
linuxintellij-ideapycharmkeyboard-shortcuts

Intellij (PyCharm) does not recognize AltGr Shortcuts anymore in Linux


I have a German keyboard and I am using my Alt Gr for short cuts very heavily. Now I recently switched to a newer Linux version and all my Alt Gr stopped working. Instead of executing the command attributed to the shortcut the bound character i.e. ŋ for Alt Gr + G was shown.

Doing some research I found some long standing related bug tickets:

But none of the settings shown there fixed the shortcuts. So how to fix them?

The output of xmodmap -pke and setxkbmap -print -verbose 10 showed no difference between my old Linux (working shortcuts) and the new one.


Solution

  • The problem seemed to be related to Modifier Keys. It turned out that xmodmap -pm showed a different configuration between the two Linux.

    Fedora 22 (not working) showed

    shift       Shift_L (0x32),  Shift_R (0x3e)
    lock        Caps_Lock (0x42)
    control     Control_L (0x25),  Control_R (0x69)
    mod1        Alt_L (0x40),  Alt_L (0xcc),  Meta_L (0xcd)
    mod2        Num_Lock (0x4d)
    mod3        Mode_switch (0xcb)
    mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
    mod5        ISO_Level3_Shift (0x5c)
    

    While Ubuntu (working) was returning

    shift       Shift_L (0x32),  Shift_R (0x3e)
    lock        Caps_Lock (0x42)
    control     Control_L (0x25),  Control_R (0x69)
    mod1        Alt_L (0x40),  Alt_L (0xcc),  Meta_L (0xcd)
    mod2        Num_Lock (0x4d)
    mod3      
    mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
    mod5        ISO_Level3_Shift (0x5c),  ISO_Level3_Shift (0x6c),  Mode_switch (0xcb)
    

    With the help of this Archlinux Wiki article, I was able to create the following ~/.Xmodmap.

    ! First we need clear the existing mods
    clear mod1
    clear mod3
    clear mod5
    ! The Mode_switch needs to be bound to a key, in order to work
    ! In my layout this wasn't the case, so I needed to manually do this
    keycode 203 = Mode_switch NoSymbol Mode_switch
    ! Finally delcare the correct modifiers
    add mod1 = Alt_L Meta_L
    add mod5 = ISO_Level3_Shift Mode_switch
    

    This fixed my Alt Gr shortcuts in PyCharm, now they are recognized as expected. Settings > Keymap > Use national layouts for shortcuts is off.

    Note, I can still write special chars like ŋ in other editors and also in PyCharm as long as no shortcut is bound to it.