Skip to content

Commit 43a1d49

Browse files
Arpit SinghAndroid (Google) Code Review
authored andcommitted
Merge changes I34ed5f0f,I9538646f into main
* changes: [23/n Dispatcher refactor] Add const ref to window and connection Move utility functions related to isFromSource to Input.h
2 parents 4e451db + 5b4aeb3 commit 43a1d49

6 files changed

Lines changed: 173 additions & 217 deletions

File tree

include/input/Input.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ struct PointerProperties;
316316

317317
bool isStylusEvent(uint32_t source, const std::vector<PointerProperties>& properties);
318318

319+
bool isStylusHoverEvent(uint32_t source, const std::vector<PointerProperties>& properties,
320+
int32_t action);
321+
322+
bool isFromMouse(uint32_t source, ToolType tooltype);
323+
324+
bool isFromTouchpad(uint32_t source, ToolType tooltype);
325+
326+
bool isFromDrawingTablet(uint32_t source, ToolType tooltype);
327+
328+
bool isHoverAction(int32_t action);
329+
330+
bool isMouseOrTouchpad(uint32_t sources);
331+
319332
/*
320333
* Flags that flow alongside events in the input dispatch system to help with certain
321334
* policy decisions such as waking from device sleep.

libs/input/Input.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,36 @@ bool isStylusEvent(uint32_t source, const std::vector<PointerProperties>& proper
284284
return false;
285285
}
286286

287+
bool isStylusHoverEvent(uint32_t source, const std::vector<PointerProperties>& properties,
288+
int32_t action) {
289+
return isStylusEvent(source, properties) && isHoverAction(action);
290+
}
291+
292+
bool isFromMouse(uint32_t source, ToolType toolType) {
293+
return isFromSource(source, AINPUT_SOURCE_MOUSE) && toolType == ToolType::MOUSE;
294+
}
295+
296+
bool isFromTouchpad(uint32_t source, ToolType toolType) {
297+
return isFromSource(source, AINPUT_SOURCE_MOUSE) && toolType == ToolType::FINGER;
298+
}
299+
300+
bool isFromDrawingTablet(uint32_t source, ToolType toolType) {
301+
return isFromSource(source, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS) &&
302+
isStylusToolType(toolType);
303+
}
304+
305+
bool isHoverAction(int32_t action) {
306+
return action == AMOTION_EVENT_ACTION_HOVER_ENTER ||
307+
action == AMOTION_EVENT_ACTION_HOVER_MOVE || action == AMOTION_EVENT_ACTION_HOVER_EXIT;
308+
}
309+
310+
bool isMouseOrTouchpad(uint32_t sources) {
311+
// Check if this is a mouse or touchpad, but not a drawing tablet.
312+
return isFromSource(sources, AINPUT_SOURCE_MOUSE_RELATIVE) ||
313+
(isFromSource(sources, AINPUT_SOURCE_MOUSE) &&
314+
!isFromSource(sources, AINPUT_SOURCE_STYLUS));
315+
}
316+
287317
VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) {
288318
return {{VerifiedInputEvent::Type::KEY, event.getDeviceId(), event.getEventTime(),
289319
event.getSource(), event.getDisplayId()},

services/inputflinger/PointerChoreographer.cpp

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,6 @@ namespace android {
3636

3737
namespace {
3838

39-
bool isFromMouse(const NotifyMotionArgs& args) {
40-
return isFromSource(args.source, AINPUT_SOURCE_MOUSE) &&
41-
args.pointerProperties[0].toolType == ToolType::MOUSE;
42-
}
43-
44-
bool isFromTouchpad(const NotifyMotionArgs& args) {
45-
return isFromSource(args.source, AINPUT_SOURCE_MOUSE) &&
46-
args.pointerProperties[0].toolType == ToolType::FINGER;
47-
}
48-
49-
bool isFromDrawingTablet(const NotifyMotionArgs& args) {
50-
return isFromSource(args.source, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS) &&
51-
isStylusToolType(args.pointerProperties[0].toolType);
52-
}
53-
54-
bool isHoverAction(int32_t action) {
55-
return action == AMOTION_EVENT_ACTION_HOVER_ENTER ||
56-
action == AMOTION_EVENT_ACTION_HOVER_MOVE || action == AMOTION_EVENT_ACTION_HOVER_EXIT;
57-
}
58-
59-
bool isStylusHoverEvent(const NotifyMotionArgs& args) {
60-
return isStylusEvent(args.source, args.pointerProperties) && isHoverAction(args.action);
61-
}
62-
63-
bool isMouseOrTouchpad(uint32_t sources) {
64-
// Check if this is a mouse or touchpad, but not a drawing tablet.
65-
return isFromSource(sources, AINPUT_SOURCE_MOUSE_RELATIVE) ||
66-
(isFromSource(sources, AINPUT_SOURCE_MOUSE) &&
67-
!isFromSource(sources, AINPUT_SOURCE_STYLUS));
68-
}
69-
7039
inline void notifyPointerDisplayChange(std::optional<std::tuple<ui::LogicalDisplayId, vec2>> change,
7140
PointerChoreographerPolicyInterface& policy) {
7241
if (!change) {
@@ -239,15 +208,16 @@ NotifyMotionArgs PointerChoreographer::processMotion(const NotifyMotionArgs& arg
239208
PointerDisplayChange pointerDisplayChange;
240209
{ // acquire lock
241210
std::scoped_lock _l(getLock());
242-
if (isFromMouse(args)) {
211+
if (isFromMouse(args.source, args.pointerProperties[0].toolType)) {
243212
newArgs = processMouseEventLocked(args);
244213
pointerDisplayChange = calculatePointerDisplayChangeToNotify();
245-
} else if (isFromTouchpad(args)) {
214+
} else if (isFromTouchpad(args.source, args.pointerProperties[0].toolType)) {
246215
newArgs = processTouchpadEventLocked(args);
247216
pointerDisplayChange = calculatePointerDisplayChangeToNotify();
248-
} else if (isFromDrawingTablet(args)) {
217+
} else if (isFromDrawingTablet(args.source, args.pointerProperties[0].toolType)) {
249218
processDrawingTabletEventLocked(args);
250-
} else if (mStylusPointerIconEnabled && isStylusHoverEvent(args)) {
219+
} else if (mStylusPointerIconEnabled &&
220+
isStylusHoverEvent(args.source, args.pointerProperties, args.action)) {
251221
processStylusHoverEventLocked(args);
252222
} else if (isFromSource(args.source, AINPUT_SOURCE_TOUCHSCREEN)) {
253223
processTouchscreenAndStylusEventLocked(args);

0 commit comments

Comments
 (0)