| 805 | } |
| 806 | |
| 807 | bool KeyMap::keysForModifierState( |
| 808 | KeyButton button, int32_t group, ModifierToKeys &activeModifiers, KeyModifierMask ¤tState, |
| 809 | KeyModifierMask requiredState, KeyModifierMask sensitiveMask, KeyModifierMask notRequiredMask, |
| 810 | Keystrokes &keystrokes |
| 811 | ) const |
| 812 | { |
| 813 | // compute which modifiers need changing |
| 814 | KeyModifierMask flipMask = ((currentState ^ requiredState) & sensitiveMask); |
| 815 | // if a modifier is not required then don't even try to match it. if |
| 816 | // we don't mask out notRequiredMask then we'll try to match those |
| 817 | // modifiers but succeed if we can't. however, this is known not |
| 818 | // to work if the key itself is a modifier (the numlock toggle can |
| 819 | // interfere) so we don't try to match at all. |
| 820 | flipMask &= ~notRequiredMask; |
| 821 | LOG( |
| 822 | (CLOG_DEBUG1 "flip: %04x (%04x vs %04x in %04x - %04x)", flipMask, currentState, requiredState, |
| 823 | sensitiveMask & 0xffffu, notRequiredMask & 0xffffu) |
| 824 | ); |
| 825 | if (flipMask == 0) { |
| 826 | return true; |
| 827 | } |
| 828 | |
| 829 | // fix modifiers. this is complicated by the fact that a modifier may |
| 830 | // be sensitive to other modifiers! (who thought that up?) |
| 831 | // |
| 832 | // we'll assume that modifiers with higher bits are affected by modifiers |
| 833 | // with lower bits. there's not much basis for that assumption except |
| 834 | // that we're pretty sure shift isn't changed by other modifiers. |
| 835 | int32_t bit = kKeyModifierNumBits; |
| 836 | while (bit-- > 0) { |
| 837 | KeyModifierMask mask = (1u << bit); |
| 838 | if ((flipMask & mask) == 0) { |
| 839 | // modifier is already correct |
| 840 | continue; |
| 841 | } |
| 842 | |
| 843 | // do we want the modifier active or inactive? |
| 844 | bool active = ((requiredState & mask) != 0); |
| 845 | |
| 846 | // get the KeyItem for the modifier in the group |
| 847 | const KeyItem *keyItem = keyForModifier(button, group, bit); |
| 848 | if (keyItem == nullptr) { |
| 849 | if ((mask & notRequiredMask) == 0) { |
| 850 | LOG_DEBUG1("no key for modifier %04x", mask); |
| 851 | return false; |
| 852 | } else { |
| 853 | continue; |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | // if this modifier is sensitive to modifiers then adjust those |
| 858 | // modifiers. also check if our assumption was correct. note |
| 859 | // that we only need to adjust the modifiers on key down. |
| 860 | KeyModifierMask sensitive = keyItem->m_sensitive; |
| 861 | if ((sensitive & mask) != 0) { |
| 862 | // modifier is sensitive to itself. that makes no sense |
| 863 | // so ignore it. |
| 864 | LOG_DEBUG1("modifier %04x modified by itself", mask); |
nothing calls this directly
no outgoing calls
no test coverage detected