summaryrefslogtreecommitdiffstats
path: root/services/input/InputReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'services/input/InputReader.cpp')
-rw-r--r--services/input/InputReader.cpp175
1 files changed, 41 insertions, 134 deletions
diff --git a/services/input/InputReader.cpp b/services/input/InputReader.cpp
index 49cb864..c9fac81 100644
--- a/services/input/InputReader.cpp
+++ b/services/input/InputReader.cpp
@@ -120,29 +120,31 @@ static const int32_t keyCodeRotationMap[][4] = {
static const size_t keyCodeRotationMapSize =
sizeof(keyCodeRotationMap) / sizeof(keyCodeRotationMap[0]);
-int32_t rotateKeyCode(int32_t keyCode, int32_t orientation) {
+static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation) {
return rotateValueUsingRotationMap(keyCode, orientation,
keyCodeRotationMap, keyCodeRotationMapSize);
}
-static const int32_t edgeFlagRotationMap[][4] = {
- // edge flags enumerated counter-clockwise with the original (unrotated) edge flag first
- // no rotation, 90 degree rotation, 180 degree rotation, 270 degree rotation
- { AMOTION_EVENT_EDGE_FLAG_BOTTOM, AMOTION_EVENT_EDGE_FLAG_RIGHT,
- AMOTION_EVENT_EDGE_FLAG_TOP, AMOTION_EVENT_EDGE_FLAG_LEFT },
- { AMOTION_EVENT_EDGE_FLAG_RIGHT, AMOTION_EVENT_EDGE_FLAG_TOP,
- AMOTION_EVENT_EDGE_FLAG_LEFT, AMOTION_EVENT_EDGE_FLAG_BOTTOM },
- { AMOTION_EVENT_EDGE_FLAG_TOP, AMOTION_EVENT_EDGE_FLAG_LEFT,
- AMOTION_EVENT_EDGE_FLAG_BOTTOM, AMOTION_EVENT_EDGE_FLAG_RIGHT },
- { AMOTION_EVENT_EDGE_FLAG_LEFT, AMOTION_EVENT_EDGE_FLAG_BOTTOM,
- AMOTION_EVENT_EDGE_FLAG_RIGHT, AMOTION_EVENT_EDGE_FLAG_TOP },
-};
-static const size_t edgeFlagRotationMapSize =
- sizeof(edgeFlagRotationMap) / sizeof(edgeFlagRotationMap[0]);
+static void rotateDelta(int32_t orientation, float* deltaX, float* deltaY) {
+ float temp;
+ switch (orientation) {
+ case DISPLAY_ORIENTATION_90:
+ temp = *deltaX;
+ *deltaX = *deltaY;
+ *deltaY = -temp;
+ break;
-static int32_t rotateEdgeFlag(int32_t edgeFlag, int32_t orientation) {
- return rotateValueUsingRotationMap(edgeFlag, orientation,
- edgeFlagRotationMap, edgeFlagRotationMapSize);
+ case DISPLAY_ORIENTATION_180:
+ *deltaX = -*deltaX;
+ *deltaY = -*deltaY;
+ break;
+
+ case DISPLAY_ORIENTATION_270:
+ temp = *deltaX;
+ *deltaX = -*deltaY;
+ *deltaY = temp;
+ break;
+ }
}
static inline bool sourcesMatchMask(uint32_t sources, uint32_t sourceMask) {
@@ -181,25 +183,6 @@ static bool isPointerDown(int32_t buttonState) {
| AMOTION_EVENT_BUTTON_TERTIARY);
}
-static int32_t calculateEdgeFlagsUsingPointerBounds(
- const sp<PointerControllerInterface>& pointerController, float x, float y) {
- int32_t edgeFlags = 0;
- float minX, minY, maxX, maxY;
- if (pointerController->getBounds(&minX, &minY, &maxX, &maxY)) {
- if (x <= minX) {
- edgeFlags |= AMOTION_EVENT_EDGE_FLAG_LEFT;
- } else if (x >= maxX) {
- edgeFlags |= AMOTION_EVENT_EDGE_FLAG_RIGHT;
- }
- if (y <= minY) {
- edgeFlags |= AMOTION_EVENT_EDGE_FLAG_TOP;
- } else if (y >= maxY) {
- edgeFlags |= AMOTION_EVENT_EDGE_FLAG_BOTTOM;
- }
- }
- return edgeFlags;
-}
-
static float calculateCommonVector(float a, float b) {
if (a > 0 && b > 0) {
return a < b ? a : b;
@@ -1619,7 +1602,6 @@ void CursorInputMapper::sync(nsecs_t when) {
}
int32_t motionEventAction;
- int32_t motionEventEdgeFlags;
int32_t lastButtonState, currentButtonState;
PointerProperties pointerProperties;
PointerCoords pointerCoords;
@@ -1676,29 +1658,9 @@ void CursorInputMapper::sync(nsecs_t when) {
orientation = DISPLAY_ORIENTATION_0;
}
- float temp;
- switch (orientation) {
- case DISPLAY_ORIENTATION_90:
- temp = deltaX;
- deltaX = deltaY;
- deltaY = -temp;
- break;
-
- case DISPLAY_ORIENTATION_180:
- deltaX = -deltaX;
- deltaY = -deltaY;
- break;
-
- case DISPLAY_ORIENTATION_270:
- temp = deltaX;
- deltaX = -deltaY;
- deltaY = temp;
- break;
- }
+ rotateDelta(orientation, &deltaX, &deltaY);
}
- motionEventEdgeFlags = AMOTION_EVENT_EDGE_FLAG_NONE;
-
pointerProperties.clear();
pointerProperties.id = 0;
pointerProperties.toolType = AMOTION_EVENT_TOOL_TYPE_MOUSE;
@@ -1742,11 +1704,6 @@ void CursorInputMapper::sync(nsecs_t when) {
mPointerController->getPosition(&x, &y);
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
-
- if (motionEventAction == AMOTION_EVENT_ACTION_DOWN) {
- motionEventEdgeFlags = calculateEdgeFlagsUsingPointerBounds(
- mPointerController, x, y);
- }
} else {
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, deltaX);
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, deltaY);
@@ -1771,7 +1728,7 @@ void CursorInputMapper::sync(nsecs_t when) {
// Send motion event.
int32_t metaState = mContext->getGlobalMetaState();
getDispatcher()->notifyMotion(when, getDeviceId(), mSource, policyFlags,
- motionEventAction, 0, metaState, currentButtonState, motionEventEdgeFlags,
+ motionEventAction, 0, metaState, currentButtonState, 0,
1, &pointerProperties, &pointerCoords, mXPrecision, mYPrecision, downTime);
// Send hover move after UP to tell the application that the mouse is hovering now.
@@ -3168,9 +3125,8 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) {
}
// Update current touch coordinates.
- int32_t edgeFlags;
float xPrecision, yPrecision;
- prepareTouches(&edgeFlags, &xPrecision, &yPrecision);
+ prepareTouches(&xPrecision, &yPrecision);
// Dispatch motions.
BitSet32 currentIdBits = mCurrentTouch.idBits;
@@ -3239,13 +3195,10 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) {
if (dispatchedIdBits.count() == 1) {
// First pointer is going down. Set down time.
mDownTime = when;
- } else {
- // Only send edge flags with first pointer down.
- edgeFlags = AMOTION_EVENT_EDGE_FLAG_NONE;
}
dispatchMotion(when, policyFlags, mTouchSource,
- AMOTION_EVENT_ACTION_POINTER_DOWN, 0, metaState, buttonState, edgeFlags,
+ AMOTION_EVENT_ACTION_POINTER_DOWN, 0, metaState, buttonState, 0,
mCurrentTouchProperties, mCurrentTouchCoords,
mCurrentTouch.idToIndex, dispatchedIdBits, downId,
xPrecision, yPrecision, mDownTime);
@@ -3259,8 +3212,7 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) {
}
}
-void TouchInputMapper::prepareTouches(int32_t* outEdgeFlags,
- float* outXPrecision, float* outYPrecision) {
+void TouchInputMapper::prepareTouches(float* outXPrecision, float* outYPrecision) {
uint32_t currentPointerCount = mCurrentTouch.pointerCount;
uint32_t lastPointerCount = mLastTouch.pointerCount;
@@ -3471,28 +3423,6 @@ void TouchInputMapper::prepareTouches(int32_t* outEdgeFlags,
properties.toolType = getTouchToolType(mCurrentTouch.pointers[i].isStylus);
}
- // Check edge flags by looking only at the first pointer since the flags are
- // global to the event.
- *outEdgeFlags = AMOTION_EVENT_EDGE_FLAG_NONE;
- if (lastPointerCount == 0 && currentPointerCount > 0) {
- const PointerData& in = mCurrentTouch.pointers[0];
-
- if (in.x <= mRawAxes.x.minValue) {
- *outEdgeFlags |= rotateEdgeFlag(AMOTION_EVENT_EDGE_FLAG_LEFT,
- mLocked.surfaceOrientation);
- } else if (in.x >= mRawAxes.x.maxValue) {
- *outEdgeFlags |= rotateEdgeFlag(AMOTION_EVENT_EDGE_FLAG_RIGHT,
- mLocked.surfaceOrientation);
- }
- if (in.y <= mRawAxes.y.minValue) {
- *outEdgeFlags |= rotateEdgeFlag(AMOTION_EVENT_EDGE_FLAG_TOP,
- mLocked.surfaceOrientation);
- } else if (in.y >= mRawAxes.y.maxValue) {
- *outEdgeFlags |= rotateEdgeFlag(AMOTION_EVENT_EDGE_FLAG_BOTTOM,
- mLocked.surfaceOrientation);
- }
- }
-
*outXPrecision = mLocked.orientedXPrecision;
*outYPrecision = mLocked.orientedYPrecision;
}
@@ -3640,19 +3570,12 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, uint32_t policyFlag
downGestureIdBits.clearBit(id);
dispatchedGestureIdBits.markBit(id);
- int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_NONE;
if (dispatchedGestureIdBits.count() == 1) {
- // First pointer is going down. Calculate edge flags and set down time.
- uint32_t index = mPointerGesture.currentGestureIdToIndex[id];
- const PointerCoords& downCoords = mPointerGesture.currentGestureCoords[index];
- edgeFlags = calculateEdgeFlagsUsingPointerBounds(mPointerController,
- downCoords.getAxisValue(AMOTION_EVENT_AXIS_X),
- downCoords.getAxisValue(AMOTION_EVENT_AXIS_Y));
mPointerGesture.downTime = when;
}
dispatchMotion(when, policyFlags, mPointerSource,
- AMOTION_EVENT_ACTION_POINTER_DOWN, 0, metaState, buttonState, edgeFlags,
+ AMOTION_EVENT_ACTION_POINTER_DOWN, 0, metaState, buttonState, 0,
mPointerGesture.currentGestureProperties,
mPointerGesture.currentGestureCoords, mPointerGesture.currentGestureIdToIndex,
dispatchedGestureIdBits, id,
@@ -3895,6 +3818,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when,
float deltaY = (currentPointer.y - lastPointer.y)
* mLocked.pointerGestureYMovementScale;
+ rotateDelta(mLocked.surfaceOrientation, &deltaX, &deltaY);
mPointerGesture.pointerVelocityControl.move(when, &deltaX, &deltaY);
// Move the pointer using a relative motion.
@@ -4033,6 +3957,7 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when,
float deltaY = (currentPointer.y - lastPointer.y)
* mLocked.pointerGestureYMovementScale;
+ rotateDelta(mLocked.surfaceOrientation, &deltaX, &deltaY);
mPointerGesture.pointerVelocityControl.move(when, &deltaX, &deltaY);
// Move the pointer using a relative motion.
@@ -4290,6 +4215,8 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when,
commonDeltaX *= mLocked.pointerGestureXMovementScale;
commonDeltaY *= mLocked.pointerGestureYMovementScale;
+
+ rotateDelta(mLocked.surfaceOrientation, &commonDeltaX, &commonDeltaY);
mPointerGesture.pointerVelocityControl.move(when, &commonDeltaX, &commonDeltaY);
mPointerGesture.referenceGestureX += commonDeltaX;
@@ -4297,32 +4224,11 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when,
}
// Report gestures.
- if (mPointerGesture.currentGestureMode == PointerGesture::PRESS) {
- // PRESS mode.
-#if DEBUG_GESTURES
- LOGD("Gestures: PRESS activeTouchId=%d,"
- "activeGestureId=%d, currentTouchPointerCount=%d",
- activeTouchId, mPointerGesture.activeGestureId, mCurrentTouch.pointerCount);
-#endif
- LOG_ASSERT(mPointerGesture.activeGestureId >= 0);
-
- mPointerGesture.currentGestureIdBits.clear();
- mPointerGesture.currentGestureIdBits.markBit(mPointerGesture.activeGestureId);
- mPointerGesture.currentGestureIdToIndex[mPointerGesture.activeGestureId] = 0;
- mPointerGesture.currentGestureProperties[0].clear();
- mPointerGesture.currentGestureProperties[0].id = mPointerGesture.activeGestureId;
- mPointerGesture.currentGestureProperties[0].toolType =
- AMOTION_EVENT_TOOL_TYPE_INDIRECT_FINGER;
- mPointerGesture.currentGestureCoords[0].clear();
- mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X,
- mPointerGesture.referenceGestureX);
- mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y,
- mPointerGesture.referenceGestureY);
- mPointerGesture.currentGestureCoords[0].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
- } else if (mPointerGesture.currentGestureMode == PointerGesture::SWIPE) {
- // SWIPE mode.
+ if (mPointerGesture.currentGestureMode == PointerGesture::PRESS
+ || mPointerGesture.currentGestureMode == PointerGesture::SWIPE) {
+ // PRESS or SWIPE mode.
#if DEBUG_GESTURES
- LOGD("Gestures: SWIPE activeTouchId=%d,"
+ LOGD("Gestures: PRESS or SWIPE activeTouchId=%d,"
"activeGestureId=%d, currentTouchPointerCount=%d",
activeTouchId, mPointerGesture.activeGestureId, mCurrentTouch.pointerCount);
#endif
@@ -4416,10 +4322,11 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when,
mPointerGesture.currentGestureIdBits.markBit(gestureId);
mPointerGesture.currentGestureIdToIndex[gestureId] = i;
- float x = (mCurrentTouch.pointers[i].x - mPointerGesture.referenceTouchX)
- * mLocked.pointerGestureXZoomScale + mPointerGesture.referenceGestureX;
- float y = (mCurrentTouch.pointers[i].y - mPointerGesture.referenceTouchY)
- * mLocked.pointerGestureYZoomScale + mPointerGesture.referenceGestureY;
+ float deltaX = (mCurrentTouch.pointers[i].x - mPointerGesture.referenceTouchX)
+ * mLocked.pointerGestureXZoomScale;
+ float deltaY = (mCurrentTouch.pointers[i].y - mPointerGesture.referenceTouchY)
+ * mLocked.pointerGestureYZoomScale;
+ rotateDelta(mLocked.surfaceOrientation, &deltaX, &deltaY);
mPointerGesture.currentGestureProperties[i].clear();
mPointerGesture.currentGestureProperties[i].id = gestureId;
@@ -4427,9 +4334,9 @@ bool TouchInputMapper::preparePointerGestures(nsecs_t when,
AMOTION_EVENT_TOOL_TYPE_INDIRECT_FINGER;
mPointerGesture.currentGestureCoords[i].clear();
mPointerGesture.currentGestureCoords[i].setAxisValue(
- AMOTION_EVENT_AXIS_X, x);
+ AMOTION_EVENT_AXIS_X, mPointerGesture.referenceGestureX + deltaX);
mPointerGesture.currentGestureCoords[i].setAxisValue(
- AMOTION_EVENT_AXIS_Y, y);
+ AMOTION_EVENT_AXIS_Y, mPointerGesture.referenceGestureY + deltaY);
mPointerGesture.currentGestureCoords[i].setAxisValue(
AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
}