summaryrefslogtreecommitdiff
path: root/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'services/inputflinger/reader/mapper/KeyboardInputMapper.cpp')
-rw-r--r--services/inputflinger/reader/mapper/KeyboardInputMapper.cpp50
1 files changed, 12 insertions, 38 deletions
diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp
index 104d087387..e0092210a0 100644
--- a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp
@@ -14,9 +14,7 @@
* limitations under the License.
*/
-// clang-format off
#include "../Macros.h"
-// clang-format on
#include "KeyboardInputMapper.h"
@@ -132,13 +130,15 @@ void KeyboardInputMapper::dump(std::string& dump) {
std::optional<DisplayViewport> KeyboardInputMapper::findViewport(
nsecs_t when, const InputReaderConfiguration* config) {
- if (getDeviceContext().getAssociatedViewport()) {
+ const std::optional<uint8_t> displayPort = getDeviceContext().getAssociatedDisplayPort();
+ if (displayPort) {
+ // Find the viewport that contains the same port
return getDeviceContext().getAssociatedViewport();
}
// No associated display defined, try to find default display if orientationAware.
if (mParameters.orientationAware) {
- return config->getDisplayViewportByType(ViewportType::INTERNAL);
+ return config->getDisplayViewportByType(ViewportType::VIEWPORT_INTERNAL);
}
return std::nullopt;
@@ -214,8 +214,7 @@ void KeyboardInputMapper::process(const RawEvent* rawEvent) {
mCurrentHidUsage = 0;
if (isKeyboardOrGamepadKey(scanCode)) {
- processKey(rawEvent->when, rawEvent->readTime, rawEvent->value != 0, scanCode,
- usageCode);
+ processKey(rawEvent->when, rawEvent->value != 0, scanCode, usageCode);
}
break;
}
@@ -268,8 +267,7 @@ bool KeyboardInputMapper::isMediaKey(int32_t keyCode) {
return false;
}
-void KeyboardInputMapper::processKey(nsecs_t when, nsecs_t readTime, bool down, int32_t scanCode,
- int32_t usageCode) {
+void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode, int32_t usageCode) {
int32_t keyCode;
int32_t keyMetaState;
uint32_t policyFlags;
@@ -299,7 +297,7 @@ void KeyboardInputMapper::processKey(nsecs_t when, nsecs_t readTime, bool down,
return;
}
if (policyFlags & POLICY_FLAG_GESTURE) {
- getDeviceContext().cancelTouch(when, readTime);
+ getDeviceContext().cancelTouch(when);
}
KeyDown keyDown;
@@ -350,9 +348,8 @@ void KeyboardInputMapper::processKey(nsecs_t when, nsecs_t readTime, bool down,
policyFlags |= POLICY_FLAG_DISABLE_KEY_REPEAT;
}
- NotifyKeyArgs args(getContext()->getNextId(), when, readTime, getDeviceId(), mSource,
- getDisplayId(), policyFlags,
- down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP,
+ NotifyKeyArgs args(getContext()->getNextId(), when, getDeviceId(), mSource, getDisplayId(),
+ policyFlags, down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP,
AKEY_EVENT_FLAG_FROM_SYSTEM, keyCode, scanCode, keyMetaState, downTime);
getListener()->notifyKey(&args);
}
@@ -391,14 +388,11 @@ void KeyboardInputMapper::updateMetaState(int32_t keyCode) {
bool KeyboardInputMapper::updateMetaStateIfNeeded(int32_t keyCode, bool down) {
int32_t oldMetaState = mMetaState;
int32_t newMetaState = android::updateMetaState(keyCode, down, oldMetaState);
- int32_t metaStateChanged = oldMetaState ^ newMetaState;
+ bool metaStateChanged = oldMetaState != newMetaState;
if (metaStateChanged) {
mMetaState = newMetaState;
- constexpr int32_t allLedMetaState =
- AMETA_CAPS_LOCK_ON | AMETA_NUM_LOCK_ON | AMETA_SCROLL_LOCK_ON;
- if ((metaStateChanged & allLedMetaState) != 0) {
- getContext()->updateLedMetaState(newMetaState & allLedMetaState);
- }
+ updateLedState(false);
+
getContext()->updateGlobalMetaState();
}
@@ -419,26 +413,6 @@ void KeyboardInputMapper::initializeLedState(LedState& ledState, int32_t led) {
}
void KeyboardInputMapper::updateLedState(bool reset) {
- mMetaState |= getContext()->getLedMetaState();
-
- constexpr int32_t META_NUM = 3;
- const std::array<int32_t, META_NUM> keyCodes = {AKEYCODE_CAPS_LOCK, AKEYCODE_NUM_LOCK,
- AKEYCODE_SCROLL_LOCK};
- const std::array<int32_t, META_NUM> metaCodes = {AMETA_CAPS_LOCK_ON, AMETA_NUM_LOCK_ON,
- AMETA_SCROLL_LOCK_ON};
- std::array<uint8_t, META_NUM> flags = {0, 0, 0};
- bool hasKeyLayout =
- getDeviceContext().markSupportedKeyCodes(META_NUM, keyCodes.data(), flags.data());
- // If the device doesn't have the physical meta key it shouldn't generate the corresponding
- // meta state.
- if (hasKeyLayout) {
- for (int i = 0; i < META_NUM; i++) {
- if (!flags[i]) {
- mMetaState &= ~metaCodes[i];
- }
- }
- }
-
updateLedStateForModifier(mCapsLockLedState, ALED_CAPS_LOCK, AMETA_CAPS_LOCK_ON, reset);
updateLedStateForModifier(mNumLockLedState, ALED_NUM_LOCK, AMETA_NUM_LOCK_ON, reset);
updateLedStateForModifier(mScrollLockLedState, ALED_SCROLL_LOCK, AMETA_SCROLL_LOCK_ON, reset);