@@ -57,6 +57,8 @@ constexpr auto HOVER_MOVE = AMOTION_EVENT_ACTION_HOVER_MOVE;
5757constexpr auto INVALID_CURSOR_POSITION = AMOTION_EVENT_INVALID_CURSOR_POSITION;
5858constexpr auto AXIS_X = AMOTION_EVENT_AXIS_X;
5959constexpr auto AXIS_Y = AMOTION_EVENT_AXIS_Y;
60+ constexpr auto AXIS_RELATIVE_X = AMOTION_EVENT_AXIS_RELATIVE_X;
61+ constexpr auto AXIS_RELATIVE_Y = AMOTION_EVENT_AXIS_RELATIVE_Y;
6062constexpr ui::LogicalDisplayId DISPLAY_ID = ui::LogicalDisplayId::DEFAULT;
6163constexpr ui::LogicalDisplayId SECONDARY_DISPLAY_ID = ui::LogicalDisplayId{DISPLAY_ID.val () + 1 };
6264constexpr int32_t DISPLAY_WIDTH = 480 ;
@@ -261,6 +263,59 @@ TEST_F(CursorInputMapperUnitTest, HoverAndLeftButtonPress) {
261263 VariantWith<NotifyMotionArgs>(WithMotionAction (HOVER_MOVE))));
262264}
263265
266+ TEST_F (CursorInputMapperUnitTest, MoveAndButtonChangeInSameFrame) {
267+ createMapper ();
268+ std::list<NotifyArgs> args;
269+
270+ // Move the cursor and press the button
271+ args += process (EV_REL, REL_X, -10 );
272+ args += process (EV_REL, REL_Y, 20 );
273+ args += process (EV_KEY, BTN_LEFT, 1 );
274+ args += process (EV_SYN, SYN_REPORT, 0 );
275+ ASSERT_THAT (args,
276+ ElementsAre (VariantWith<NotifyMotionArgs>(
277+ AllOf (WithMotionAction (HOVER_MOVE), WithButtonState (0 ),
278+ WithNegativeAxis (AXIS_RELATIVE_X),
279+ WithPositiveAxis (AXIS_RELATIVE_Y), WithPressure (0 .0f ))),
280+ VariantWith<NotifyMotionArgs>(
281+ AllOf (WithMotionAction (ACTION_DOWN),
282+ WithButtonState (AMOTION_EVENT_BUTTON_PRIMARY),
283+ WithZeroAxis (AXIS_RELATIVE_X),
284+ WithZeroAxis (AXIS_RELATIVE_Y), WithPressure (1 .0f ))),
285+ VariantWith<NotifyMotionArgs>(
286+ AllOf (WithMotionAction (BUTTON_PRESS),
287+ WithActionButton (AMOTION_EVENT_BUTTON_PRIMARY),
288+ WithButtonState (AMOTION_EVENT_BUTTON_PRIMARY),
289+ WithZeroAxis (AXIS_RELATIVE_X),
290+ WithZeroAxis (AXIS_RELATIVE_Y), WithPressure (1 .0f )))));
291+
292+ // Move some more and release the button
293+ args.clear ();
294+ args += process (EV_REL, REL_X, 10 );
295+ args += process (EV_REL, REL_Y, -5 );
296+ args += process (EV_KEY, BTN_LEFT, 0 );
297+ args += process (EV_SYN, SYN_REPORT, 0 );
298+ ASSERT_THAT (args,
299+ ElementsAre (VariantWith<NotifyMotionArgs>(
300+ AllOf (WithMotionAction (ACTION_MOVE),
301+ WithButtonState (AMOTION_EVENT_BUTTON_PRIMARY),
302+ WithPositiveAxis (AXIS_RELATIVE_X),
303+ WithNegativeAxis (AXIS_RELATIVE_Y), WithPressure (1 .0f ))),
304+ VariantWith<NotifyMotionArgs>(
305+ AllOf (WithMotionAction (BUTTON_RELEASE),
306+ WithActionButton (AMOTION_EVENT_BUTTON_PRIMARY),
307+ WithButtonState (0 ), WithZeroAxis (AXIS_RELATIVE_X),
308+ WithZeroAxis (AXIS_RELATIVE_Y), WithPressure (0 .0f ))),
309+ VariantWith<NotifyMotionArgs>(
310+ AllOf (WithMotionAction (ACTION_UP), WithButtonState (0 ),
311+ WithZeroAxis (AXIS_RELATIVE_X),
312+ WithZeroAxis (AXIS_RELATIVE_Y), WithPressure (0 .0f ))),
313+ VariantWith<NotifyMotionArgs>(
314+ AllOf (WithMotionAction (HOVER_MOVE), WithButtonState (0 ),
315+ WithZeroAxis (AXIS_RELATIVE_X),
316+ WithZeroAxis (AXIS_RELATIVE_Y), WithPressure (0 .0f )))));
317+ }
318+
264319/* *
265320 * Test that enabling mouse swap primary button will have the left click result in a
266321 * `SECONDARY_BUTTON` event and a right click will result in a `PRIMARY_BUTTON` event.
@@ -539,12 +594,15 @@ TEST_F(CursorInputMapperUnitTest, ProcessShouldHandleCombinedXYAndButtonUpdates)
539594 args += process (ARBITRARY_TIME, EV_KEY, BTN_MOUSE, 1 );
540595 args += process (ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0 );
541596 EXPECT_THAT (args,
542- ElementsAre (VariantWith<NotifyMotionArgs>(WithMotionAction (ACTION_DOWN)),
543- VariantWith<NotifyMotionArgs>(WithMotionAction (BUTTON_PRESS))));
544- EXPECT_THAT (args,
545- Each (VariantWith<NotifyMotionArgs>(AllOf (WithPositiveAxis (AXIS_X),
546- WithNegativeAxis (AXIS_Y),
547- WithPressure (1 .0f )))));
597+ ElementsAre (VariantWith<NotifyMotionArgs>(
598+ AllOf (WithMotionAction (ACTION_MOVE), WithPressure (0 .0f ),
599+ WithPositiveAxis (AXIS_X), WithNegativeAxis (AXIS_Y))),
600+ VariantWith<NotifyMotionArgs>(
601+ AllOf (WithMotionAction (ACTION_DOWN), WithPressure (1 .0f ),
602+ WithZeroAxis (AXIS_X), WithZeroAxis (AXIS_Y))),
603+ VariantWith<NotifyMotionArgs>(
604+ AllOf (WithMotionAction (BUTTON_PRESS), WithPressure (1 .0f ),
605+ WithZeroAxis (AXIS_X), WithZeroAxis (AXIS_Y)))));
548606 args.clear ();
549607
550608 // Move X, Y a bit while pressed.
@@ -780,11 +838,9 @@ TEST_F(CursorInputMapperUnitTest, ProcessShouldHandleAllButtonsWithZeroCoords) {
780838 args += process (ARBITRARY_TIME, EV_KEY, BTN_RIGHT, 0 );
781839 args += process (ARBITRARY_TIME, EV_SYN, SYN_REPORT, 0 );
782840 EXPECT_THAT (args,
783- ElementsAre (VariantWith<NotifyMotionArgs>(WithMotionAction (BUTTON_RELEASE)),
784- VariantWith<NotifyMotionArgs>(WithMotionAction (ACTION_MOVE))));
785- EXPECT_THAT (args,
786- Each (VariantWith<NotifyMotionArgs>(
787- AllOf (WithButtonState (AMOTION_EVENT_BUTTON_TERTIARY),
841+ ElementsAre (VariantWith<NotifyMotionArgs>(
842+ AllOf (WithMotionAction (BUTTON_RELEASE),
843+ WithButtonState (AMOTION_EVENT_BUTTON_TERTIARY),
788844 WithCoords (0 .0f , 0 .0f ), WithPressure (1 .0f )))));
789845 args.clear ();
790846
@@ -817,10 +873,6 @@ TEST_P(CursorInputMapperButtonKeyTest, ProcessShouldHandleButtonKeyWithZeroCoord
817873 EXPECT_THAT (args,
818874 ElementsAre (VariantWith<NotifyKeyArgs>(AllOf (WithKeyAction (AKEY_EVENT_ACTION_DOWN),
819875 WithKeyCode (expectedKeyCode))),
820- VariantWith<NotifyMotionArgs>(
821- AllOf (WithMotionAction (HOVER_MOVE),
822- WithButtonState (expectedButtonState),
823- WithCoords (0 .0f , 0 .0f ), WithPressure (0 .0f ))),
824876 VariantWith<NotifyMotionArgs>(
825877 AllOf (WithMotionAction (BUTTON_PRESS),
826878 WithButtonState (expectedButtonState),
@@ -833,9 +885,6 @@ TEST_P(CursorInputMapperButtonKeyTest, ProcessShouldHandleButtonKeyWithZeroCoord
833885 ElementsAre (VariantWith<NotifyMotionArgs>(
834886 AllOf (WithMotionAction (BUTTON_RELEASE), WithButtonState (0 ),
835887 WithCoords (0 .0f , 0 .0f ), WithPressure (0 .0f ))),
836- VariantWith<NotifyMotionArgs>(
837- AllOf (WithMotionAction (HOVER_MOVE), WithButtonState (0 ),
838- WithCoords (0 .0f , 0 .0f ), WithPressure (0 .0f ))),
839888 VariantWith<NotifyKeyArgs>(AllOf (WithKeyAction (AKEY_EVENT_ACTION_UP),
840889 WithKeyCode (expectedKeyCode)))));
841890}
0 commit comments