| 764 | } |
| 765 | |
| 766 | bool KeyMap::keysToRestoreModifiers( |
| 767 | const KeyItem &keyItem, int32_t, ModifierToKeys &activeModifiers, KeyModifierMask ¤tState, |
| 768 | const ModifierToKeys &desiredModifiers, Keystrokes &keystrokes |
| 769 | ) const |
| 770 | { |
| 771 | // XXX -- we're not considering modified modifiers here |
| 772 | |
| 773 | ModifierToKeys oldModifiers = activeModifiers; |
| 774 | |
| 775 | // get the pressed modifier buttons before and after |
| 776 | ButtonToKeyMap oldKeys; |
| 777 | ButtonToKeyMap newKeys; |
| 778 | collectButtons(oldModifiers, oldKeys); |
| 779 | collectButtons(desiredModifiers, newKeys); |
| 780 | |
| 781 | // release unwanted keys |
| 782 | for (const auto &[_mask, _keyItem] : oldModifiers) { |
| 783 | KeyButton button = _keyItem.m_button; |
| 784 | if (button != keyItem.m_button && !newKeys.contains(button)) { |
| 785 | EKeystroke type = kKeystrokeRelease; |
| 786 | if (_keyItem.m_lock) { |
| 787 | type = kKeystrokeUnmodify; |
| 788 | } |
| 789 | addKeystrokes(type, _keyItem, activeModifiers, currentState, keystrokes); |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | // press wanted keys |
| 794 | for (const auto &[_mask, _keyItem] : desiredModifiers) { |
| 795 | const KeyButton button = _keyItem.m_button; |
| 796 | if (button != keyItem.m_button && !oldKeys.contains(button)) { |
| 797 | EKeystroke type = kKeystrokePress; |
| 798 | if (_keyItem.m_lock) { |
| 799 | type = kKeystrokeModify; |
| 800 | } |
| 801 | addKeystrokes(type, _keyItem, activeModifiers, currentState, keystrokes); |
| 802 | } |
| 803 | } |
| 804 | return true; |
| 805 | } |
| 806 | |
| 807 | bool KeyMap::keysForModifierState( |
| 808 | KeyButton button, int32_t group, ModifierToKeys &activeModifiers, KeyModifierMask ¤tState, |