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.
This commit is contained in:
crs 2004-10-30 16:41:36 +00:00
parent 719757ca22
commit 519871fe15
1 changed files with 30 additions and 0 deletions

View File

@ -584,6 +584,18 @@ CXWindowsKeyState::mapToModifierMask(unsigned int i, KeySym keysym)
void void
CXWindowsKeyState::updateModifiers() 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 { struct CModifierBitInfo {
public: public:
KeySym CXWindowsKeyState::*m_keysym; KeySym CXWindowsKeyState::*m_keysym;
@ -595,6 +607,24 @@ CXWindowsKeyState::updateModifiers()
{ &CXWindowsKeyState::m_modeSwitchKeysym, XK_ISO_Level3_Shift, NoSymbol }, { &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 // choose the keysym to use for some modifiers. if a modifier has
// both left and right versions then (arbitrarily) prefer the left. // both left and right versions then (arbitrarily) prefer the left.
for (size_t i = 0; i < sizeof(s_modifierBitTable) / for (size_t i = 0; i < sizeof(s_modifierBitTable) /