diff options
Diffstat (limited to 'services/input/InputReader.h')
-rw-r--r-- | services/input/InputReader.h | 186 |
1 files changed, 151 insertions, 35 deletions
diff --git a/services/input/InputReader.h b/services/input/InputReader.h index 671e194..55315f7 100644 --- a/services/input/InputReader.h +++ b/services/input/InputReader.h @@ -40,6 +40,117 @@ class InputMapper; /* + * Input reader configuration. + * + * Specifies various options that modify the behavior of the input reader. + */ +struct InputReaderConfiguration { + // Determines whether to turn on some hacks we have to improve the touch interaction with a + // certain device whose screen currently is not all that good. + bool filterTouchEvents; + + // Determines whether to turn on some hacks to improve touch interaction with another device + // where touch coordinate data can get corrupted. + bool filterJumpyTouchEvents; + + // Gets the amount of time to disable virtual keys after the screen is touched + // in order to filter out accidental virtual key presses due to swiping gestures + // or taps near the edge of the display. May be 0 to disable the feature. + nsecs_t virtualKeyQuietTime; + + // The excluded device names for the platform. + // Devices with these names will be ignored. + Vector<String8> excludedDeviceNames; + + // Velocity control parameters for mouse pointer movements. + VelocityControlParameters pointerVelocityControlParameters; + + // Velocity control parameters for mouse wheel movements. + VelocityControlParameters wheelVelocityControlParameters; + + // Quiet time between certain pointer gesture transitions. + // Time to allow for all fingers or buttons to settle into a stable state before + // starting a new gesture. + nsecs_t pointerGestureQuietInterval; + + // The minimum speed that a pointer must travel for us to consider switching the active + // touch pointer to it during a drag. This threshold is set to avoid switching due + // to noise from a finger resting on the touch pad (perhaps just pressing it down). + float pointerGestureDragMinSwitchSpeed; // in pixels per second + + // Tap gesture delay time. + // The time between down and up must be less than this to be considered a tap. + nsecs_t pointerGestureTapInterval; + + // Tap drag gesture delay time. + // The time between the previous tap's up and the next down must be less than + // this to be considered a drag. Otherwise, the previous tap is finished and a + // new tap begins. + // + // Note that the previous tap will be held down for this entire duration so this + // interval must be shorter than the long press timeout. + nsecs_t pointerGestureTapDragInterval; + + // The distance in pixels that the pointer is allowed to move from initial down + // to up and still be called a tap. + float pointerGestureTapSlop; // in pixels + + // Time after the first touch points go down to settle on an initial centroid. + // This is intended to be enough time to handle cases where the user puts down two + // fingers at almost but not quite exactly the same time. + nsecs_t pointerGestureMultitouchSettleInterval; + + // The transition from PRESS to SWIPE or FREEFORM gesture mode is made when + // at least two pointers have moved at least this far from their starting place. + float pointerGestureMultitouchMinDistance; // in pixels + + // The transition from PRESS to SWIPE gesture mode can only occur when the + // cosine of the angle between the two vectors is greater than or equal to than this value + // which indicates that the vectors are oriented in the same direction. + // When the vectors are oriented in the exactly same direction, the cosine is 1.0. + // (In exactly opposite directions, the cosine is -1.0.) + float pointerGestureSwipeTransitionAngleCosine; + + // The transition from PRESS to SWIPE gesture mode can only occur when the + // fingers are no more than this far apart relative to the diagonal size of + // the touch pad. For example, a ratio of 0.5 means that the fingers must be + // no more than half the diagonal size of the touch pad apart. + float pointerGestureSwipeMaxWidthRatio; + + // The gesture movement speed factor relative to the size of the display. + // Movement speed applies when the fingers are moving in the same direction. + // Without acceleration, a full swipe of the touch pad diagonal in movement mode + // will cover this portion of the display diagonal. + float pointerGestureMovementSpeedRatio; + + // The gesture zoom speed factor relative to the size of the display. + // Zoom speed applies when the fingers are mostly moving relative to each other + // to execute a scale gesture or similar. + // Without acceleration, a full swipe of the touch pad diagonal in zoom mode + // will cover this portion of the display diagonal. + float pointerGestureZoomSpeedRatio; + + InputReaderConfiguration() : + filterTouchEvents(false), + filterJumpyTouchEvents(false), + virtualKeyQuietTime(0), + pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, 3.0f), + wheelVelocityControlParameters(1.0f, 15.0f, 50.0f, 4.0f), + pointerGestureQuietInterval(100 * 1000000LL), // 100 ms + pointerGestureDragMinSwitchSpeed(50), // 50 pixels per second + pointerGestureTapInterval(150 * 1000000LL), // 150 ms + pointerGestureTapDragInterval(150 * 1000000LL), // 150 ms + pointerGestureTapSlop(10.0f), // 10 pixels + pointerGestureMultitouchSettleInterval(100 * 1000000LL), // 100 ms + pointerGestureMultitouchMinDistance(15), // 15 pixels + pointerGestureSwipeTransitionAngleCosine(0.2588f), // cosine of 75 degrees + pointerGestureSwipeMaxWidthRatio(0.25f), + pointerGestureMovementSpeedRatio(0.8f), + pointerGestureZoomSpeedRatio(0.3f) { } +}; + + +/* * Input reader policy interface. * * The input reader policy is used by the input reader to interact with the Window Manager @@ -68,24 +179,8 @@ public: virtual bool getDisplayInfo(int32_t displayId, int32_t* width, int32_t* height, int32_t* orientation) = 0; - /* Determines whether to turn on some hacks we have to improve the touch interaction with a - * certain device whose screen currently is not all that good. - */ - virtual bool filterTouchEvents() = 0; - - /* Determines whether to turn on some hacks to improve touch interaction with another device - * where touch coordinate data can get corrupted. - */ - virtual bool filterJumpyTouchEvents() = 0; - - /* Gets the amount of time to disable virtual keys after the screen is touched - * in order to filter out accidental virtual key presses due to swiping gestures - * or taps near the edge of the display. May be 0 to disable the feature. - */ - virtual nsecs_t getVirtualKeyQuietTime() = 0; - - /* Gets the excluded device names for the platform. */ - virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) = 0; + /* Gets the input reader configuration. */ + virtual void getReaderConfiguration(InputReaderConfiguration* outConfig) = 0; /* Gets a pointer controller associated with the specified cursor device (ie. a mouse). */ virtual sp<PointerControllerInterface> obtainPointerController(int32_t deviceId) = 0; @@ -139,6 +234,9 @@ public: /* Determine whether physical keys exist for the given framework-domain key codes. */ virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags) = 0; + + /* Reopens and reconfigures all input devices. */ + virtual void refreshConfiguration() = 0; }; @@ -162,6 +260,7 @@ public: virtual void requestTimeoutAtTime(nsecs_t when) = 0; virtual InputReaderPolicyInterface* getPolicy() = 0; + virtual const InputReaderConfiguration* getConfig() = 0; virtual InputDispatcherInterface* getDispatcher() = 0; virtual EventHubInterface* getEventHub() = 0; }; @@ -202,6 +301,8 @@ public: virtual bool hasKeys(int32_t deviceId, uint32_t sourceMask, size_t numCodes, const int32_t* keyCodes, uint8_t* outFlags); + virtual void refreshConfiguration(); + protected: // These methods are protected virtual so they can be overridden and instrumented // by test cases. @@ -212,7 +313,10 @@ private: sp<InputReaderPolicyInterface> mPolicy; sp<InputDispatcherInterface> mDispatcher; + InputReaderConfiguration mConfig; + virtual InputReaderPolicyInterface* getPolicy() { return mPolicy.get(); } + virtual const InputReaderConfiguration* getConfig() { return &mConfig; } virtual InputDispatcherInterface* getDispatcher() { return mDispatcher.get(); } virtual EventHubInterface* getEventHub() { return mEventHub.get(); } @@ -240,18 +344,17 @@ private: void timeoutExpired(nsecs_t when); void handleConfigurationChanged(nsecs_t when); - void configureExcludedDevices(); // state management for all devices Mutex mStateLock; - int32_t mGlobalMetaState; + int32_t mGlobalMetaState; // guarded by mStateLock virtual void updateGlobalMetaState(); virtual int32_t getGlobalMetaState(); virtual void fadePointer(); - InputConfiguration mInputConfiguration; + InputConfiguration mInputConfiguration; // guarded by mStateLock void updateInputConfiguration(); nsecs_t mDisableVirtualKeysTimeout; // only accessed by reader thread @@ -259,9 +362,12 @@ private: virtual bool shouldDropVirtualKey(nsecs_t now, InputDevice* device, int32_t keyCode, int32_t scanCode); - nsecs_t mNextTimeout; // only accessed by reader thread + nsecs_t mNextTimeout; // only accessed by reader thread, not guarded virtual void requestTimeoutAtTime(nsecs_t when); + volatile int32_t mRefreshConfiguration; // atomic + void configure(bool firstTime); + // state queries typedef int32_t (InputDevice::*GetStateFunc)(uint32_t sourceMask, int32_t code); int32_t getState(int32_t deviceId, uint32_t sourceMask, int32_t code, @@ -354,6 +460,7 @@ public: inline const String8 getDeviceName() { return mDevice->getName(); } inline InputReaderContext* getContext() { return mContext; } inline InputReaderPolicyInterface* getPolicy() { return mContext->getPolicy(); } + inline const InputReaderConfiguration* getConfig() { return mContext->getConfig(); } inline InputDispatcherInterface* getDispatcher() { return mContext->getDispatcher(); } inline EventHubInterface* getEventHub() { return mContext->getEventHub(); } @@ -538,6 +645,12 @@ private: float mVWheelScale; float mHWheelScale; + // Velocity controls for mouse pointer and wheel movements. + // The controls for X and Y wheel movements are separate to keep them decoupled. + VelocityControl mPointerVelocityControl; + VelocityControl mWheelXVelocityControl; + VelocityControl mWheelYVelocityControl; + sp<PointerControllerInterface> mPointerController; struct LockedState { @@ -669,6 +782,9 @@ protected: uint32_t mTouchSource; // sources when reporting touch data uint32_t mPointerSource; // sources when reporting pointer gestures + // The reader's configuration. + const InputReaderConfiguration* mConfig; + // Immutable configuration parameters. struct Parameters { enum DeviceType { @@ -684,7 +800,6 @@ protected: bool useBadTouchFilter; bool useJumpyTouchFilter; bool useAveragingTouchFilter; - nsecs_t virtualKeyQuietTime; enum GestureMode { GESTURE_MODE_POINTER, @@ -964,6 +1079,8 @@ private: // Exactly one finger dragging following a tap. // Pointer follows the active finger. // Emits DOWN, MOVE and UP events at the pointer location. + // + // Detect double-taps when the finger goes up while in TAP_DRAG mode. TAP_DRAG, // Button is pressed. @@ -974,6 +1091,8 @@ private: // Exactly one finger, button is not pressed. // Pointer follows the active finger. // Emits HOVER_MOVE events at the pointer location. + // + // Detect taps when the finger goes up while in HOVER mode. HOVER, // Exactly two fingers but neither have moved enough to clearly indicate @@ -1021,12 +1140,6 @@ private: PointerProperties lastGestureProperties[MAX_POINTERS]; PointerCoords lastGestureCoords[MAX_POINTERS]; - // Pointer coords and ids for the current spots. - PointerControllerInterface::SpotGesture spotGesture; - BitSet32 spotIdBits; // same set of ids as touch ids - uint32_t spotIdToIndex[MAX_POINTER_ID + 1]; - PointerCoords spotCoords[MAX_POINTERS]; - // Time the pointer gesture last went down. nsecs_t downTime; @@ -1062,6 +1175,9 @@ private: // A velocity tracker for determining whether to switch active pointers during drags. VelocityTracker velocityTracker; + // Velocity control for pointer movements. + VelocityControl pointerVelocityControl; + void reset() { firstTouchTime = LLONG_MIN; activeTouchId = -1; @@ -1070,12 +1186,11 @@ private: currentGestureIdBits.clear(); lastGestureMode = NEUTRAL; lastGestureIdBits.clear(); - spotGesture = PointerControllerInterface::SPOT_GESTURE_NEUTRAL; - spotIdBits.clear(); downTime = 0; velocityTracker.clear(); resetTap(); resetQuietTime(); + pointerVelocityControl.reset(); } void resetTap() { @@ -1096,7 +1211,6 @@ private: void dispatchPointerGestures(nsecs_t when, uint32_t policyFlags, bool isTimeout); bool preparePointerGestures(nsecs_t when, bool* outCancelPreviousGesture, bool* outFinishPreviousGesture, bool isTimeout); - void moveSpotsLocked(); // Dispatches a motion event. // If the changedId is >= 0 and the action is POINTER_DOWN or POINTER_UP, the @@ -1243,8 +1357,7 @@ private: uint32_t buttonDown; uint32_t buttonUp; - Accumulator() : slots(NULL) { - clear(false); + Accumulator() : currentSlot(0), slots(NULL), buttonDown(0), buttonUp(0) { } ~Accumulator() { @@ -1255,11 +1368,14 @@ private: slots = new Slot[slotCount]; } - void clear(size_t slotCount) { + void clearSlots(size_t slotCount) { for (size_t i = 0; i < slotCount; i++) { slots[i].clear(); } currentSlot = 0; + } + + void clearButtons() { buttonDown = 0; buttonUp = 0; } |