| 42 | } |
| 43 | |
| 44 | bool KeybindingsMenu::sendEvent(InputEvent const& event) { |
| 45 | if (!m_visible) |
| 46 | return false; |
| 47 | |
| 48 | if (m_activeKeybinding) { |
| 49 | if (m_context->actions(event).contains(InterfaceAction::KeybindingClear)) { |
| 50 | clearActive(); |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | if (m_context->actions(event).contains(InterfaceAction::KeybindingCancel)) { |
| 55 | exitActiveMode(); |
| 56 | return true; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if (m_activeKeybinding) { |
| 61 | // HACK: I need to pass events only to the trash button first. |
| 62 | if (m_activeKeybinding->parent()->fetchChild<ButtonWidget>("deleteBinding")->sendEvent(event)) |
| 63 | return true; |
| 64 | |
| 65 | if (auto keyUp = event.ptr<KeyUpEvent>()) { |
| 66 | if (Maybe<KeyMod> modKey = KeyChordMods.maybe(keyUp->key)) { |
| 67 | m_currentMods &= ~*modKey; |
| 68 | setKeybinding(KeyChord{keyUp->key, m_currentMods}); |
| 69 | return true; |
| 70 | } |
| 71 | } else if (auto keyDown = event.ptr<KeyDownEvent>()) { |
| 72 | Maybe<KeyMod> modKey = KeyModNames.maybeLeft(KeyNames.getRight(keyDown->key)); |
| 73 | |
| 74 | if (modKey) { |
| 75 | m_currentMods |= *modKey; |
| 76 | return true; |
| 77 | } else { |
| 78 | setKeybinding(KeyChord{keyDown->key, m_currentMods}); |
| 79 | return true; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | if (m_context->actions(event).contains(InterfaceAction::GuiClose)) { |
| 85 | dismiss(); |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | if (Pane::sendEvent(event)) |
| 90 | return true; |
| 91 | |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | void KeybindingsMenu::show() { |
| 96 | m_origConfiguration = Root::singleton().configuration()->get("bindings"); |