Skip to content

Commit 0dcf727

Browse files
HarryCuttsAndroid (Google) Code Review
authored andcommitted
Merge "touchpad: add touchpad system gesture setting" into main
2 parents 0e5536c + af66cee commit 0dcf727

5 files changed

Lines changed: 124 additions & 2 deletions

File tree

services/inputflinger/include/InputReaderBase.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ struct InputReaderConfiguration {
245245
// True to use three-finger tap as a customizable shortcut; false to use it as a middle-click.
246246
bool touchpadThreeFingerTapShortcutEnabled;
247247

248+
// True to enable system gestures (three- and four-finger swipes) on touchpads.
249+
bool touchpadSystemGesturesEnabled;
250+
248251
// The set of currently disabled input devices.
249252
std::set<int32_t> disabledDevices;
250253

@@ -297,6 +300,7 @@ struct InputReaderConfiguration {
297300
shouldNotifyTouchpadHardwareState(false),
298301
touchpadRightClickZoneEnabled(false),
299302
touchpadThreeFingerTapShortcutEnabled(false),
303+
touchpadSystemGesturesEnabled(true),
300304
stylusButtonMotionEventsEnabled(true),
301305
stylusPointerIconEnabled(false),
302306
mouseReverseVerticalScrollingEnabled(false),

services/inputflinger/reader/mapper/TouchpadInputMapper.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when,
351351

352352
bumpGeneration();
353353
}
354+
std::list<NotifyArgs> out;
354355
if (!changes.any() || changes.test(InputReaderConfiguration::Change::TOUCHPAD_SETTINGS)) {
355356
mPropertyProvider.getProperty("Use Custom Touchpad Pointer Accel Curve")
356357
.setBoolValues({true});
@@ -375,11 +376,11 @@ std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when,
375376
mPropertyProvider.getProperty("Button Right Click Zone Enable")
376377
.setBoolValues({config.touchpadRightClickZoneEnabled});
377378
mTouchpadHardwareStateNotificationsEnabled = config.shouldNotifyTouchpadHardwareState;
378-
379379
mGestureConverter.setThreeFingerTapShortcutEnabled(
380380
config.touchpadThreeFingerTapShortcutEnabled);
381+
out += mGestureConverter.setEnableSystemGestures(when,
382+
config.touchpadSystemGesturesEnabled);
381383
}
382-
std::list<NotifyArgs> out;
383384
if ((!changes.any() && config.pointerCaptureRequest.isEnable()) ||
384385
changes.test(InputReaderConfiguration::Change::POINTER_CAPTURE)) {
385386
mPointerCaptured = config.pointerCaptureRequest.isEnable();

services/inputflinger/reader/mapper/gestures/GestureConverter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ std::list<NotifyArgs> GestureConverter::reset(nsecs_t when) {
132132
return out;
133133
}
134134

135+
std::list<NotifyArgs> GestureConverter::setEnableSystemGestures(nsecs_t when, bool enable) {
136+
std::list<NotifyArgs> out;
137+
if (!enable && mCurrentClassification == MotionClassification::MULTI_FINGER_SWIPE) {
138+
out += handleMultiFingerSwipeLift(when, when);
139+
}
140+
mEnableSystemGestures = enable;
141+
return out;
142+
}
143+
135144
void GestureConverter::populateMotionRanges(InputDeviceInfo& info) const {
136145
info.addMotionRange(AMOTION_EVENT_AXIS_PRESSURE, SOURCE, 0.0f, 1.0f, 0, 0, 0);
137146

@@ -461,6 +470,9 @@ std::list<NotifyArgs> GestureConverter::endScroll(nsecs_t when, nsecs_t readTime
461470
uint32_t fingerCount,
462471
float dx, float dy) {
463472
std::list<NotifyArgs> out = {};
473+
if (!mEnableSystemGestures) {
474+
return out;
475+
}
464476

465477
if (mCurrentClassification != MotionClassification::MULTI_FINGER_SWIPE) {
466478
// If the user changes the number of fingers mid-way through a swipe (e.g. they start with

services/inputflinger/reader/mapper/gestures/GestureConverter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class GestureConverter {
5959
mThreeFingerTapShortcutEnabled = enabled;
6060
}
6161

62+
[[nodiscard]] std::list<NotifyArgs> setEnableSystemGestures(nsecs_t when, bool enable);
63+
6264
void populateMotionRanges(InputDeviceInfo& info) const;
6365

6466
[[nodiscard]] std::list<NotifyArgs> handleGesture(nsecs_t when, nsecs_t readTime,
@@ -104,6 +106,7 @@ class GestureConverter {
104106
InputReaderContext& mReaderContext;
105107
const bool mEnableFlingStop;
106108
const bool mEnableNoFocusChange;
109+
bool mEnableSystemGestures{true};
107110

108111
bool mThreeFingerTapShortcutEnabled;
109112

services/inputflinger/tests/GestureConverter_test.cpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const auto TOUCHPAD_PALM_REJECTION_V2 =
4848
using testing::AllOf;
4949
using testing::Each;
5050
using testing::ElementsAre;
51+
using testing::IsEmpty;
5152
using testing::VariantWith;
5253

5354
class GestureConverterTest : public testing::Test {
@@ -849,6 +850,107 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
849850
WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
850851
}
851852

853+
TEST_F(GestureConverterTest, DisablingSystemGestures_IgnoresMultiFingerSwipe) {
854+
InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
855+
GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
856+
converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
857+
858+
std::list<NotifyArgs> args = converter.setEnableSystemGestures(ARBITRARY_TIME, false);
859+
ASSERT_THAT(args, IsEmpty());
860+
861+
Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
862+
/*dy=*/10);
863+
Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
864+
/*dy=*/5);
865+
Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
866+
867+
args += converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
868+
args += converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
869+
args += converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
870+
ASSERT_THAT(args, IsEmpty());
871+
872+
args = converter.setEnableSystemGestures(ARBITRARY_TIME, true);
873+
ASSERT_THAT(args, IsEmpty());
874+
875+
args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
876+
ASSERT_THAT(args,
877+
ElementsAre(VariantWith<NotifyMotionArgs>(
878+
WithMotionAction(AMOTION_EVENT_ACTION_DOWN)),
879+
VariantWith<NotifyMotionArgs>(WithMotionAction(
880+
AMOTION_EVENT_ACTION_POINTER_DOWN |
881+
1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT)),
882+
VariantWith<NotifyMotionArgs>(WithMotionAction(
883+
AMOTION_EVENT_ACTION_POINTER_DOWN |
884+
2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT)),
885+
VariantWith<NotifyMotionArgs>(
886+
WithMotionAction(AMOTION_EVENT_ACTION_MOVE))));
887+
ASSERT_THAT(args,
888+
Each(VariantWith<NotifyMotionArgs>(
889+
WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE))));
890+
}
891+
892+
TEST_F(GestureConverterTest, DisablingSystemGestures_EndsOngoingMultiFingerSwipe) {
893+
InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
894+
GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
895+
converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);
896+
897+
Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
898+
/*dy=*/10);
899+
std::list<NotifyArgs> args;
900+
args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
901+
ASSERT_FALSE(args.empty());
902+
903+
// Disabling system gestures should end the swipe early.
904+
args = converter.setEnableSystemGestures(ARBITRARY_TIME, false);
905+
ASSERT_THAT(args,
906+
ElementsAre(VariantWith<NotifyMotionArgs>(
907+
AllOf(WithMotionAction(
908+
AMOTION_EVENT_ACTION_POINTER_UP |
909+
2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
910+
WithGestureOffset(0, 0, EPSILON),
911+
WithMotionClassification(
912+
MotionClassification::MULTI_FINGER_SWIPE),
913+
WithPointerCount(3u))),
914+
VariantWith<NotifyMotionArgs>(
915+
AllOf(WithMotionAction(
916+
AMOTION_EVENT_ACTION_POINTER_UP |
917+
1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
918+
WithGestureOffset(0, 0, EPSILON),
919+
WithMotionClassification(
920+
MotionClassification::MULTI_FINGER_SWIPE),
921+
WithPointerCount(2u))),
922+
VariantWith<NotifyMotionArgs>(
923+
AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
924+
WithGestureOffset(0, 0, EPSILON),
925+
WithMotionClassification(
926+
MotionClassification::MULTI_FINGER_SWIPE),
927+
WithPointerCount(1u))),
928+
VariantWith<NotifyMotionArgs>(
929+
AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
930+
WithMotionClassification(MotionClassification::NONE)))));
931+
ASSERT_THAT(args,
932+
Each(VariantWith<NotifyMotionArgs>(
933+
AllOf(WithToolType(ToolType::FINGER),
934+
WithDisplayId(ui::LogicalDisplayId::DEFAULT)))));
935+
936+
// Further movement in the same swipe should be ignored.
937+
Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
938+
/*dy=*/5);
939+
args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
940+
ASSERT_THAT(args, IsEmpty());
941+
Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
942+
args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
943+
ASSERT_THAT(args, IsEmpty());
944+
945+
// But single-finger pointer motion should be reported.
946+
Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
947+
args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
948+
ASSERT_THAT(args,
949+
ElementsAre(VariantWith<NotifyMotionArgs>(
950+
AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
951+
WithRelativeMotion(-5, 10), WithButtonState(0)))));
952+
}
953+
852954
TEST_F(GestureConverterTest, Pinch_Inwards) {
853955
input_flags::enable_touchpad_no_focus_change(true);
854956

0 commit comments

Comments
 (0)