From 2d52f129bb1312d1914c00a8204aded9d872bb1e Mon Sep 17 00:00:00 2001 From: Stephen Kennedy Date: Fri, 22 Aug 2008 10:36:12 +0000 Subject: Fix for key repeat bug svn-id: r34094 --- backends/keymapper/keymapper.cpp | 48 ++++++++++++++++++++++++++++------------ backends/keymapper/keymapper.h | 8 +++++-- 2 files changed, 40 insertions(+), 16 deletions(-) (limited to 'backends') diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp index d453a875cc..9f4b42658b 100644 --- a/backends/keymapper/keymapper.cpp +++ b/backends/keymapper/keymapper.cpp @@ -127,6 +127,12 @@ bool Keymapper::pushKeymap(const String& name, bool inherit) { } void Keymapper::pushKeymap(Keymap *newMap, bool inherit, bool global) { + List::iterator it; + for (it = _keysDown.begin(); it != _keysDown.end(); ++it) { + Action *action = getAction(*it); + if (action) executeAction(action, false); + } + _keysDown.clear(); MapRecord mr = {newMap, inherit, global}; _activeMaps.push(mr); } @@ -144,54 +150,68 @@ bool Keymapper::mapKeyUp(const KeyState& key) { return mapKey(key, false); } -bool Keymapper::mapKey(const KeyState& key, bool isKeyDown) { +bool Keymapper::mapKey(const KeyState& key, bool keyDown) { if (!_enabled) return false; if (_activeMaps.empty()) return false; + Action *action = getAction(key); + if (!action) return false; + + if (keyDown) + _keysDown.push_back(key); + else + _keysDown.remove(key); + + executeAction(action, keyDown); + return true; +} + +Action *Keymapper::getAction(const KeyState& key) { Action *action = 0; - for (int i = _activeMaps.size() - 1; !action && i >= 0; --i) { + for (int i = _activeMaps.size() - 1; i >= 0; --i) { MapRecord mr = _activeMaps[i]; action = mr.keymap->getMappedAction(key); - if (mr.inherit == false) break; + if (action || mr.inherit == false) break; } - if (!action) return false; + return action; +} +void Keymapper::executeAction(const Action *action, bool keyDown) { List::iterator it; for (it = action->events.begin(); it != action->events.end(); ++it) { Event evt = *it; switch (evt.type) { case EVENT_KEYDOWN: - if (!isKeyDown) evt.type = EVENT_KEYUP; + if (!keyDown) evt.type = EVENT_KEYUP; break; case EVENT_KEYUP: - if (isKeyDown) evt.type = EVENT_KEYDOWN; + if (keyDown) evt.type = EVENT_KEYDOWN; break; case EVENT_LBUTTONDOWN: - if (!isKeyDown) evt.type = EVENT_LBUTTONUP; + if (!keyDown) evt.type = EVENT_LBUTTONUP; break; case EVENT_LBUTTONUP: - if (isKeyDown) evt.type = EVENT_LBUTTONDOWN; + if (keyDown) evt.type = EVENT_LBUTTONDOWN; break; case EVENT_RBUTTONDOWN: - if (!isKeyDown) evt.type = EVENT_RBUTTONUP; + if (!keyDown) evt.type = EVENT_RBUTTONUP; break; case EVENT_RBUTTONUP: - if (isKeyDown) evt.type = EVENT_RBUTTONDOWN; + if (keyDown) evt.type = EVENT_RBUTTONDOWN; break; case EVENT_MBUTTONDOWN: - if (!isKeyDown) evt.type = EVENT_MBUTTONUP; + if (!keyDown) evt.type = EVENT_MBUTTONUP; break; case EVENT_MBUTTONUP: - if (isKeyDown) evt.type = EVENT_MBUTTONDOWN; + if (keyDown) evt.type = EVENT_MBUTTONDOWN; break; default: // don't deliver other events on key up - if (!isKeyDown) continue; + if (!keyDown) continue; } evt.mouse = _eventMan->getMousePos(); _eventMan->pushEvent(evt); } - return true; } const HardwareKey *Keymapper::getHardwareKey(const KeyState& key) { diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h index 78ab2d2203..d6ba89288d 100644 --- a/backends/keymapper/keymapper.h +++ b/backends/keymapper/keymapper.h @@ -141,10 +141,10 @@ public: * 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 isKeyDown true for key down, false for key up + * @param keyDown true for key down, false for key up * @return true if key was mapped */ - bool mapKey(const KeyState& key, bool isKeyDown); + bool mapKey(const KeyState& key, bool keyDown); /** * @brief Map a key down event. @@ -183,6 +183,9 @@ private: HardwareKeySet *_hardwareKeys; void pushKeymap(Keymap *newMap, bool inherit, bool global); + + Action *getAction(const KeyState& key); + void executeAction(const Action *act, bool keyDown); typedef List::iterator Iterator; @@ -191,6 +194,7 @@ private: bool _enabled; Stack _activeMaps; + List _keysDown; }; -- cgit v1.2.3