diff options
Diffstat (limited to 'backends')
-rw-r--r-- | backends/keymapper/keymapper.cpp | 45 | ||||
-rw-r--r-- | backends/keymapper/keymapper.h | 25 |
2 files changed, 30 insertions, 40 deletions
diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp index cda34ff052..7ada676516 100644 --- a/backends/keymapper/keymapper.cpp +++ b/backends/keymapper/keymapper.cpp @@ -180,38 +180,35 @@ void Keymapper::popKeymap(const char *name) { } -bool Keymapper::notifyEvent(const Common::Event &ev) { - bool mapped = false; +List<Event> Keymapper::mapEvent(const Event &ev, EventSource *source) { + if (source && !source->allowMapping()) { + return DefaultEventMapper::mapEvent(ev, source); + } + + List<Event> mappedEvents; if (ev.type == Common::EVENT_KEYDOWN) - mapped = mapKeyDown(ev.kbd); + mappedEvents = mapKeyDown(ev.kbd); else if (ev.type == Common::EVENT_KEYUP) - mapped = mapKeyUp(ev.kbd); + mappedEvents = mapKeyUp(ev.kbd); - if (mapped) - return true; + if (!mappedEvents.empty()) + return mappedEvents; else - return mapEvent(ev); -} - -bool Keymapper::mapEvent(const Common::Event &ev) { - // pass through - copy the event - Event evt = ev; - addEvent(evt); - return true; + return DefaultEventMapper::mapEvent(ev, source); } -bool Keymapper::mapKeyDown(const KeyState& key) { +List<Event> Keymapper::mapKeyDown(const KeyState& key) { return mapKey(key, true); } -bool Keymapper::mapKeyUp(const KeyState& key) { +List<Event> Keymapper::mapKeyUp(const KeyState& key) { return mapKey(key, false); } -bool Keymapper::mapKey(const KeyState& key, bool keyDown) { +List<Event> Keymapper::mapKey(const KeyState& key, bool keyDown) { if (!_enabled || _activeMaps.empty()) - return false; + return List<Event>(); Action *action = 0; @@ -238,11 +235,9 @@ bool Keymapper::mapKey(const KeyState& key, bool keyDown) { } if (!action) - return false; + return List<Event>(); - executeAction(action, keyDown); - - return true; + return executeAction(action, keyDown); } Action *Keymapper::getAction(const KeyState& key) { @@ -251,7 +246,8 @@ Action *Keymapper::getAction(const KeyState& key) { return action; } -void Keymapper::executeAction(const Action *action, bool keyDown) { +List<Event> Keymapper::executeAction(const Action *action, bool keyDown) { + List<Event> mappedEvents; List<Event>::const_iterator it; for (it = action->events.begin(); it != action->events.end(); ++it) { @@ -291,8 +287,9 @@ void Keymapper::executeAction(const Action *action, bool keyDown) { } evt.mouse = _eventMan->getMousePos(); - addEvent(evt); + mappedEvents.push_back(evt); } + return mappedEvents; } const HardwareKey *Keymapper::findHardwareKey(const KeyState& key) { diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h index 626df013ac..31bfcbc080 100644 --- a/backends/keymapper/keymapper.h +++ b/backends/keymapper/keymapper.h @@ -39,7 +39,7 @@ namespace Common { const char *const kGuiKeymapName = "gui"; const char *const kGlobalKeymapName = "global"; -class Keymapper : public Common::EventMapper, private Common::ArtificialEventSource { +class Keymapper : public Common::DefaultEventMapper { public: struct MapRecord { @@ -77,6 +77,9 @@ public: Keymapper(EventManager *eventMan); ~Keymapper(); + // EventMapper interface + virtual List<Event> mapEvent(const Event &ev, EventSource *source); + /** * Registers a HardwareKeySet with the Keymapper * @note should only be called once (during backend initialisation) @@ -137,37 +140,27 @@ public: */ void popKeymap(const char *name = 0); - // Implementation of the EventMapper interface - bool notifyEvent(const Common::Event &ev); - bool pollEvent(Common::Event &ev) { return Common::ArtificialEventSource::pollEvent(ev); } - /** * @brief Map a key press event. * If the active keymap contains a Action mapped to the given key, then * the Action's events are pushed into the EventManager's event queue. * @param key key that was pressed * @param keyDown true for key down, false for key up - * @return true if key was mapped + * @return mapped events */ - bool mapKey(const KeyState& key, bool keyDown); + List<Event> mapKey(const KeyState& key, bool keyDown); /** * @brief Map a key down event. * @see mapKey */ - bool mapKeyDown(const KeyState& key); + List<Event> mapKeyDown(const KeyState& key); /** * @brief Map a key up event. * @see mapKey */ - bool mapKeyUp(const KeyState& key); - - /** - * Map non-key incoming events - * @param ev incoming event - */ - bool mapEvent(const Common::Event &ev); + List<Event> mapKeyUp(const KeyState& key); /** * Enable/disable the keymapper @@ -195,7 +188,7 @@ private: void pushKeymap(Keymap *newMap, bool transparent, bool global); Action *getAction(const KeyState& key); - void executeAction(const Action *act, bool keyDown); + List<Event> executeAction(const Action *act, bool keyDown); EventManager *_eventMan; |