Skip to content
Open
6 changes: 6 additions & 0 deletions services/inputflinger/dispatcher/InputDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static constexpr bool DEBUG_TOUCH_OCCLUSION = true;
#include <powermanager/PowerManager.h>
#include <unistd.h>
#include <utils/Trace.h>
#include <cutils/properties.h>

#include <cerrno>
#include <cinttypes>
Expand Down Expand Up @@ -3760,12 +3761,17 @@ void InputDispatcher::notifyConfigurationChanged(const NotifyConfigurationChange
*/
void InputDispatcher::accelerateMetaShortcuts(const int32_t deviceId, const int32_t action,
int32_t& keyCode, int32_t& metaState) {
// Allow overriding win key with home key
char mWinAsHome[PROPERTY_VALUE_MAX] = {0};
property_get("ro.boot.force.win_as_home", mWinAsHome, "0");
if (metaState & AMETA_META_ON && action == AKEY_EVENT_ACTION_DOWN) {
int32_t newKeyCode = AKEYCODE_UNKNOWN;
if (keyCode == AKEYCODE_DEL) {
newKeyCode = AKEYCODE_BACK;
} else if (keyCode == AKEYCODE_ENTER) {
newKeyCode = AKEYCODE_HOME;
} else if (strcmp(mWinAsHome, "1") == 0) {
newKeyCode = AKEYCODE_HOME;
}
if (newKeyCode != AKEYCODE_UNKNOWN) {
std::scoped_lock _l(mLock);
Expand Down
1 change: 1 addition & 0 deletions services/inputflinger/include/InputReaderBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ class InputReaderPolicyInterface : public virtual RefBase {
/* Gets the affine calibration associated with the specified device. */
virtual TouchAffineTransformation getTouchAffineTransformation(
const std::string& inputDeviceDescriptor, int32_t surfaceRotation) = 0;
virtual int32_t notifyDisplayIdChanged() = 0;
};

} // namespace android
Expand Down
7 changes: 6 additions & 1 deletion services/inputflinger/reader/InputReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <unistd.h>
#include <utils/Errors.h>
#include <utils/Thread.h>

#include <cutils/properties.h>
#include "InputDevice.h"

using android::base::StringPrintf;
Expand Down Expand Up @@ -458,6 +458,11 @@ void InputReader::updatePointerDisplayLocked() {

std::optional<DisplayViewport> viewport =
mConfig.getDisplayViewportById(mConfig.defaultPointerDisplayId);

int32_t mOverrideDisplayId = property_get_int32("persist.override.cursor_display_id", -1);
if (mOverrideDisplayId != -1) {
viewport = mConfig.getDisplayViewportById(mOverrideDisplayId);
}
if (!viewport) {
ALOGW("Can't find the designated viewport with ID %" PRId32 " to update cursor input "
"mapper. Fall back to default display",
Expand Down
30 changes: 28 additions & 2 deletions services/inputflinger/reader/mapper/CursorInputMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "CursorScrollAccumulator.h"
#include "PointerControllerInterface.h"
#include "TouchCursorInputMapperCommon.h"
#include <cutils/properties.h>

namespace android {

Expand Down Expand Up @@ -362,6 +363,7 @@ void CursorInputMapper::dumpParameters(std::string& dump) {
void CursorInputMapper::reset(nsecs_t when) {
mButtonState = 0;
mDownTime = 0;
mDisplayId=0;

mPointerVelocityControl.reset();
mWheelXVelocityControl.reset();
Expand Down Expand Up @@ -400,7 +402,11 @@ void CursorInputMapper::process(const RawEvent* rawEvent) {
mCursorMotionAccumulator.process(rawEvent);
mCursorPositionAccumulator.process(rawEvent);
mCursorScrollAccumulator.process(rawEvent);

if (auto viewport = mDeviceContext.getAssociatedViewport(); viewport) {
if (viewport->displayId != mPointerController->getDisplayId()) {
mPointerController->setDisplayViewport(*viewport);
}
}
if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
sync(rawEvent->when, rawEvent->readTime);
}
Expand Down Expand Up @@ -519,7 +525,27 @@ void CursorInputMapper::sync(nsecs_t when, nsecs_t readTime) {
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition);
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX);
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY);
displayId = mPointerController->getDisplayId();

char mMousePresentation[PROPERTY_VALUE_MAX] = {0};
property_get("persist.mouse.presentation", mMousePresentation, "0");
if (strcmp(mMousePresentation, "1") == 0) {
displayId = mDisplayId;
float minX, minY, maxX, maxY;
if (mPointerController->getBounds(&minX, &minY, &maxX, &maxY)) {
float originalY = yCursorPosition; // remember the original y position
if(xCursorPosition==minX){
displayId=getPolicy()->notifyDisplayIdChanged();
mDisplayId=displayId;
mPointerController->setPosition(maxX, originalY);
} else if(xCursorPosition==maxX){
displayId=getPolicy()->notifyDisplayIdChanged();
mDisplayId=displayId;
mPointerController->setPosition(minX, originalY);
}
}
}else{
displayId = mPointerController->getDisplayId();
}
} else {
// Pointer capture and navigation modes
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, deltaX);
Expand Down
2 changes: 2 additions & 0 deletions services/inputflinger/reader/mapper/CursorInputMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class CursorInputMapper : public InputMapper {
float mVWheelScale;
float mHWheelScale;

int32_t mDisplayId;

// Velocity controls for mouse pointer and wheel movements.
// The controls for X and Y wheel movements are separate to keep them decoupled.
VelocityControl mPointerVelocityControl;
Expand Down
26 changes: 25 additions & 1 deletion services/inputflinger/reader/mapper/TouchInputMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "CursorScrollAccumulator.h"
#include "TouchButtonAccumulator.h"
#include "TouchCursorInputMapperCommon.h"
#include <cutils/properties.h>

namespace android {

Expand Down Expand Up @@ -1442,6 +1443,7 @@ void TouchInputMapper::reset(nsecs_t when) {
mHavePointerIds = false;
mCurrentMotionAborted = false;
mDownTime = 0;
mDisplayId = 0;

mCurrentVirtualKey.down = false;

Expand Down Expand Up @@ -2638,7 +2640,29 @@ void TouchInputMapper::dispatchPointerGestures(nsecs_t when, nsecs_t readTime, u
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, y);

const int32_t displayId = mPointerController->getDisplayId();
int32_t displayId = ADISPLAY_ID_NONE;

char mMousePresentation[PROPERTY_VALUE_MAX] = {0};
property_get("persist.mouse.presentation", mMousePresentation, "0");
if (strcmp(mMousePresentation, "1") == 0) {
displayId = mDisplayId;
float minX, minY, maxX, maxY;
if (mPointerController->getBounds(&minX, &minY, &maxX, &maxY)) {
float originalY = y; // remember the original y position
if(x==minX){
displayId=getPolicy()->notifyDisplayIdChanged();
mDisplayId=displayId;
mPointerController->setPosition(maxX, originalY);
} else if(x==maxX){
displayId=getPolicy()->notifyDisplayIdChanged();
mDisplayId=displayId;
mPointerController->setPosition(minX, originalY);
}
}
}else{
displayId = mPointerController->getDisplayId();
}

NotifyMotionArgs args(getContext()->getNextId(), when, readTime, getDeviceId(), mSource,
displayId, policyFlags, AMOTION_EVENT_ACTION_HOVER_MOVE, 0, flags,
metaState, buttonState, MotionClassification::NONE,
Expand Down
2 changes: 2 additions & 0 deletions services/inputflinger/reader/mapper/TouchInputMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ class TouchInputMapper : public InputMapper {
// requested orientation, so it will depend on whether the device is orientation aware.
int32_t mSurfaceOrientation;

int32_t mDisplayId;

// Translation and scaling factors, orientation-independent.
float mXTranslate;
float mXScale;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "EventHub.h"
#include "InputDevice.h"
#include <cutils/properties.h>

namespace android {

Expand Down Expand Up @@ -84,7 +85,13 @@ uint32_t CursorButtonAccumulator::getButtonState() const {
result |= AMOTION_EVENT_BUTTON_PRIMARY;
}
if (mBtnRight) {
result |= AMOTION_EVENT_BUTTON_SECONDARY;
char mBtnRightState[PROPERTY_VALUE_MAX] = {0};
property_get("ro.boot.force.right_mouse_as_back", mBtnRightState, "false");
if (strcmp(mBtnRightState, "true") == 0) {
result |= AMOTION_EVENT_BUTTON_BACK;
} else {
result |= AMOTION_EVENT_BUTTON_SECONDARY;
}
}
if (mBtnMiddle) {
result |= AMOTION_EVENT_BUTTON_TERTIARY;
Expand Down
5 changes: 5 additions & 0 deletions services/inputflinger/tests/InputReader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ class FakeInputReaderPolicy : public InputReaderPolicyInterface {
return mInputDevices;
}

int32_t notifyDisplayIdChanged(){
return 0;
}


TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor,
int32_t surfaceRotation) {
return transform;
Expand Down