Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

frameworks-native: Commit

frameworks/native


Commit MetaInfo

Revision6084c3ffaba854080c32edfa77aa616a9fc309b4 (tree)
Time2018-12-26 13:14:02
AuthorJon Doe <tuksgig@gmai...>
CommiterChih-Wei Huang

Log Message

inputflinger: treat tablet-style inputs as absolute coordinate mouse pointer

Qemu and VirtualBox use tablet-style inputs. However, it's difficult to
work with the current "invisible finger" or "drag pointer" interface
provided to the virtual absolute coordinate pointing devices.
Instead, this patch classifies them as a regular mouse pointer
(INPUT_DEVICE_CLASS_CURSOR), which is more intuitive to work with.

Change Summary

Incremental Difference

--- a/services/inputflinger/EventHub.cpp
+++ b/services/inputflinger/EventHub.cpp
@@ -1214,6 +1214,12 @@ status_t EventHub::openDeviceLocked(const char *devicePath, bool ignoreAlreadyOp
12141214 && test_bit(REL_X, device->relBitmask)
12151215 && test_bit(REL_Y, device->relBitmask)) {
12161216 device->classes |= INPUT_DEVICE_CLASS_CURSOR;
1217+ // Is this an absolute x-y axis with relative wheel mouse device?
1218+ } else if (test_bit(BTN_MOUSE, device->keyBitmask)
1219+ && test_bit(ABS_X, device->absBitmask)
1220+ && test_bit(ABS_Y, device->absBitmask)
1221+ && test_bit(REL_WHEEL, device->relBitmask)) {
1222+ device->classes |= INPUT_DEVICE_CLASS_CURSOR;
12171223 }
12181224
12191225 // See if this is a rotary encoder type device.
@@ -1238,7 +1244,8 @@ status_t EventHub::openDeviceLocked(const char *devicePath, bool ignoreAlreadyOp
12381244 // Is this an old style single-touch driver?
12391245 } else if ((test_bit(BTN_TOUCH, device->keyBitmask) || test_bit(BTN_LEFT, device->keyBitmask))
12401246 && test_bit(ABS_X, device->absBitmask)
1241- && test_bit(ABS_Y, device->absBitmask)) {
1247+ && test_bit(ABS_Y, device->absBitmask)
1248+ && !test_bit(REL_WHEEL, device->relBitmask)) {
12421249 device->classes |= INPUT_DEVICE_CLASS_TOUCH;
12431250 // Is this a BT stylus?
12441251 } else if ((test_bit(ABS_PRESSURE, device->absBitmask) ||
--- a/services/inputflinger/InputReader.cpp
+++ b/services/inputflinger/InputReader.cpp
@@ -1320,15 +1320,29 @@ void CursorMotionAccumulator::process(const RawEvent* rawEvent) {
13201320 switch (rawEvent->code) {
13211321 case REL_X:
13221322 mRelX = rawEvent->value;
1323+ mMoved = true;
13231324 break;
13241325 case REL_Y:
13251326 mRelY = rawEvent->value;
1327+ mMoved = true;
1328+ break;
1329+ }
1330+ } else if (rawEvent->type == EV_ABS) {
1331+ switch (rawEvent->code) {
1332+ case ABS_X:
1333+ mAbsX = rawEvent->value;
1334+ mMoved = true;
1335+ break;
1336+ case ABS_Y:
1337+ mAbsY = rawEvent->value;
1338+ mMoved = true;
13261339 break;
13271340 }
13281341 }
13291342 }
13301343
13311344 void CursorMotionAccumulator::finishSync() {
1345+ mMoved = false;
13321346 clearRelativeAxes();
13331347 }
13341348
@@ -2480,6 +2494,10 @@ void CursorInputMapper::configure(nsecs_t when,
24802494 switch (mParameters.mode) {
24812495 case Parameters::MODE_POINTER:
24822496 mSource = AINPUT_SOURCE_MOUSE;
2497+ if (mParameters.hasAbsAxis) {
2498+ getAbsoluteAxisInfo(ABS_X, &mRawAbsXInfo);
2499+ getAbsoluteAxisInfo(ABS_Y, &mRawAbsYInfo);
2500+ }
24832501 mXPrecision = 1.0f;
24842502 mYPrecision = 1.0f;
24852503 mXScale = 1.0f;
@@ -2506,10 +2524,18 @@ void CursorInputMapper::configure(nsecs_t when,
25062524 }
25072525
25082526 if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
2509- if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
2527+ if (mParameters.hasAssociatedDisplay) {
25102528 DisplayViewport v;
25112529 if (config->getDisplayInfo(false /*external*/, &v)) {
2512- mOrientation = v.orientation;
2530+ if (mParameters.orientationAware) {
2531+ mOrientation = v.orientation;
2532+ }
2533+ if (mParameters.hasAbsAxis) {
2534+ mXScale = float(v.logicalRight - v.logicalLeft)/(mRawAbsXInfo.maxValue - mRawAbsXInfo.minValue + 1);
2535+ mYScale = float(v.logicalBottom - v.logicalTop)/(mRawAbsYInfo.maxValue - mRawAbsYInfo.minValue + 1);
2536+ mXPrecision = 1.0f / mXScale;
2537+ mYPrecision = 1.0f / mYScale;
2538+ }
25132539 } else {
25142540 mOrientation = DISPLAY_ORIENTATION_0;
25152541 }
@@ -2539,6 +2565,11 @@ void CursorInputMapper::configureParameters() {
25392565 if (mParameters.mode == Parameters::MODE_POINTER || mParameters.orientationAware) {
25402566 mParameters.hasAssociatedDisplay = true;
25412567 }
2568+
2569+ mParameters.hasAbsAxis = false;
2570+ if (mParameters.mode == Parameters::MODE_POINTER) {
2571+ mParameters.hasAbsAxis = getDevice()->hasAbsoluteAxis(ABS_X) && getDevice()->hasAbsoluteAxis(ABS_Y) ? true : false;
2572+ }
25422573 }
25432574
25442575 void CursorInputMapper::dumpParameters(String8& dump) {
@@ -2559,6 +2590,8 @@ void CursorInputMapper::dumpParameters(String8& dump) {
25592590
25602591 dump.appendFormat(INDENT4 "OrientationAware: %s\n",
25612592 toString(mParameters.orientationAware));
2593+ dump.appendFormat(INDENT4 "Absolute Axis: %s\n",
2594+ toString(mParameters.hasAbsAxis));
25622595 }
25632596
25642597 void CursorInputMapper::reset(nsecs_t when) {
@@ -2586,6 +2619,28 @@ void CursorInputMapper::process(const RawEvent* rawEvent) {
25862619 }
25872620 }
25882621
2622+void CursorInputMapper::rotateAbsolute(float* absX, float* absY) {
2623+ float temp;
2624+ switch (mOrientation) {
2625+ case DISPLAY_ORIENTATION_90:
2626+ temp = *absX;
2627+ *absX = *absY;
2628+ *absY = ((mRawAbsXInfo.maxValue - mRawAbsXInfo.minValue) + 1) - temp;
2629+ break;
2630+
2631+ case DISPLAY_ORIENTATION_180:
2632+ *absX = ((mRawAbsXInfo.maxValue - mRawAbsXInfo.minValue) + 1) - *absX;
2633+ *absY = ((mRawAbsYInfo.maxValue - mRawAbsYInfo.minValue) + 1) - *absY;
2634+ break;
2635+
2636+ case DISPLAY_ORIENTATION_270:
2637+ temp = *absX;
2638+ *absX = ((mRawAbsYInfo.maxValue - mRawAbsYInfo.minValue) + 1) - *absY;
2639+ *absY = temp;
2640+ break;
2641+ }
2642+}
2643+
25892644 void CursorInputMapper::sync(nsecs_t when) {
25902645 int32_t lastButtonState = mButtonState;
25912646 int32_t currentButtonState = mCursorButtonAccumulator.getButtonState();
@@ -2607,17 +2662,8 @@ void CursorInputMapper::sync(nsecs_t when) {
26072662 int32_t buttonsPressed = currentButtonState & ~lastButtonState;
26082663 int32_t buttonsReleased = lastButtonState & ~currentButtonState;
26092664
2610- float deltaX = mCursorMotionAccumulator.getRelativeX() * mXScale;
2611- float deltaY = mCursorMotionAccumulator.getRelativeY() * mYScale;
2612- bool moved = deltaX != 0 || deltaY != 0;
2613-
2614- // Rotate delta according to orientation if needed.
2615- if (mParameters.orientationAware && mParameters.hasAssociatedDisplay
2616- && (deltaX != 0.0f || deltaY != 0.0f)) {
2617- rotateDelta(mOrientation, &deltaX, &deltaY);
2618- }
2665+ bool moved = false;
26192666
2620- // Move the pointer.
26212667 PointerProperties pointerProperties;
26222668 pointerProperties.clear();
26232669 pointerProperties.id = 0;
@@ -2626,6 +2672,47 @@ void CursorInputMapper::sync(nsecs_t when) {
26262672 PointerCoords pointerCoords;
26272673 pointerCoords.clear();
26282674
2675+ if (!mParameters.hasAbsAxis) {
2676+ float deltaX = mCursorMotionAccumulator.getRelativeX() * mXScale;
2677+ float deltaY = mCursorMotionAccumulator.getRelativeY() * mYScale;
2678+ moved = deltaX != 0 || deltaY != 0;
2679+
2680+ // Rotate delta according to orientation if needed.
2681+ if (mParameters.orientationAware && mParameters.hasAssociatedDisplay
2682+ && (deltaX != 0.0f || deltaY != 0.0f)) {
2683+ rotateDelta(mOrientation, &deltaX, &deltaY);
2684+ }
2685+ mPointerVelocityControl.move(when, &deltaX, &deltaY);
2686+ if (mPointerController != NULL) {
2687+ if (moved) {
2688+ mPointerController->move(deltaX, deltaY);
2689+ }
2690+ float x, y;
2691+ mPointerController->getPosition(&x, &y);
2692+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
2693+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
2694+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX);
2695+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY);
2696+ } else {
2697+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, deltaX);
2698+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, deltaY);
2699+ }
2700+ } else {
2701+ float absX = mCursorMotionAccumulator.getAbsoluteX() - mRawAbsXInfo.minValue;
2702+ float absY = mCursorMotionAccumulator.getAbsoluteY() - mRawAbsYInfo.minValue;
2703+ if (mParameters.orientationAware) {
2704+ rotateAbsolute(&absX, &absY);
2705+ }
2706+ absX = absX * mXScale;
2707+ absY = absY * mYScale;
2708+ moved = mCursorMotionAccumulator.hasMoved();
2709+ if (moved) {
2710+ mPointerController->setPosition(absX, absY);
2711+ }
2712+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, absX);
2713+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, absY);
2714+ }
2715+
26292716 float vscroll = mCursorScrollAccumulator.getRelativeVWheel();
26302717 float hscroll = mCursorScrollAccumulator.getRelativeHWheel();
26312718 bool scrolled = vscroll != 0 || hscroll != 0;
@@ -2633,35 +2720,20 @@ void CursorInputMapper::sync(nsecs_t when) {
26332720 mWheelYVelocityControl.move(when, NULL, &vscroll);
26342721 mWheelXVelocityControl.move(when, &hscroll, NULL);
26352722
2636- mPointerVelocityControl.move(when, &deltaX, &deltaY);
2637-
26382723 int32_t displayId;
26392724 if (mPointerController != NULL) {
26402725 if (moved || scrolled || buttonsChanged) {
26412726 mPointerController->setPresentation(
26422727 PointerControllerInterface::PRESENTATION_POINTER);
26432728
2644- if (moved) {
2645- mPointerController->move(deltaX, deltaY);
2646- }
2647-
26482729 if (buttonsChanged) {
26492730 mPointerController->setButtonState(currentButtonState);
26502731 }
26512732
26522733 mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
26532734 }
2654-
2655- float x, y;
2656- mPointerController->getPosition(&x, &y);
2657- pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
2658- pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
2659- pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX);
2660- pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY);
26612735 displayId = ADISPLAY_ID_DEFAULT;
26622736 } else {
2663- pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, deltaX);
2664- pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, deltaY);
26652737 displayId = ADISPLAY_ID_NONE;
26662738 }
26672739
--- a/services/inputflinger/InputReader.h
+++ b/services/inputflinger/InputReader.h
@@ -711,10 +711,16 @@ public:
711711
712712 inline int32_t getRelativeX() const { return mRelX; }
713713 inline int32_t getRelativeY() const { return mRelY; }
714+ inline int32_t getAbsoluteX() const { return mAbsX; }
715+ inline int32_t getAbsoluteY() const { return mAbsY; }
716+ inline bool hasMoved() const { return mMoved; }
714717
715718 private:
716719 int32_t mRelX;
717720 int32_t mRelY;
721+ int32_t mAbsX;
722+ int32_t mAbsY;
723+ bool mMoved;
718724
719725 void clearRelativeAxes();
720726 };
@@ -1206,6 +1212,7 @@ private:
12061212 Mode mode;
12071213 bool hasAssociatedDisplay;
12081214 bool orientationAware;
1215+ bool hasAbsAxis;
12091216 } mParameters;
12101217
12111218 CursorButtonAccumulator mCursorButtonAccumulator;
@@ -1213,6 +1220,8 @@ private:
12131220 CursorScrollAccumulator mCursorScrollAccumulator;
12141221
12151222 int32_t mSource;
1223+ RawAbsoluteAxisInfo mRawAbsXInfo;
1224+ RawAbsoluteAxisInfo mRawAbsYInfo;
12161225 float mXScale;
12171226 float mYScale;
12181227 float mXPrecision;
@@ -1236,7 +1245,7 @@ private:
12361245
12371246 void configureParameters();
12381247 void dumpParameters(String8& dump);
1239-
1248+ void rotateAbsolute(float* absX, float* absY);
12401249 void sync(nsecs_t when);
12411250 };
12421251
Show on old repository browser