aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/events/default/default-events.cpp20
-rw-r--r--backends/events/default/default-events.h21
-rw-r--r--backends/keymapper/keymapper.cpp11
-rw-r--r--backends/keymapper/keymapper.h6
4 files changed, 18 insertions, 40 deletions
diff --git a/backends/events/default/default-events.cpp b/backends/events/default/default-events.cpp
index cffc210aaf..8cbc44d052 100644
--- a/backends/events/default/default-events.cpp
+++ b/backends/events/default/default-events.cpp
@@ -206,14 +206,13 @@ DefaultEventManager::DefaultEventManager(Common::EventSource *boss) :
#endif
#ifdef ENABLE_KEYMAPPER
_keymapper = new Common::Keymapper(this);
+ // EventDispatcher will automatically free the keymapper
+ g_eventDispatcher.registerMapper(_keymapper);
_remap = false;
#endif
}
DefaultEventManager::~DefaultEventManager() {
-#ifdef ENABLE_KEYMAPPER
- delete _keymapper;
-#endif
#ifdef ENABLE_VKEYBD
delete _vk;
#endif
@@ -388,21 +387,6 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
if (!_eventQueue.empty()) {
event = _eventQueue.pop();
result = true;
-
-#ifdef ENABLE_KEYMAPPER
- if (result) {
- // send key press events to keymapper
- if (event.type == Common::EVENT_KEYDOWN) {
- if (_keymapper->mapKeyDown(event.kbd)) {
- result = false;
- }
- } else if (event.type == Common::EVENT_KEYUP) {
- if (_keymapper->mapKeyUp(event.kbd)) {
- result = false;
- }
- }
- }
-#endif
}
if (_recordMode != kPassthrough) {
diff --git a/backends/events/default/default-events.h b/backends/events/default/default-events.h
index b8f47385a8..2f4f347e34 100644
--- a/backends/events/default/default-events.h
+++ b/backends/events/default/default-events.h
@@ -51,26 +51,7 @@ class DefaultEventManager : public Common::EventManager, Common::EventObserver {
bool _remap;
#endif
- // TODO: Maybe move this to common/events.h, when other code uses something similar
- class ArtificialEventSource : public Common::EventSource {
- private:
- Common::Queue<Common::Event> _artificialEventQueue;
- public:
- void addEvent(const Common::Event &ev) {
- _artificialEventQueue.push(ev);
- }
-
- bool pollEvent(Common::Event &ev) {
- if (!_artificialEventQueue.empty()) {
- ev = _artificialEventQueue.pop();
- return true;
- } else {
- return false;
- }
- }
-
- bool allowMapping() const { return false; }
- } _artificialEventSource;
+ Common::ArtificialEventSource _artificialEventSource;
Common::Queue<Common::Event> _eventQueue;
bool notifyEvent(const Common::Event &ev) {
diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp
index 7d888828c6..c0c454168c 100644
--- a/backends/keymapper/keymapper.cpp
+++ b/backends/keymapper/keymapper.cpp
@@ -168,6 +168,15 @@ void Keymapper::popKeymap() {
_activeMaps.pop();
}
+bool Keymapper::notifyEvent(const Common::Event &ev) {
+ if (ev.type == Common::EVENT_KEYDOWN)
+ return mapKeyDown(ev.kbd);
+ else if (ev.type == Common::EVENT_KEYUP)
+ return mapKeyUp(ev.kbd);
+ else
+ return false;
+}
+
bool Keymapper::mapKeyDown(const KeyState& key) {
return mapKey(key, true);
}
@@ -255,7 +264,7 @@ void Keymapper::executeAction(const Action *action, bool keyDown) {
}
evt.mouse = _eventMan->getMousePos();
- _eventMan->pushEvent(evt);
+ addEvent(evt);
}
}
diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h
index c82f64b0ed..f492882ca2 100644
--- a/backends/keymapper/keymapper.h
+++ b/backends/keymapper/keymapper.h
@@ -39,7 +39,7 @@
namespace Common {
-class Keymapper {
+class Keymapper : public Common::EventMapper, private Common::ArtificialEventSource {
public:
struct MapRecord {
@@ -134,6 +134,10 @@ public:
*/
void popKeymap();
+ // 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