summaryrefslogtreecommitdiff
path: root/services/inputflinger/InputReader.cpp
diff options
context:
space:
mode:
author Xin Li <delphij@google.com> 2017-12-06 11:52:02 -0800
committer Xin Li <delphij@google.com> 2017-12-06 14:24:50 -0800
commitd1a6d1eb81b14966a30a68b67996916ee27afb6f (patch)
treef5100ca72ea06d172b17fd11f8403549315740d8 /services/inputflinger/InputReader.cpp
parent68686bd15198f64db633a757718b918895a1ca71 (diff)
parent60175af9c8938d2362ec8a8b06543ce8c41b2338 (diff)
DO NOT MERGE: Merge Oreo MR1 into master
Exempt-From-Owner-Approval: Changes already landed internally Change-Id: I37c19d77fbf144fb30cc2a2877247a855684d4ad
Diffstat (limited to 'services/inputflinger/InputReader.cpp')
-rw-r--r--services/inputflinger/InputReader.cpp64
1 files changed, 60 insertions, 4 deletions
diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp
index cc81a298a2..d4266f6df9 100644
--- a/services/inputflinger/InputReader.cpp
+++ b/services/inputflinger/InputReader.cpp
@@ -147,7 +147,33 @@ static const int32_t keyCodeRotationMap[][4] = {
static const size_t keyCodeRotationMapSize =
sizeof(keyCodeRotationMap) / sizeof(keyCodeRotationMap[0]);
+static int32_t rotateStemKey(int32_t value, int32_t orientation,
+ const int32_t map[][2], size_t mapSize) {
+ if (orientation == DISPLAY_ORIENTATION_180) {
+ for (size_t i = 0; i < mapSize; i++) {
+ if (value == map[i][0]) {
+ return map[i][1];
+ }
+ }
+ }
+ return value;
+}
+
+// The mapping can be defined using input device configuration properties keyboard.rotated.stem_X
+static int32_t stemKeyRotationMap[][2] = {
+ // key codes enumerated with the original (unrotated) key first
+ // no rotation, 180 degree rotation
+ { AKEYCODE_STEM_PRIMARY, AKEYCODE_STEM_PRIMARY },
+ { AKEYCODE_STEM_1, AKEYCODE_STEM_1 },
+ { AKEYCODE_STEM_2, AKEYCODE_STEM_2 },
+ { AKEYCODE_STEM_3, AKEYCODE_STEM_3 },
+};
+static const size_t stemKeyRotationMapSize =
+ sizeof(stemKeyRotationMap) / sizeof(stemKeyRotationMap[0]);
+
static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation) {
+ keyCode = rotateStemKey(keyCode, orientation,
+ stemKeyRotationMap, stemKeyRotationMapSize);
return rotateValueUsingRotationMap(keyCode, orientation,
keyCodeRotationMap, keyCodeRotationMapSize);
}
@@ -231,7 +257,7 @@ bool InputReaderConfiguration::getDisplayViewport(ViewportType viewportType,
const String8* uniqueDisplayId, DisplayViewport* outViewport) const {
const DisplayViewport* viewport = NULL;
if (viewportType == ViewportType::VIEWPORT_VIRTUAL && uniqueDisplayId != NULL) {
- for (DisplayViewport currentViewport : mVirtualDisplays) {
+ for (const DisplayViewport& currentViewport : mVirtualDisplays) {
if (currentViewport.uniqueId == *uniqueDisplayId) {
viewport = &currentViewport;
break;
@@ -2260,18 +2286,36 @@ void KeyboardInputMapper::configure(nsecs_t when,
}
}
+static void mapStemKey(int32_t keyCode, const PropertyMap& config, char const *property) {
+ int32_t mapped = 0;
+ if (config.tryGetProperty(String8(property), mapped) && mapped > 0) {
+ for (size_t i = 0; i < stemKeyRotationMapSize; i++) {
+ if (stemKeyRotationMap[i][0] == keyCode) {
+ stemKeyRotationMap[i][1] = mapped;
+ return;
+ }
+ }
+ }
+}
+
void KeyboardInputMapper::configureParameters() {
mParameters.orientationAware = false;
- getDevice()->getConfiguration().tryGetProperty(String8("keyboard.orientationAware"),
+ const PropertyMap& config = getDevice()->getConfiguration();
+ config.tryGetProperty(String8("keyboard.orientationAware"),
mParameters.orientationAware);
mParameters.hasAssociatedDisplay = false;
if (mParameters.orientationAware) {
mParameters.hasAssociatedDisplay = true;
+
+ mapStemKey(AKEYCODE_STEM_PRIMARY, config, "keyboard.rotated.stem_primary");
+ mapStemKey(AKEYCODE_STEM_1, config, "keyboard.rotated.stem_1");
+ mapStemKey(AKEYCODE_STEM_2, config, "keyboard.rotated.stem_2");
+ mapStemKey(AKEYCODE_STEM_3, config, "keyboard.rotated.stem_3");
}
mParameters.handlesKeyRepeat = false;
- getDevice()->getConfiguration().tryGetProperty(String8("keyboard.handlesKeyRepeat"),
+ config.tryGetProperty(String8("keyboard.handlesKeyRepeat"),
mParameters.handlesKeyRepeat);
}
@@ -2926,7 +2970,7 @@ void CursorInputMapper::fadePointer() {
// --- RotaryEncoderInputMapper ---
RotaryEncoderInputMapper::RotaryEncoderInputMapper(InputDevice* device) :
- InputMapper(device) {
+ InputMapper(device), mOrientation(DISPLAY_ORIENTATION_0) {
mSource = AINPUT_SOURCE_ROTARY_ENCODER;
}
@@ -2968,6 +3012,14 @@ void RotaryEncoderInputMapper::configure(nsecs_t when,
if (!changes) {
mRotaryEncoderScrollAccumulator.configure(getDevice());
}
+ if (!changes || (InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
+ DisplayViewport v;
+ if (config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, NULL, &v)) {
+ mOrientation = v.orientation;
+ } else {
+ mOrientation = DISPLAY_ORIENTATION_0;
+ }
+ }
}
void RotaryEncoderInputMapper::reset(nsecs_t when) {
@@ -3005,6 +3057,10 @@ void RotaryEncoderInputMapper::sync(nsecs_t when) {
policyFlags |= POLICY_FLAG_WAKE;
}
+ if (mOrientation == DISPLAY_ORIENTATION_180) {
+ scroll = -scroll;
+ }
+
// Send motion event.
if (scrolled) {
int32_t metaState = mContext->getGlobalMetaState();