Caps Lock toggle with Meta + Alt (1/2)
Caps Lock implementation in frameworks/native
Bug: 27482276
Change-Id: I848f660f1dd8d20e49b27f141f612387c7e30c47
diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp
index 8556c23..374a5de 100644
--- a/services/inputflinger/InputReader.cpp
+++ b/services/inputflinger/InputReader.cpp
@@ -697,6 +697,21 @@
return result;
}
+void InputReader::toggleCapsLockState(int32_t deviceId) {
+ ssize_t deviceIndex = mDevices.indexOfKey(deviceId);
+ if (deviceIndex < 0) {
+ ALOGW("Ignoring toggleCapsLock for unknown deviceId %" PRId32 ".", deviceId);
+ return;
+ }
+
+ InputDevice* device = mDevices.valueAt(deviceIndex);
+ if (device->isIgnored()) {
+ return;
+ }
+
+ device->updateMetaState(AKEYCODE_CAPS_LOCK);
+}
+
bool InputReader::hasKeys(int32_t deviceId, uint32_t sourceMask,
size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) {
AutoMutex _l(mLock);
@@ -1172,6 +1187,13 @@
return result;
}
+void InputDevice::updateMetaState(int32_t keyCode) {
+ size_t numMappers = mMappers.size();
+ for (size_t i = 0; i < numMappers; i++) {
+ mMappers[i]->updateMetaState(keyCode);
+ }
+}
+
void InputDevice::fadePointer() {
size_t numMappers = mMappers.size();
for (size_t i = 0; i < numMappers; i++) {
@@ -1880,6 +1902,9 @@
return 0;
}
+void InputMapper::updateMetaState(int32_t keyCode) {
+}
+
void InputMapper::updateExternalStylusState(const StylusState& state) {
}
@@ -2265,18 +2290,12 @@
}
}
- int32_t oldMetaState = mMetaState;
- int32_t newMetaState = updateMetaState(keyCode, down, oldMetaState);
- bool metaStateChanged = oldMetaState != newMetaState;
- if (metaStateChanged) {
- mMetaState = newMetaState;
- updateLedState(false);
-
+ if (updateMetaStateIfNeeded(keyCode, down)) {
// 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;
+ keyMetaState = mMetaState;
}
nsecs_t downTime = mDownTime;
@@ -2294,10 +2313,6 @@
policyFlags |= POLICY_FLAG_DISABLE_KEY_REPEAT;
}
- if (metaStateChanged) {
- getContext()->updateGlobalMetaState();
- }
-
if (down && !isMetaKey(keyCode)) {
getContext()->fadePointer();
}
@@ -2335,6 +2350,24 @@
return mMetaState;
}
+void KeyboardInputMapper::updateMetaState(int32_t keyCode) {
+ updateMetaStateIfNeeded(keyCode, false);
+}
+
+bool KeyboardInputMapper::updateMetaStateIfNeeded(int32_t keyCode, bool down) {
+ int32_t oldMetaState = mMetaState;
+ int32_t newMetaState = android::updateMetaState(keyCode, down, oldMetaState);
+ bool metaStateChanged = oldMetaState != newMetaState;
+ if (metaStateChanged) {
+ mMetaState = newMetaState;
+ updateLedState(false);
+
+ getContext()->updateGlobalMetaState();
+ }
+
+ return metaStateChanged;
+}
+
void KeyboardInputMapper::resetLedState() {
initializeLedState(mCapsLockLedState, ALED_CAPS_LOCK);
initializeLedState(mNumLockLedState, ALED_NUM_LOCK);