From 519871fe15abb76f4b28dea1bf03b9188ae94eeb Mon Sep 17 00:00:00 2001 From: crs Date: Sat, 30 Oct 2004 16:41:36 +0000 Subject: [PATCH] Changed X11 key mapping to fallback to the modifier keysym with the opposite handedness if the desired handedness is missing. For example, if Alt_R is unmapped as it often is on keyboards with Mode_switch, the client will use Alt_L if it is mapped when told to synthesize Alt_R. This should fix handling of AltGr sent from a win32 server. AltGr is literally just Control_L and Alt_R and, previously, an X11 client without Alt_R mapped would only simulate Control_L. This does not address the fact that the user may really just want the Alt modifier; there are already hueristics to attempt to figure that out. --- lib/platform/CXWindowsKeyState.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/platform/CXWindowsKeyState.cpp b/lib/platform/CXWindowsKeyState.cpp index 09058653..ea4184c4 100644 --- a/lib/platform/CXWindowsKeyState.cpp +++ b/lib/platform/CXWindowsKeyState.cpp @@ -584,6 +584,18 @@ CXWindowsKeyState::mapToModifierMask(unsigned int i, KeySym keysym) void CXWindowsKeyState::updateModifiers() { + struct CHandedModifiers { + KeySym m_left; + KeySym m_right; + }; + static const CHandedModifiers s_handedModifiers[] = { + { XK_Shift_L, XK_Shift_R }, + { XK_Control_L, XK_Control_R }, + { XK_Meta_L, XK_Meta_R }, + { XK_Alt_L, XK_Alt_R }, + { XK_Super_L, XK_Super_R }, + { XK_Hyper_L, XK_Hyper_R } + }; struct CModifierBitInfo { public: KeySym CXWindowsKeyState::*m_keysym; @@ -595,6 +607,24 @@ CXWindowsKeyState::updateModifiers() { &CXWindowsKeyState::m_modeSwitchKeysym, XK_ISO_Level3_Shift, NoSymbol }, }; + // for any modifier with left/right versions that has one side but + // not the other mapped, map the missing side to the existing side. + // this will map, for example, Alt_R to Alt_L if Alt_L is mapped + // but Alt_R isn't. this is almost always what the user wants + // since the user almost never cares about the difference between + // Alt_L and Alt_R. + for (size_t i = 0; i < sizeof(s_handedModifiers) / + sizeof(s_handedModifiers[0]); ++i) { + KeySymIndex lIndex = m_keysymMap.find(s_handedModifiers[i].m_left); + KeySymIndex rIndex = m_keysymMap.find(s_handedModifiers[i].m_right); + if (lIndex == m_keysymMap.end() && rIndex != m_keysymMap.end()) { + m_keysymMap[s_handedModifiers[i].m_left] = rIndex->second; + } + else if (lIndex != m_keysymMap.end() && rIndex == m_keysymMap.end()) { + m_keysymMap[s_handedModifiers[i].m_right] = lIndex->second; + } + } + // choose the keysym to use for some modifiers. if a modifier has // both left and right versions then (arbitrarily) prefer the left. for (size_t i = 0; i < sizeof(s_modifierBitTable) /