From c0a215282d12872cf32fb24f9067216c0f869b96 Mon Sep 17 00:00:00 2001 From: Tarek Soliman Date: Thu, 1 Mar 2012 06:29:44 -0600 Subject: KEYMAPPER: Add delays for *UP events coming from non-keys Delayed entries are in a queue where each entry stores how many milliseconds should pass based on the last entry. --- backends/keymapper/keymapper.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'backends/keymapper') diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp index 99bcb44179..dcb021f2d8 100644 --- a/backends/keymapper/keymapper.cpp +++ b/backends/keymapper/keymapper.cpp @@ -25,9 +25,14 @@ #ifdef ENABLE_KEYMAPPER #include "common/config-manager.h" +#include "common/system.h" namespace Common { +// These magic numbers are provided by fuzzie and WebOS +static const uint32 kDelayKeyboardEventMillis = 250; +static const uint32 kDelayMouseEventMillis = 50; + void Keymapper::Domain::addKeymap(Keymap *map) { iterator it = find(map->getName()); @@ -281,9 +286,9 @@ Action *Keymapper::getAction(const KeyState& key) { List Keymapper::executeAction(const Action *action, IncomingEventType incomingType) { List mappedEvents; List::const_iterator it; - + Event evt; for (it = action->events.begin(); it != action->events.end(); ++it) { - Event evt = Event(*it); + evt = Event(*it); EventType convertedType = convertDownToUp(evt.type); // hardware keys need to send up instead when they are up @@ -294,15 +299,23 @@ List Keymapper::executeAction(const Action *action, IncomingEventType inc } evt.mouse = _eventMan->getMousePos(); - mappedEvents.push_back(evt); + + // Check if the event is coming from a non-key hardware event + // that is mapped to a key event + if (incomingType == kIncomingNonKey && convertedType != EVENT_INVALID) + // WORKAROUND: Delay the down events coming from non-key hardware events + // with a zero delay. This is to prevent DOWN1 DOWN2 UP1 UP2. + addDelayedEvent(0, evt); + else + mappedEvents.push_back(evt); // non-keys need to send up as well - // TODO: implement a way to add a delay - if (incomingType == kIncomingNonKey) { - if (convertedType == EVENT_INVALID) - continue; // don't send any non-down-converted events on up they were already sent on down + if (incomingType == kIncomingNonKey && convertedType != EVENT_INVALID) { + // WORKAROUND: Delay the up events coming from non-key hardware events + // This is for engines that run scripts that check on key being down evt.type = convertedType; - mappedEvents.push_back(evt); + const uint32 delay = (convertedType == EVENT_KEYUP ? kDelayKeyboardEventMillis : kDelayMouseEventMillis); + addDelayedEvent(delay, evt); } } return mappedEvents; -- cgit v1.2.3