diff options
Diffstat (limited to 'services/inputflinger/InputReader.cpp')
-rw-r--r-- | services/inputflinger/InputReader.cpp | 66 |
1 files changed, 57 insertions, 9 deletions
diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp index b2cbfe8..53ff155 100644 --- a/services/inputflinger/InputReader.cpp +++ b/services/inputflinger/InputReader.cpp @@ -116,9 +116,9 @@ static inline const char* toString(bool value) { } static int32_t rotateValueUsingRotationMap(int32_t value, int32_t orientation, - const int32_t map[][4], size_t mapSize) { + const int32_t map[][4], size_t mapSize, int32_t rotationMapOffset) { if (orientation != DISPLAY_ORIENTATION_0) { - for (size_t i = 0; i < mapSize; i++) { + for (size_t i = rotationMapOffset; i < mapSize; i++) { if (value == map[i][0]) { return map[i][orientation]; } @@ -130,6 +130,16 @@ static int32_t rotateValueUsingRotationMap(int32_t value, int32_t orientation, static const int32_t keyCodeRotationMap[][4] = { // key codes enumerated counter-clockwise with the original (unrotated) key first // no rotation, 90 degree rotation, 180 degree rotation, 270 degree rotation + + // volume keys - tablet + { AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_DOWN }, + { AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_UP }, + + // volume keys - phone or hybrid + { AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_UP }, + { AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_DOWN }, + + // dpad keys - common { AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT }, { AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN }, { AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT }, @@ -138,9 +148,9 @@ static const int32_t keyCodeRotationMap[][4] = { static const size_t keyCodeRotationMapSize = sizeof(keyCodeRotationMap) / sizeof(keyCodeRotationMap[0]); -static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation) { +static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation, int32_t rotationMapOffset) { return rotateValueUsingRotationMap(keyCode, orientation, - keyCodeRotationMap, keyCodeRotationMapSize); + keyCodeRotationMap, keyCodeRotationMapSize, rotationMapOffset); } static void rotateDelta(int32_t orientation, float* deltaX, float* deltaY) { @@ -2131,10 +2141,16 @@ void KeyboardInputMapper::configure(nsecs_t when, mOrientation = DISPLAY_ORIENTATION_0; } } + if (!changes || (changes & InputReaderConfiguration::CHANGE_VOLUME_KEYS_ROTATION)) { + // mode 0 (disabled) ~ offset 4 + // mode 1 (phone) ~ offset 2 + // mode 2 (tablet) ~ offset 0 + mRotationMapOffset = 4 - 2 * config->volumeKeysRotationMode; + } } void KeyboardInputMapper::configureParameters() { - mParameters.orientationAware = false; + mParameters.orientationAware = !getDevice()->isExternal(); getDevice()->getConfiguration().tryGetProperty(String8("keyboard.orientationAware"), mParameters.orientationAware); @@ -2218,7 +2234,7 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode, if (down) { // Rotate key codes according to orientation if needed. if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) { - keyCode = rotateKeyCode(keyCode, mOrientation); + keyCode = rotateKeyCode(keyCode, mOrientation, mRotationMapOffset); } // Add key down. @@ -2934,7 +2950,8 @@ void TouchInputMapper::configure(nsecs_t when, if (!changes || (changes & (InputReaderConfiguration::CHANGE_DISPLAY_INFO | InputReaderConfiguration::CHANGE_POINTER_GESTURE_ENABLEMENT | InputReaderConfiguration::CHANGE_SHOW_TOUCHES - | InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE))) { + | InputReaderConfiguration::CHANGE_EXTERNAL_STYLUS_PRESENCE + | InputReaderConfiguration::CHANGE_STYLUS_ICON_ENABLED))) { // Configure device sources, surface dimensions, orientation and // scaling factors. configureSurface(when, &resetNeeded); @@ -3006,6 +3023,8 @@ void TouchInputMapper::configureParameters() { mParameters.deviceType = Parameters::DEVICE_TYPE_TOUCH_NAVIGATION; } else if (deviceTypeString == "pointer") { mParameters.deviceType = Parameters::DEVICE_TYPE_POINTER; + } else if (deviceTypeString == "gesture") { + mParameters.deviceType = Parameters::DEVICE_TYPE_GESTURE_SENSOR; } else if (deviceTypeString != "default") { ALOGW("Invalid value for touch.deviceType: '%s'", deviceTypeString.string()); } @@ -3061,6 +3080,9 @@ void TouchInputMapper::dumpParameters(String8& dump) { case Parameters::DEVICE_TYPE_POINTER: dump.append(INDENT4 "DeviceType: pointer\n"); break; + case Parameters::DEVICE_TYPE_GESTURE_SENSOR: + dump.append(INDENT4 "DeviceType: gesture\n"); + break; default: ALOG_ASSERT(false); } @@ -3123,6 +3145,9 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) { } else if (mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_NAVIGATION) { mSource = AINPUT_SOURCE_TOUCH_NAVIGATION; mDeviceMode = DEVICE_MODE_NAVIGATION; + } else if (mParameters.deviceType == Parameters::DEVICE_TYPE_GESTURE_SENSOR) { + mSource = AINPUT_SOURCE_GESTURE_SENSOR; + mDeviceMode = DEVICE_MODE_UNSCALED; } else { mSource = AINPUT_SOURCE_TOUCHPAD; mDeviceMode = DEVICE_MODE_UNSCALED; @@ -4858,7 +4883,7 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag && (mPointerGesture.lastGestureMode == PointerGesture::SWIPE || mPointerGesture.lastGestureMode == PointerGesture::FREEFORM)) { // Remind the user of where the pointer is after finishing a gesture with spots. - mPointerController->unfade(PointerControllerInterface::TRANSITION_GRADUAL); + unfadePointer(PointerControllerInterface::TRANSITION_GRADUAL); } break; case PointerGesture::TAP: @@ -5847,6 +5872,7 @@ void TouchInputMapper::dispatchPointerStylus(nsecs_t when, uint32_t policyFlags) mPointerSimple.currentProperties.id = 0; mPointerSimple.currentProperties.toolType = mCurrentCookedState.cookedPointerData.pointerProperties[index].toolType; + mLastStylusTime = when; } else { down = false; hovering = false; @@ -5923,11 +5949,16 @@ void TouchInputMapper::dispatchPointerSimple(nsecs_t when, uint32_t policyFlags, mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_POINTER); mPointerController->clearSpots(); mPointerController->setButtonState(mCurrentRawState.buttonState); - mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE); + unfadePointer(PointerControllerInterface::TRANSITION_IMMEDIATE); } else if (!down && !hovering && (mPointerSimple.down || mPointerSimple.hovering)) { mPointerController->fade(PointerControllerInterface::TRANSITION_GRADUAL); } } + + if (rejectPalm(when)) { // stylus is currently active + mPointerSimple.reset(); + return; + } if (mPointerSimple.down && !down) { mPointerSimple.down = false; @@ -6049,6 +6080,9 @@ void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32 const PointerProperties* properties, const PointerCoords* coords, const uint32_t* idToIndex, BitSet32 idBits, int32_t changedId, float xPrecision, float yPrecision, nsecs_t downTime) { + + if (rejectPalm(when)) return; + PointerCoords pointerCoords[MAX_POINTERS]; PointerProperties pointerProperties[MAX_POINTERS]; uint32_t pointerCount = 0; @@ -6122,6 +6156,20 @@ void TouchInputMapper::fadePointer() { } } +void TouchInputMapper::unfadePointer(PointerControllerInterface::Transition transition) { + if (mPointerController != NULL && + !(mPointerUsage == POINTER_USAGE_STYLUS && !mConfig.stylusIconEnabled)) { + mPointerController->unfade(transition); + } +} + +nsecs_t TouchInputMapper::mLastStylusTime = 0; + +bool TouchInputMapper::rejectPalm(nsecs_t when) { + return (when - mLastStylusTime < mConfig.stylusPalmRejectionTime) && + mPointerSimple.currentProperties.toolType != AMOTION_EVENT_TOOL_TYPE_STYLUS; +} + void TouchInputMapper::cancelTouch(nsecs_t when) { abortPointerUsage(when, 0 /*policyFlags*/); abortTouches(when, 0 /* policyFlags*/); |