aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/keymapper/keymapper.cpp45
-rw-r--r--backends/keymapper/keymapper.h25
-rw-r--r--common/EventDispatcher.cpp22
-rw-r--r--common/events.h22
4 files changed, 51 insertions, 63 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;
diff --git a/common/EventDispatcher.cpp b/common/EventDispatcher.cpp
index 6f36ee5f0f..4c7286bbb5 100644
--- a/common/EventDispatcher.cpp
+++ b/common/EventDispatcher.cpp
@@ -21,7 +21,6 @@
*/
#include "common/events.h"
-#include "common/textconsole.h"
namespace Common {
@@ -49,26 +48,15 @@ void EventDispatcher::dispatch() {
dispatchPoll();
for (List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) {
- const bool allowMapping = i->source->allowMapping();
-
while (i->source->pollEvent(event)) {
// We only try to process the events via the setup event mapper, when
// we have a setup mapper and when the event source allows mapping.
assert(_mapper);
- if (allowMapping) {
- bool mapped = _mapper->notifyEvent(event);
- // EventMappers must map all events
- if (!mapped)
- error("Event [%u] was not mapped by the EventMapper!", event.type);
- // We allow the event mapper to create multiple events, when
- // eating an event.
- while (_mapper->pollEvent(event))
- dispatchEvent(event);
-
- // Try getting another event from the current EventSource.
- continue;
- } else {
- dispatchEvent(Event(event));
+ List<Event> mappedEvents = _mapper->mapEvent(event, i->source);
+
+ for (List<Event>::iterator j = mappedEvents.begin(); j != mappedEvents.end(); ++j) {
+ const Event mappedEvent = *j;
+ dispatchEvent(mappedEvent);
}
}
}
diff --git a/common/events.h b/common/events.h
index 48854b2abf..fec4d37d34 100644
--- a/common/events.h
+++ b/common/events.h
@@ -213,15 +213,25 @@ public:
*
* An example for this is the Keymapper.
*/
-class EventMapper : public EventSource, public EventObserver {
+class EventMapper {
public:
- /** For event mappers resulting events should never be mapped */
- bool allowMapping() const { return false; }
+ virtual ~EventMapper() {}
+
+ /**
+ * Map an incoming event to one or more action events
+ */
+ virtual List<Event> mapEvent(const Event &ev, EventSource *source) = 0;
};
-class DefaultEventMapper : public EventMapper, private ArtificialEventSource {
- bool notifyEvent(const Event &ev) { ArtificialEventSource::addEvent(Event(ev)); return true; }
- bool pollEvent(Event &ev) { return ArtificialEventSource::pollEvent(ev); }
+class DefaultEventMapper : public EventMapper {
+public:
+ // EventMapper interface
+ virtual List<Event> mapEvent(const Event &ev, EventSource *source) {
+ List<Event> events;
+ // just pass it through
+ events.push_back(ev);
+ return events;
+ }
};
/**