经常有客户将触摸和屏的方向装反,又不愿意拆机重装;又或者在设置中将屏幕旋转了90度,而此时触摸方向没变,只能通过代码解决啦。
diff --git a/frameworks/na
tive/services/inputflinger/InputReader.cpp b/frameworks/native/services/inputflinger/InputReader.cpp
index c07c3bb508..f5ef4d91b2 100755
--- a/frameworks/native/services/inputflinger/InputReader.cpp
+++ b/frameworks/native/services/inputflinger/InputReader.cpp
@@ -3511,6 +3511,18 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
bool viewportChanged = mViewport != newViewport;
if (viewportChanged) {
mViewport = newViewport;
+ char tp_orientation[PROPERTY_VALUE_MAX] = {0};
+ property_get("persist.sys.tp_rotation", tp_orientation, "0");
+ int mRotation = atoi(tp_orientation);
+ if ( mRotation == 0 ) {
+ mViewport.orientation = mViewport.orientation + DISPLAY_ORIENTATION_0;
+ } else if ( mRotation == 90 ) {
+ mViewport.orientation = mViewport.orientation + DISPLAY_ORIENTATION_90;
+ } else if ( mRotation == 180 ) {
+ mViewport.orientation = mViewport.orientation + DISPLAY_ORIENTATION_180;
+ } else if ( mRotation == 270 ) {
+ mViewport.orientation = mViewport.orientation + DISPLAY_ORIENTATION_270;
+ }
if (mDeviceMode == DEVICE_MODE_DIRECT || mDeviceMode == DEVICE_MODE_POINTER) {
persist.sys.tp_rotation设置触摸的初始方向,当然也可以在设置中添加一个触摸屏旋转选项来方便客户操作,只需修改这个值即可。
说明一下:mViewport.orientation本身也是有个值的,比如APP是竖屏,系统是横屏,打开APP的时候系统会自动旋转为竖屏,此时mViewport.orientation也会跟着变化。所以mViewport.orientation最后的值为mViewport.orientation + DISPLAY_ORIENTATION_X.
原作者:空~。