From bf9a755bea30a7a42773724823db1eed094397ea Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Sun, 19 Jan 2014 21:40:25 +0100 Subject: [PATCH] Check all modifiers before declaring the remap keycode invalid. Sometimes XChangeKeyboardMapping() maps the keysym to a modifier. --- src/autotype/x11/AutoTypeX11.cpp | 15 ++++++++++++++- src/autotype/x11/AutoTypeX11.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/autotype/x11/AutoTypeX11.cpp b/src/autotype/x11/AutoTypeX11.cpp index 13457cb44..950b34213 100644 --- a/src/autotype/x11/AutoTypeX11.cpp +++ b/src/autotype/x11/AutoTypeX11.cpp @@ -442,11 +442,12 @@ void AutoTypePlatformX11::updateKeymap() /* determine the keycode to use for remapped keys */ inx = (m_remapKeycode - m_minKeycode) * m_keysymPerKeycode; - if (m_remapKeycode == 0 || m_keysymTable[inx] != m_currentRemapKeysym) { + if (m_remapKeycode == 0 || !isRemapKeycodeValid()) { for (keycode = m_minKeycode; keycode <= m_maxKeycode; keycode++) { inx = (keycode - m_minKeycode) * m_keysymPerKeycode; if (m_keysymTable[inx] == NoSymbol) { m_remapKeycode = keycode; + m_currentRemapKeysym = NoSymbol; break; } } @@ -467,6 +468,18 @@ void AutoTypePlatformX11::updateKeymap() XFreeModifiermap(modifiers); } +bool AutoTypePlatformX11::isRemapKeycodeValid() +{ + int baseKeycode = (m_remapKeycode - m_minKeycode) * m_keysymPerKeycode; + for (int i = 0; i < m_keysymPerKeycode; i++) { + if (m_keysymTable[baseKeycode + i] == m_currentRemapKeysym) { + return true; + } + } + + return false; +} + void AutoTypePlatformX11::startCatchXErrors() { Q_ASSERT(!m_catchXErrors); diff --git a/src/autotype/x11/AutoTypeX11.h b/src/autotype/x11/AutoTypeX11.h index 5d6708170..d2cd05b57 100644 --- a/src/autotype/x11/AutoTypeX11.h +++ b/src/autotype/x11/AutoTypeX11.h @@ -72,6 +72,7 @@ private: static int x11ErrorHandler(Display* display, XErrorEvent* error); void updateKeymap(); + bool isRemapKeycodeValid(); int AddKeysym(KeySym keysym); void AddModifier(KeySym keysym); void SendEvent(XKeyEvent* event, int event_type);