Track the last remapped keysym in m_currentRemapKeycode to enforce

a new computation of m_remapKeycode when the keyboard layout
changes.
(This fixes a potential problem with AddKeysym overwriting
 used keysyms after applying a new keyboard layout).
This commit is contained in:
Albert Weichselbraun 2013-12-16 09:18:03 +01:00
parent 1fce1ac905
commit 6a50a76466
2 changed files with 12 additions and 9 deletions

View File

@ -46,7 +46,8 @@ AutoTypePlatformX11::AutoTypePlatformX11()
m_keysymTable = Q_NULLPTR;
m_xkb = Q_NULLPTR;
m_specialCharacterKeycode = 0;
m_remapKeycode = 0;
m_currentRemapKeycode = NoSymbol;
m_modifierMask = ControlMask | ShiftMask | Mod1Mask | Mod4Mask;
m_loaded = true;
@ -440,11 +441,12 @@ void AutoTypePlatformX11::updateKeymap()
&m_keysymPerKeycode);
/* determine the keycode to use for remapped keys */
if (m_specialCharacterKeycode == 0) {
inx = (m_remapKeycode - m_minKeycode) * m_keysymPerKeycode;
if (m_remapKeycode == 0 || m_keysymTable[inx] != m_currentRemapKeycode) {
for (keycode = m_minKeycode; keycode <= m_maxKeycode; keycode++) {
inx = (keycode - m_minKeycode) * m_keysymPerKeycode;
if (m_keysymTable[inx] == NoSymbol) {
m_specialCharacterKeycode = keycode;
m_remapKeycode = keycode;
break;
}
}
@ -505,13 +507,13 @@ int AutoTypePlatformX11::x11ErrorHandler(Display* display, XErrorEvent* error)
*/
int AutoTypePlatformX11::AddKeysym(KeySym keysym)
{
if (m_specialCharacterKeycode == 0) {
if (m_remapKeycode == 0) {
return 0;
}
int inx = (m_specialCharacterKeycode - m_minKeycode) * m_keysymPerKeycode;
int inx = (m_remapKeycode- m_minKeycode) * m_keysymPerKeycode;
m_keysymTable[inx] = keysym;
XChangeKeyboardMapping(m_dpy, m_specialCharacterKeycode, m_keysymPerKeycode, &m_keysymTable[inx], 1);
XChangeKeyboardMapping(m_dpy, m_remapKeycode, m_keysymPerKeycode, &m_keysymTable[inx], 1);
XFlush(m_dpy);
/* Xlib needs some time until the mapping is distributed to
@ -521,7 +523,7 @@ int AutoTypePlatformX11::AddKeysym(KeySym keysym)
ts.tv_nsec = 10 * 1000 * 1000;
nanosleep(&ts, Q_NULLPTR);
return m_specialCharacterKeycode;
return m_remapKeycode;
}
/*

View File

@ -106,8 +106,9 @@ private:
int m_minKeycode;
int m_maxKeycode;
int m_keysymPerKeycode;
/* dedicated 'special character' keycode */
int m_specialCharacterKeycode;
/* dedicated keycode for remapped keys */
unsigned int m_remapKeycode;
KeySym m_currentRemapKeycode;
KeyCode m_modifier_keycode[N_MOD_INDICES];
bool m_loaded;
};