am 278b525d
: Add system accelerators for BACK and HOME.
* commit '278b525d25b852554015ec4f92862f9297b502fd': Add system accelerators for BACK and HOME.
This commit is contained in:
commit
9f6c3a8e01
@ -2366,9 +2366,36 @@ void InputDispatcher::notifyKey(const NotifyKeyArgs* args) {
|
||||
|
||||
policyFlags |= POLICY_FLAG_TRUSTED;
|
||||
|
||||
int32_t keyCode = args->keyCode;
|
||||
if (metaState & AMETA_META_ON && args->action == AKEY_EVENT_ACTION_DOWN) {
|
||||
int32_t newKeyCode = AKEYCODE_UNKNOWN;
|
||||
if (keyCode == AKEYCODE_DEL) {
|
||||
newKeyCode = AKEYCODE_BACK;
|
||||
} else if (keyCode == AKEYCODE_ENTER) {
|
||||
newKeyCode = AKEYCODE_HOME;
|
||||
}
|
||||
if (newKeyCode != AKEYCODE_UNKNOWN) {
|
||||
AutoMutex _l(mLock);
|
||||
struct KeyReplacement replacement = {keyCode, args->deviceId};
|
||||
mReplacedKeys.add(replacement, newKeyCode);
|
||||
keyCode = newKeyCode;
|
||||
metaState &= ~AMETA_META_ON;
|
||||
}
|
||||
} else if (args->action == AKEY_EVENT_ACTION_UP) {
|
||||
// In order to maintain a consistent stream of up and down events, check to see if the key
|
||||
// going up is one we've replaced in a down event and haven't yet replaced in an up event,
|
||||
// even if the modifier was released between the down and the up events.
|
||||
AutoMutex _l(mLock);
|
||||
struct KeyReplacement replacement = {keyCode, args->deviceId};
|
||||
ssize_t index = mReplacedKeys.indexOfKey(replacement);
|
||||
keyCode = mReplacedKeys.valueAt(index);
|
||||
mReplacedKeys.removeItemsAt(index);
|
||||
metaState &= ~AMETA_META_ON;
|
||||
}
|
||||
|
||||
KeyEvent event;
|
||||
event.initialize(args->deviceId, args->source, args->action,
|
||||
flags, args->keyCode, args->scanCode, metaState, 0,
|
||||
flags, keyCode, args->scanCode, metaState, 0,
|
||||
args->downTime, args->eventTime);
|
||||
|
||||
mPolicy->interceptKeyBeforeQueueing(&event, /*byref*/ policyFlags);
|
||||
@ -2391,7 +2418,7 @@ void InputDispatcher::notifyKey(const NotifyKeyArgs* args) {
|
||||
int32_t repeatCount = 0;
|
||||
KeyEntry* newEntry = new KeyEntry(args->eventTime,
|
||||
args->deviceId, args->source, policyFlags,
|
||||
args->action, flags, args->keyCode, args->scanCode,
|
||||
args->action, flags, keyCode, args->scanCode,
|
||||
metaState, repeatCount, args->downTime);
|
||||
|
||||
needWake = enqueueInboundEventLocked(newEntry);
|
||||
@ -3050,6 +3077,7 @@ void InputDispatcher::resetAndDropEverythingLocked(const char* reason) {
|
||||
|
||||
mTouchStatesByDisplay.clear();
|
||||
mLastHoverWindowHandle.clear();
|
||||
mReplacedKeys.clear();
|
||||
}
|
||||
|
||||
void InputDispatcher::logDispatchStateLocked() {
|
||||
@ -3188,6 +3216,18 @@ void InputDispatcher::dumpDispatchStateLocked(String8& dump) {
|
||||
dump.append(INDENT "InboundQueue: <empty>\n");
|
||||
}
|
||||
|
||||
if (!mReplacedKeys.isEmpty()) {
|
||||
dump.append(INDENT "ReplacedKeys:\n");
|
||||
for (size_t i = 0; i < mReplacedKeys.size(); i++) {
|
||||
const KeyReplacement& replacement = mReplacedKeys.keyAt(i);
|
||||
int32_t newKeyCode = mReplacedKeys.valueAt(i);
|
||||
dump.appendFormat(INDENT2 "%zu: originalKeyCode=%d, deviceId=%d, newKeyCode=%d\n",
|
||||
i, replacement.keyCode, replacement.deviceId, newKeyCode);
|
||||
}
|
||||
} else {
|
||||
dump.append(INDENT "ReplacedKeys: <empty>\n");
|
||||
}
|
||||
|
||||
if (!mConnectionsByFd.isEmpty()) {
|
||||
dump.append(INDENT "Connections:\n");
|
||||
for (size_t i = 0; i < mConnectionsByFd.size(); i++) {
|
||||
|
@ -904,6 +904,20 @@ private:
|
||||
void resetKeyRepeatLocked();
|
||||
KeyEntry* synthesizeKeyRepeatLocked(nsecs_t currentTime);
|
||||
|
||||
// Key replacement tracking
|
||||
struct KeyReplacement {
|
||||
int32_t keyCode;
|
||||
int32_t deviceId;
|
||||
bool operator==(const KeyReplacement& rhs) const {
|
||||
return keyCode == rhs.keyCode && deviceId == rhs.deviceId;
|
||||
}
|
||||
bool operator<(const KeyReplacement& rhs) const {
|
||||
return keyCode != rhs.keyCode ? keyCode < rhs.keyCode : deviceId < rhs.deviceId;
|
||||
}
|
||||
};
|
||||
// Maps the key code replaced, device id tuple to the key code it was replaced with
|
||||
KeyedVector<KeyReplacement, int32_t> mReplacedKeys;
|
||||
|
||||
// Deferred command processing.
|
||||
bool haveCommandsLocked() const;
|
||||
bool runCommandsLockedInterruptible();
|
||||
|
Loading…
Reference in New Issue
Block a user