Skip to content

Commit 5cd7497

Browse files
author
Arpit Singh
committed
Refactor processing of relative pointer movements
Refactor to extract common code that controls cursor movement of a relative mouse in processing of motion events in PointerChoreographer. Bug: 367660694 Test: atest inputflinger_tests Flag: EXEMPT refactor Change-Id: I7f8683f7cda7de6c7bcaf82ceb02dc54b70c71ee
1 parent 7918c82 commit 5cd7497

2 files changed

Lines changed: 20 additions & 24 deletions

File tree

services/inputflinger/PointerChoreographer.cpp

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,7 @@ NotifyMotionArgs PointerChoreographer::processMouseEventLocked(const NotifyMotio
243243
pc.setPosition(args.xCursorPosition, args.yCursorPosition);
244244
} else {
245245
// This is a relative mouse, so move the cursor by the specified amount.
246-
const float deltaX = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X);
247-
const float deltaY = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y);
248-
pc.move(deltaX, deltaY);
249-
const auto [x, y] = pc.getPosition();
250-
newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x);
251-
newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
252-
newArgs.xCursorPosition = x;
253-
newArgs.yCursorPosition = y;
246+
processPointerDeviceMotionEventLocked(/*byref*/ newArgs, /*byref*/ pc);
254247
}
255248
if (canUnfadeOnDisplay(displayId)) {
256249
pc.unfade(PointerControllerInterface::Transition::IMMEDIATE);
@@ -266,24 +259,9 @@ NotifyMotionArgs PointerChoreographer::processTouchpadEventLocked(const NotifyMo
266259
newArgs.displayId = displayId;
267260
if (args.getPointerCount() == 1 && args.classification == MotionClassification::NONE) {
268261
// This is a movement of the mouse pointer.
269-
const float deltaX = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X);
270-
const float deltaY = args.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y);
271-
pc.move(deltaX, deltaY);
272-
if (canUnfadeOnDisplay(displayId)) {
273-
pc.unfade(PointerControllerInterface::Transition::IMMEDIATE);
274-
}
275-
276-
const auto [x, y] = pc.getPosition();
277-
newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x);
278-
newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
279-
newArgs.xCursorPosition = x;
280-
newArgs.yCursorPosition = y;
262+
processPointerDeviceMotionEventLocked(/*byref*/ newArgs, /*byref*/ pc);
281263
} else {
282264
// This is a trackpad gesture with fake finger(s) that should not move the mouse pointer.
283-
if (canUnfadeOnDisplay(displayId)) {
284-
pc.unfade(PointerControllerInterface::Transition::IMMEDIATE);
285-
}
286-
287265
const auto [x, y] = pc.getPosition();
288266
for (uint32_t i = 0; i < newArgs.getPointerCount(); i++) {
289267
newArgs.pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X,
@@ -294,9 +272,25 @@ NotifyMotionArgs PointerChoreographer::processTouchpadEventLocked(const NotifyMo
294272
newArgs.xCursorPosition = x;
295273
newArgs.yCursorPosition = y;
296274
}
275+
if (canUnfadeOnDisplay(displayId)) {
276+
pc.unfade(PointerControllerInterface::Transition::IMMEDIATE);
277+
}
297278
return newArgs;
298279
}
299280

281+
void PointerChoreographer::processPointerDeviceMotionEventLocked(NotifyMotionArgs& newArgs,
282+
PointerControllerInterface& pc) {
283+
const float deltaX = newArgs.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X);
284+
const float deltaY = newArgs.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y);
285+
286+
pc.move(deltaX, deltaY);
287+
const auto [x, y] = pc.getPosition();
288+
newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x);
289+
newArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
290+
newArgs.xCursorPosition = x;
291+
newArgs.yCursorPosition = y;
292+
}
293+
300294
void PointerChoreographer::processDrawingTabletEventLocked(const android::NotifyMotionArgs& args) {
301295
if (args.displayId == ui::LogicalDisplayId::INVALID) {
302296
return;

services/inputflinger/PointerChoreographer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class PointerChoreographer : public PointerChoreographerInterface {
145145
void processDrawingTabletEventLocked(const NotifyMotionArgs& args) REQUIRES(getLock());
146146
void processTouchscreenAndStylusEventLocked(const NotifyMotionArgs& args) REQUIRES(getLock());
147147
void processStylusHoverEventLocked(const NotifyMotionArgs& args) REQUIRES(getLock());
148+
void processPointerDeviceMotionEventLocked(NotifyMotionArgs& newArgs,
149+
PointerControllerInterface& pc) REQUIRES(getLock());
148150
void processDeviceReset(const NotifyDeviceResetArgs& args);
149151
void onControllerAddedOrRemovedLocked() REQUIRES(getLock());
150152
void onPrivacySensitiveDisplaysChangedLocked(

0 commit comments

Comments
 (0)