diff --git a/src/autotype/x11/AutoTypeX11.cpp b/src/autotype/x11/AutoTypeX11.cpp index afa0e1de3..c30433095 100644 --- a/src/autotype/x11/AutoTypeX11.cpp +++ b/src/autotype/x11/AutoTypeX11.cpp @@ -551,6 +551,9 @@ void AutoTypePlatformX11::ReadKeymap() m_altgrMask = 0; m_altgrKeysym = NoSymbol; modifiers = XGetModifierMapping(m_dpy); + /* default value, used if we do not find a mapping */ + inx_altgr = 3; + for (i = 0; i < 8; i++) { for (pos = 0; pos < modifiers->max_keypermod; pos++) { keycode = modifiers->modifiermap[i * modifiers->max_keypermod + pos]; @@ -567,12 +570,18 @@ void AutoTypePlatformX11::ReadKeymap() m_altgrMask = 0x0101 << i; /* I don't know why, but 0x2000 was required for mod3 on my Linux box */ m_altgrKeysym = keysym; + + /* set the index of the XGetKeyboardMapping for the AltGr key */ + inx_altgr = i; } } else if (keysym == XK_ISO_Level3_Shift) { /* if no Mode_switch, try to use ISO_Level3_Shift instead */ /* however, it may not work as intended - I don't know why */ m_altgrMask = 1 << i; m_altgrKeysym = keysym; + + /* set the index of the XGetKeyboardMapping for the AltGr key */ + inx_altgr = i; } } } @@ -631,15 +640,15 @@ void AutoTypePlatformX11::SendKeyPressedEvent(KeySym keysym, unsigned int shift) break; } } - if (!found && m_altgrMask && 3 <= m_keysymPerKeycode) { + if (!found && m_altgrMask && inx_altgr + 1 <= m_keysymPerKeycode) { for (keycode = m_minKeycode; !found && (keycode <= m_maxKeycode); keycode++) { inx = (keycode - m_minKeycode) * m_keysymPerKeycode; - if (m_keysymTable[inx + 2] == keysym) { + if (m_keysymTable[inx + inx_altgr] == keysym) { shift &= ~ShiftMask; shift |= m_altgrMask; found = TRUE; break; - } else if (4 <= m_keysymPerKeycode && m_keysymTable[inx + 3] == keysym) { + } else if (inx_altgr + 2 <= m_keysymPerKeycode && m_keysymTable[inx + inx_altgr + 1] == keysym) { shift |= ShiftMask | m_altgrMask; found = TRUE; break; diff --git a/src/autotype/x11/AutoTypeX11.h b/src/autotype/x11/AutoTypeX11.h index 7e67dc83f..0cb88fdaa 100644 --- a/src/autotype/x11/AutoTypeX11.h +++ b/src/autotype/x11/AutoTypeX11.h @@ -98,6 +98,8 @@ private: int m_altMask; int m_metaMask; int m_altgrMask; + /* index of the XGetKeyboardMapping for the AltGr key */ + int inx_altgr; KeySym m_altgrKeysym; };