| 471 | } |
| 472 | |
| 473 | const KeyMap::KeyItem *KeyMap::mapCommandKey( |
| 474 | Keystrokes &keys, KeyID id, int32_t group, ModifierToKeys &activeModifiers, KeyModifierMask ¤tState, |
| 475 | KeyModifierMask desiredMask, bool isAutoRepeat, const std::string &lang |
| 476 | ) const |
| 477 | { |
| 478 | static const KeyModifierMask s_overrideModifiers = 0xffffu; |
| 479 | |
| 480 | // find KeySym in table |
| 481 | KeyIDMap::const_iterator i = m_keyIDMap.find(id); |
| 482 | if (i == m_keyIDMap.end()) { |
| 483 | // unknown key |
| 484 | LOG_DEBUG1("key %04x is not on keyboard", id); |
| 485 | return nullptr; |
| 486 | } |
| 487 | const KeyGroupTable &keyGroupTable = i->second; |
| 488 | |
| 489 | // find the first key that generates this KeyID |
| 490 | const KeyItem *keyItem = nullptr; |
| 491 | const auto numGroups = getNumGroups(); |
| 492 | for (int32_t groupOffset = 0; groupOffset < numGroups; ++groupOffset) { |
| 493 | const auto effectiveGroup = getEffectiveGroup(group, groupOffset); |
| 494 | const KeyEntryList &entryList = keyGroupTable[effectiveGroup]; |
| 495 | for (const auto &entry : entryList) { |
| 496 | if (entry.size() != 1) { |
| 497 | continue; |
| 498 | } |
| 499 | // match based on shift and make sure all required modifiers, |
| 500 | // except shift, are already in the desired mask; we're |
| 501 | // after the right button not the right character. |
| 502 | // we'll use desiredMask as-is, overriding the key's required |
| 503 | // modifiers, when synthesizing this button. |
| 504 | const auto &item = entry.back(); |
| 505 | KeyModifierMask desiredShiftMask = KeyModifierShift & desiredMask; |
| 506 | KeyModifierMask requiredIgnoreShiftMask = item.m_required & ~KeyModifierShift; |
| 507 | if ((item.m_required & desiredShiftMask) == (item.m_sensitive & desiredShiftMask) && |
| 508 | ((requiredIgnoreShiftMask & desiredMask) == requiredIgnoreShiftMask)) { |
| 509 | LOG_DEBUG1("found key in group %d", effectiveGroup); |
| 510 | keyItem = &item; |
| 511 | break; |
| 512 | } |
| 513 | } |
| 514 | if (keyItem) { |
| 515 | break; |
| 516 | } |
| 517 | } |
| 518 | if (!keyItem) { |
| 519 | // no mapping for this keysym |
| 520 | LOG_DEBUG1("no mapping for key %04x", id); |
| 521 | return nullptr; |
| 522 | } |
| 523 | |
| 524 | // make working copy of modifiers |
| 525 | ModifierToKeys newModifiers = activeModifiers; |
| 526 | KeyModifierMask newState = currentState; |
| 527 | auto newGroup = group; |
| 528 | |
| 529 | // don't try to change CapsLock |
| 530 | desiredMask = (desiredMask & ~KeyModifierCapsLock) | (currentState & KeyModifierCapsLock); |