diff options
author | Dmitry Torokhov <dtor@google.com> | 2015-09-24 13:13:55 -0700 |
---|---|---|
committer | Dmitry Torokhov <dtor@google.com> | 2015-09-29 13:27:16 -0700 |
commit | 0faaa0bd7aa5dadea7c365fbb1f186da6eb097ef (patch) | |
tree | 2dc2ff68804e4cb736dd5348d2a755e5ca8a6b71 /services/inputflinger/InputReader.cpp | |
parent | 115f93eeebf7f33b56ed090de70d6e8c733e5d88 (diff) | |
download | frameworks_native-0faaa0bd7aa5dadea7c365fbb1f186da6eb097ef.zip frameworks_native-0faaa0bd7aa5dadea7c365fbb1f186da6eb097ef.tar.gz frameworks_native-0faaa0bd7aa5dadea7c365fbb1f186da6eb097ef.tar.bz2 |
Inputflinger: hook up key event replacement processing
Add handling of "replacement" key events in InputReader and EventHub by
consulting device's character key map (if exists) for presence of
replacement key code for given get code and meta state combination,
before passing it to InputDispatcher.
This enables defining special keys, such as ESC, on keyboards lacking
enough physical keys, via combination of normal keys and modifiers, for
example AltR + 1 => ESC.
Bug: 24504154
Change-Id: I7e36104808bedcf724436c1fbb63d37c35cca8af
Diffstat (limited to 'services/inputflinger/InputReader.cpp')
-rw-r--r-- | services/inputflinger/InputReader.cpp | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index 36095bf..b2cbfe8 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -2177,13 +2177,7 @@ void KeyboardInputMapper::process(const RawEvent* rawEvent) { mCurrentHidUsage = 0; if (isKeyboardOrGamepadKey(scanCode)) { - int32_t keyCode; - uint32_t flags; - if (getEventHub()->mapKey(getDeviceId(), scanCode, usageCode, &keyCode, &flags)) { - keyCode = AKEYCODE_UNKNOWN; - flags = 0; - } - processKey(rawEvent->when, rawEvent->value != 0, keyCode, scanCode, flags); + processKey(rawEvent->when, rawEvent->value != 0, scanCode, usageCode); } break; } @@ -2208,8 +2202,18 @@ bool KeyboardInputMapper::isKeyboardOrGamepadKey(int32_t scanCode) { || (scanCode >= BTN_JOYSTICK && scanCode < BTN_DIGI); } -void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode, - int32_t scanCode, uint32_t policyFlags) { +void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode, + int32_t usageCode) { + int32_t keyCode; + int32_t keyMetaState; + uint32_t policyFlags; + + if (getEventHub()->mapKey(getDeviceId(), scanCode, usageCode, mMetaState, + &keyCode, &keyMetaState, &policyFlags)) { + keyCode = AKEYCODE_UNKNOWN; + keyMetaState = mMetaState; + policyFlags = 0; + } if (down) { // Rotate key codes according to orientation if needed. @@ -2262,6 +2266,12 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode, if (metaStateChanged) { mMetaState = newMetaState; updateLedState(false); + + // If global meta state changed send it along with the key. + // If it has not changed then we'll use what keymap gave us, + // since key replacement logic might temporarily reset a few + // meta bits for given key. + keyMetaState = newMetaState; } nsecs_t downTime = mDownTime; @@ -2289,7 +2299,7 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode, NotifyKeyArgs args(when, getDeviceId(), mSource, policyFlags, down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP, - AKEY_EVENT_FLAG_FROM_SYSTEM, keyCode, scanCode, newMetaState, downTime); + AKEY_EVENT_FLAG_FROM_SYSTEM, keyCode, scanCode, keyMetaState, downTime); getListener()->notifyKey(&args); } @@ -3543,8 +3553,10 @@ void TouchInputMapper::configureVirtualKeys() { virtualKey.scanCode = virtualKeyDefinition.scanCode; int32_t keyCode; + int32_t dummyKeyMetaState; uint32_t flags; - if (getEventHub()->mapKey(getDeviceId(), virtualKey.scanCode, 0, &keyCode, &flags)) { + if (getEventHub()->mapKey(getDeviceId(), virtualKey.scanCode, 0, 0, + &keyCode, &dummyKeyMetaState, &flags)) { ALOGW(INDENT "VirtualKey %d: could not obtain key code, ignoring", virtualKey.scanCode); mVirtualKeys.pop(); // drop the key |