Android-x86
Fork

  • R/O
  • HTTP
  • SSH
  • HTTPS

frameworks-native: コミット

frameworks/native


コミットメタ情報

リビジョン5895d241ed8c98a02373a46162b22a7e3f78873e (tree)
日時2019-03-20 02:03:22
作者Jon Doe <tuksgig@gmai...>
コミッターChih-Wei Huang

ログメッセージ

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.

変更サマリ

差分

--- a/services/inputflinger/EventHub.cpp
+++ b/services/inputflinger/EventHub.cpp
@@ -1249,6 +1249,12 @@ status_t EventHub::openDeviceLocked(const char *devicePath, bool ignoreAlreadyOp
12491249 && test_bit(REL_X, device->relBitmask)
12501250 && test_bit(REL_Y, device->relBitmask)) {
12511251 device->classes |= INPUT_DEVICE_CLASS_CURSOR;
1252+ // Is this an absolute x-y axis with relative wheel mouse device?
1253+ } else if (test_bit(BTN_MOUSE, device->keyBitmask)
1254+ && test_bit(ABS_X, device->absBitmask)
1255+ && test_bit(ABS_Y, device->absBitmask)
1256+ && test_bit(REL_WHEEL, device->relBitmask)) {
1257+ device->classes |= INPUT_DEVICE_CLASS_CURSOR;
12521258 }
12531259
12541260 // See if this is a rotary encoder type device.
@@ -1273,7 +1279,8 @@ status_t EventHub::openDeviceLocked(const char *devicePath, bool ignoreAlreadyOp
12731279 // Is this an old style single-touch driver?
12741280 } else if ((test_bit(BTN_TOUCH, device->keyBitmask) || test_bit(BTN_LEFT, device->keyBitmask))
12751281 && test_bit(ABS_X, device->absBitmask)
1276- && test_bit(ABS_Y, device->absBitmask)) {
1282+ && test_bit(ABS_Y, device->absBitmask)
1283+ && !test_bit(REL_WHEEL, device->relBitmask)) {
12771284 device->classes |= INPUT_DEVICE_CLASS_TOUCH;
12781285 // Is this a BT stylus?
12791286 } else if ((test_bit(ABS_PRESSURE, device->absBitmask) ||
--- a/services/inputflinger/InputReader.cpp
+++ b/services/inputflinger/InputReader.cpp
@@ -1439,15 +1439,29 @@ void CursorMotionAccumulator::process(const RawEvent* rawEvent) {
14391439 switch (rawEvent->code) {
14401440 case REL_X:
14411441 mRelX = rawEvent->value;
1442+ mMoved = true;
14421443 break;
14431444 case REL_Y:
14441445 mRelY = rawEvent->value;
1446+ mMoved = true;
1447+ break;
1448+ }
1449+ } else if (rawEvent->type == EV_ABS) {
1450+ switch (rawEvent->code) {
1451+ case ABS_X:
1452+ mAbsX = rawEvent->value;
1453+ mMoved = true;
1454+ break;
1455+ case ABS_Y:
1456+ mAbsY = rawEvent->value;
1457+ mMoved = true;
14451458 break;
14461459 }
14471460 }
14481461 }
14491462
14501463 void CursorMotionAccumulator::finishSync() {
1464+ mMoved = false;
14511465 clearRelativeAxes();
14521466 }
14531467
@@ -2649,6 +2663,10 @@ void CursorInputMapper::configure(nsecs_t when,
26492663 // fall through.
26502664 case Parameters::MODE_POINTER:
26512665 mSource = AINPUT_SOURCE_MOUSE;
2666+ if (mParameters.hasAbsAxis) {
2667+ getAbsoluteAxisInfo(ABS_X, &mRawAbsXInfo);
2668+ getAbsoluteAxisInfo(ABS_Y, &mRawAbsYInfo);
2669+ }
26522670 mXPrecision = 1.0f;
26532671 mYPrecision = 1.0f;
26542672 mXScale = 1.0f;
@@ -2700,10 +2718,18 @@ void CursorInputMapper::configure(nsecs_t when,
27002718 }
27012719
27022720 if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
2703- if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
2721+ if (mParameters.hasAssociatedDisplay) {
27042722 DisplayViewport v;
27052723 if (config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, NULL, &v)) {
2706- mOrientation = v.orientation;
2724+ if (mParameters.orientationAware) {
2725+ mOrientation = v.orientation;
2726+ }
2727+ if (mParameters.hasAbsAxis) {
2728+ mXScale = float(v.logicalRight - v.logicalLeft)/(mRawAbsXInfo.maxValue - mRawAbsXInfo.minValue + 1);
2729+ mYScale = float(v.logicalBottom - v.logicalTop)/(mRawAbsYInfo.maxValue - mRawAbsYInfo.minValue + 1);
2730+ mXPrecision = 1.0f / mXScale;
2731+ mYPrecision = 1.0f / mYScale;
2732+ }
27072733 } else {
27082734 mOrientation = DISPLAY_ORIENTATION_0;
27092735 }
@@ -2733,6 +2759,11 @@ void CursorInputMapper::configureParameters() {
27332759 if (mParameters.mode == Parameters::MODE_POINTER || mParameters.orientationAware) {
27342760 mParameters.hasAssociatedDisplay = true;
27352761 }
2762+
2763+ mParameters.hasAbsAxis = false;
2764+ if (mParameters.mode == Parameters::MODE_POINTER) {
2765+ mParameters.hasAbsAxis = getDevice()->hasAbsoluteAxis(ABS_X) && getDevice()->hasAbsoluteAxis(ABS_Y) ? true : false;
2766+ }
27362767 }
27372768
27382769 void CursorInputMapper::dumpParameters(std::string& dump) {
@@ -2756,6 +2787,8 @@ void CursorInputMapper::dumpParameters(std::string& dump) {
27562787
27572788 dump += StringPrintf(INDENT4 "OrientationAware: %s\n",
27582789 toString(mParameters.orientationAware));
2790+ dump += StringPrintf(INDENT4 "Absolute Axis: %s\n",
2791+ toString(mParameters.hasAbsAxis));
27592792 }
27602793
27612794 void CursorInputMapper::reset(nsecs_t when) {
@@ -2783,6 +2816,28 @@ void CursorInputMapper::process(const RawEvent* rawEvent) {
27832816 }
27842817 }
27852818
2819+void CursorInputMapper::rotateAbsolute(float* absX, float* absY) {
2820+ float temp;
2821+ switch (mOrientation) {
2822+ case DISPLAY_ORIENTATION_90:
2823+ temp = *absX;
2824+ *absX = *absY;
2825+ *absY = ((mRawAbsXInfo.maxValue - mRawAbsXInfo.minValue) + 1) - temp;
2826+ break;
2827+
2828+ case DISPLAY_ORIENTATION_180:
2829+ *absX = ((mRawAbsXInfo.maxValue - mRawAbsXInfo.minValue) + 1) - *absX;
2830+ *absY = ((mRawAbsYInfo.maxValue - mRawAbsYInfo.minValue) + 1) - *absY;
2831+ break;
2832+
2833+ case DISPLAY_ORIENTATION_270:
2834+ temp = *absX;
2835+ *absX = ((mRawAbsYInfo.maxValue - mRawAbsYInfo.minValue) + 1) - *absY;
2836+ *absY = temp;
2837+ break;
2838+ }
2839+}
2840+
27862841 void CursorInputMapper::sync(nsecs_t when) {
27872842 int32_t lastButtonState = mButtonState;
27882843 int32_t currentButtonState = mCursorButtonAccumulator.getButtonState();
@@ -2804,17 +2859,7 @@ void CursorInputMapper::sync(nsecs_t when) {
28042859 int32_t buttonsPressed = currentButtonState & ~lastButtonState;
28052860 int32_t buttonsReleased = lastButtonState & ~currentButtonState;
28062861
2807- float deltaX = mCursorMotionAccumulator.getRelativeX() * mXScale;
2808- float deltaY = mCursorMotionAccumulator.getRelativeY() * mYScale;
2809- bool moved = deltaX != 0 || deltaY != 0;
2810-
2811- // Rotate delta according to orientation if needed.
2812- if (mParameters.orientationAware && mParameters.hasAssociatedDisplay
2813- && (deltaX != 0.0f || deltaY != 0.0f)) {
2814- rotateDelta(mOrientation, &deltaX, &deltaY);
2815- }
2816-
2817- // Move the pointer.
2862+ bool moved = false;
28182863 PointerProperties pointerProperties;
28192864 pointerProperties.clear();
28202865 pointerProperties.id = 0;
@@ -2823,6 +2868,47 @@ void CursorInputMapper::sync(nsecs_t when) {
28232868 PointerCoords pointerCoords;
28242869 pointerCoords.clear();
28252870
2871+ if (!mParameters.hasAbsAxis) {
2872+ float deltaX = mCursorMotionAccumulator.getRelativeX() * mXScale;
2873+ float deltaY = mCursorMotionAccumulator.getRelativeY() * mYScale;
2874+ moved = deltaX != 0 || deltaY != 0;
2875+
2876+ // Rotate delta according to orientation if needed.
2877+ if (mParameters.orientationAware && mParameters.hasAssociatedDisplay
2878+ && (deltaX != 0.0f || deltaY != 0.0f)) {
2879+ rotateDelta(mOrientation, &deltaX, &deltaY);
2880+ }
2881+ mPointerVelocityControl.move(when, &deltaX, &deltaY);
2882+ if (mPointerController != NULL) {
2883+ if (moved) {
2884+ mPointerController->move(deltaX, deltaY);
2885+ }
2886+ float x, y;
2887+ mPointerController->getPosition(&x, &y);
2888+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
2889+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
2890+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX);
2891+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY);
2892+ } else {
2893+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, deltaX);
2894+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, deltaY);
2895+ }
2896+ } else {
2897+ float absX = mCursorMotionAccumulator.getAbsoluteX() - mRawAbsXInfo.minValue;
2898+ float absY = mCursorMotionAccumulator.getAbsoluteY() - mRawAbsYInfo.minValue;
2899+ if (mParameters.orientationAware) {
2900+ rotateAbsolute(&absX, &absY);
2901+ }
2902+ absX = absX * mXScale;
2903+ absY = absY * mYScale;
2904+ moved = mCursorMotionAccumulator.hasMoved();
2905+ if (moved) {
2906+ mPointerController->setPosition(absX, absY);
2907+ }
2908+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, absX);
2909+ pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, absY);
2910+ }
2911+
28262912 float vscroll = mCursorScrollAccumulator.getRelativeVWheel();
28272913 float hscroll = mCursorScrollAccumulator.getRelativeHWheel();
28282914 bool scrolled = vscroll != 0 || hscroll != 0;
@@ -2830,35 +2916,20 @@ void CursorInputMapper::sync(nsecs_t when) {
28302916 mWheelYVelocityControl.move(when, NULL, &vscroll);
28312917 mWheelXVelocityControl.move(when, &hscroll, NULL);
28322918
2833- mPointerVelocityControl.move(when, &deltaX, &deltaY);
2834-
28352919 int32_t displayId;
28362920 if (mSource == AINPUT_SOURCE_MOUSE) {
28372921 if (moved || scrolled || buttonsChanged) {
28382922 mPointerController->setPresentation(
28392923 PointerControllerInterface::PRESENTATION_POINTER);
28402924
2841- if (moved) {
2842- mPointerController->move(deltaX, deltaY);
2843- }
2844-
28452925 if (buttonsChanged) {
28462926 mPointerController->setButtonState(currentButtonState);
28472927 }
28482928
28492929 mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE);
28502930 }
2851-
2852- float x, y;
2853- mPointerController->getPosition(&x, &y);
2854- pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
2855- pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);
2856- pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX);
2857- pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY);
28582931 displayId = ADISPLAY_ID_DEFAULT;
28592932 } else {
2860- pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, deltaX);
2861- pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, deltaY);
28622933 displayId = ADISPLAY_ID_NONE;
28632934 }
28642935
--- a/services/inputflinger/InputReader.h
+++ b/services/inputflinger/InputReader.h
@@ -677,10 +677,16 @@ public:
677677
678678 inline int32_t getRelativeX() const { return mRelX; }
679679 inline int32_t getRelativeY() const { return mRelY; }
680+ inline int32_t getAbsoluteX() const { return mAbsX; }
681+ inline int32_t getAbsoluteY() const { return mAbsY; }
682+ inline bool hasMoved() const { return mMoved; }
680683
681684 private:
682685 int32_t mRelX;
683686 int32_t mRelY;
687+ int32_t mAbsX;
688+ int32_t mAbsY;
689+ bool mMoved;
684690
685691 void clearRelativeAxes();
686692 };
@@ -1176,6 +1182,7 @@ private:
11761182 Mode mode;
11771183 bool hasAssociatedDisplay;
11781184 bool orientationAware;
1185+ bool hasAbsAxis;
11791186 } mParameters;
11801187
11811188 CursorButtonAccumulator mCursorButtonAccumulator;
@@ -1183,6 +1190,8 @@ private:
11831190 CursorScrollAccumulator mCursorScrollAccumulator;
11841191
11851192 int32_t mSource;
1193+ RawAbsoluteAxisInfo mRawAbsXInfo;
1194+ RawAbsoluteAxisInfo mRawAbsYInfo;
11861195 float mXScale;
11871196 float mYScale;
11881197 float mXPrecision;
@@ -1207,6 +1216,7 @@ private:
12071216 void configureParameters();
12081217 void dumpParameters(std::string& dump);
12091218
1219+ void rotateAbsolute(float* absX, float* absY);
12101220 void sync(nsecs_t when);
12111221 };
12121222
旧リポジトリブラウザで表示