要求:主屏在左,副屏在右。这种排列情况下鼠标仅可通过主屏的最右侧移入副屏的最左侧,或从副屏的最左侧移入主屏最右侧。
1.RK默认设计
1.1 RK的代码设计是当sys.mouse.presentation=1时,鼠标在屏幕边缘的时候就会移入另一个屏幕
- frameworks/native/services/inputflinger/reader/mapper/CursorInputMapper.cpp
void CursorInputMapper::sync(nsecs_t when) { ... if (mSource == AINPUT_SOURCE_MOUSE) { if (moved || scrolled || buttonsChanged) { mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_POINTER); if (moved) { mPointerController->move(deltaX, deltaY); } if (buttonsChanged) { mPointerController->setButtonState(currentButtonState); } mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE); } mPointerController->getPosition(&xCursorPosition, &yCursorPosition); pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, xCursorPosition); pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition); pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX); pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY); char mMousePresentation[PROPERTY_VALUE_MAX] = {0}; property_get("sys.mouse.presentation", mMousePresentation, "0"); if (strcmp(mMousePresentation, "1") == 0) { displayId = mDisplayId; float minX, minY, maxX, maxY; if (mPointerController->getBounds(&minX, &minY, &maxX, &maxY)) { // 如果鼠标位置在屏幕四周边缘,进入另外的屏幕,重新赋值displayId if (xCursorPosition==minX||xCursorPosition==maxX||yCursorPosition==minY||yCursorPosition==maxY{ displayId=getPolicy()->notifyDisplayIdChanged(); mDisplayId=displayId; } } }else{ displayId = mPointerController->getDisplayId(); } } else { pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, deltaX); pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, deltaY); displayId = ADISPLAY_ID_NONE; } }
1.2 鼠标进入不同屏,默认居中显示
- frameworks/base/libs/input/PointerController.cpp
void PointerController::setDisplayViewport(const DisplayViewport& viewport) { ... // Reset cursor position to center if size or display changed. if (oldViewport.displayId != viewport.displayId || oldDisplayWidth != newDisplayWidth || oldDisplayHeight != newDisplayHeight) { float minX, minY, maxX, maxY; if (getBoundsLocked(&minX, &minY, &maxX, &maxY)) { mLocked.pointerX = (minX + maxX) * 0.5f; mLocked.pointerY = (minY + maxY) * 0.5f; // Reload icon resources for density may be changed. loadResourcesLocked(); } else { mLocked.pointerX = 0; mLocked.pointerY = 0; } fadeOutAndReleaseAllSpotsLocked(); } else if (oldViewport.orientation != viewport.orientation) { }
2.修改鼠标进入方式
hdmi接入状态
- /frameworks/base/services/core/java/com/android/server/WiredAccessoryManager.java
public Pair
parseState(ExtconInfo extconInfo, String status) { ... if (status.contains("HDMI")){ SystemProperties.set("hdmi.plugged", status.contains("HDMI=1") ? "1":"0"); } } 2.1 主屏在左,副屏在右边模式下修改鼠标进入方式
- frameworks/native/services/inputflinger/reader/mapper/CursorInputMapper.cpp
void CursorInputMapper::sync(nsecs_t when) { ... if (mSource == AINPUT_SOURCE_MOUSE) { if (moved || scrolled || buttonsChanged) { mPointerController->setPresentation(PointerControllerInterface::PRESENTATION_POINTER); if (moved) { mPointerController->move(deltaX, deltaY); } if (buttonsChanged) { mPointerController->setButtonState(currentButtonState); } mPointerController->unfade(PointerControllerInterface::TRANSITION_IMMEDIATE); } mPointerController->getPosition(&xCursorPosition, &yCursorPosition); pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, xCursorPosition); pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition); pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX); pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY); char mMousePresentation[PROPERTY_VALUE_MAX] = {0}; property_get("sys.mouse.presentation", mMousePresentation, "0"); if (strcmp(mMousePresentation, "1") == 0) { //displayId = mDisplayId; char mHdmiPlugged[PROPERTY_VALUE_MAX] = {0}; property_get("hdmi.plugged", mHdmiPlugged, "0"); if (strcmp(mHdmiPlugged, "1") == 0){ displayId = mDisplayId; } else { // 鼠标在副屏时,拔掉hdmi导致鼠标没有功能,强制id为主屏0 displayId = 0; } float minX, minY, maxX, maxY; if (mPointerController->getBounds(&minX, &minY, &maxX, &maxY)){ // 鼠标在主屏屏幕右边缘位置,重新赋值displayId,位置改变 if (displayId == 0 && xCursorPosition==maxX) { displayId=getPolicy()->notifyDisplayIdChanged(); mDisplayId=displayId; // 设置鼠标在副屏左侧显示 if ((strcmp(mHdmiPlugged, "1") == 0)){ mPointerController->setPosition(minX+10, yCursorPosition); } } // 鼠标在副屏屏幕左边缘位置,重新赋值displayId,位置改变((主屏id默认为0,副屏id切换后递增)) if (displayId != 0 && xCursorPosition==minX){ displayId=getPolicy()->notifyDisplayIdChanged(); mDisplayId=displayId; // 设置鼠标在主屏右侧显示 mPointerController->setPosition(maxX-10, yCursorPosition); } } }else{ displayId = mPointerController->getDisplayId(); } } else { pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, deltaX); pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, deltaY); displayId = ADISPLAY_ID_NONE; } }
- frameworks/native/services/inputflinger/reader/mapper/CursorInputMapper.cpp
- /frameworks/base/services/core/java/com/android/server/WiredAccessoryManager.java
- frameworks/base/libs/input/PointerController.cpp
还没有评论,来说两句吧...