@@ -609,32 +609,78 @@ TEST_F(LinuxBackendTest, PipeBackedUinputMouseEmitsEvents) {
609609 event.high_resolution_scroll = 120 ;
610610 result = lvh::detail::test::linux_uinput_mouse_submit_pipe (event);
611611 ASSERT_TRUE (result.status .ok ()) << result.status .message ();
612- ASSERT_EQ (result.events .size (), 2U );
613- EXPECT_EQ (result.events [0 ].type , EV_REL );
614612#if defined(REL_WHEEL_HI_RES)
615- EXPECT_EQ (result.events [0 ].code , REL_WHEEL_HI_RES );
616- EXPECT_EQ (result.events [0 ].value , 120 );
613+ constexpr auto expected_vertical_scroll_event_count = 3U ;
617614#else
615+ constexpr auto expected_vertical_scroll_event_count = 2U ;
616+ #endif
617+ ASSERT_EQ (result.events .size (), expected_vertical_scroll_event_count);
618+ EXPECT_EQ (result.events [0 ].type , EV_REL );
618619 EXPECT_EQ (result.events [0 ].code , REL_WHEEL );
619620 EXPECT_EQ (result.events [0 ].value , 1 );
621+ #if defined(REL_WHEEL_HI_RES)
622+ EXPECT_EQ (result.events [1 ].type , EV_REL );
623+ EXPECT_EQ (result.events [1 ].code , REL_WHEEL_HI_RES );
624+ EXPECT_EQ (result.events [1 ].value , 120 );
620625#endif
621- EXPECT_EQ (result.events [ 1 ] .type , EV_SYN );
626+ EXPECT_EQ (result.events . back () .type , EV_SYN );
622627
623628 event = {};
624629 event.kind = lvh::MouseEventKind::horizontal_scroll;
625630 event.high_resolution_scroll = -120 ;
626631 result = lvh::detail::test::linux_uinput_mouse_submit_pipe (event);
627632 ASSERT_TRUE (result.status .ok ()) << result.status .message ();
628- ASSERT_EQ (result.events .size (), 2U );
629- EXPECT_EQ (result.events [0 ].type , EV_REL );
630633#if defined(REL_HWHEEL_HI_RES)
631- EXPECT_EQ (result.events [0 ].code , REL_HWHEEL_HI_RES );
632- EXPECT_EQ (result.events [0 ].value , -120 );
634+ constexpr auto expected_horizontal_scroll_event_count = 3U ;
633635#else
636+ constexpr auto expected_horizontal_scroll_event_count = 2U ;
637+ #endif
638+ ASSERT_EQ (result.events .size (), expected_horizontal_scroll_event_count);
639+ EXPECT_EQ (result.events [0 ].type , EV_REL );
634640 EXPECT_EQ (result.events [0 ].code , REL_HWHEEL );
635641 EXPECT_EQ (result.events [0 ].value , -1 );
642+ #if defined(REL_HWHEEL_HI_RES)
643+ EXPECT_EQ (result.events [1 ].type , EV_REL );
644+ EXPECT_EQ (result.events [1 ].code , REL_HWHEEL_HI_RES );
645+ EXPECT_EQ (result.events [1 ].value , -120 );
636646#endif
637- EXPECT_EQ (result.events [1 ].type , EV_SYN );
647+ EXPECT_EQ (result.events .back ().type , EV_SYN );
648+ }
649+
650+ TEST_F (LinuxBackendTest, PipeBackedUinputMouseAccumulatesLegacyScrollDetentsPerAxis) {
651+ const std::vector<lvh::MouseEvent> events {
652+ {.kind = lvh::MouseEventKind::vertical_scroll, .high_resolution_scroll = 60 },
653+ {.kind = lvh::MouseEventKind::horizontal_scroll, .high_resolution_scroll = -60 },
654+ {.kind = lvh::MouseEventKind::vertical_scroll, .high_resolution_scroll = 60 },
655+ {.kind = lvh::MouseEventKind::horizontal_scroll, .high_resolution_scroll = -60 },
656+ };
657+ const auto result = lvh::detail::test::linux_uinput_mouse_submit_pipe_sequence (events);
658+ ASSERT_TRUE (result.status .ok ()) << result.status .message ();
659+
660+ const auto event_values = [&result](std::uint16_t code) {
661+ std::vector<std::int32_t > values;
662+ for (const auto &event : result.events ) {
663+ if (event.type == EV_REL && event.code == code) {
664+ values.push_back (event.value );
665+ }
666+ }
667+ return values;
668+ };
669+
670+ EXPECT_EQ (event_values (REL_WHEEL ), (std::vector<std::int32_t > {1 }));
671+ EXPECT_EQ (event_values (REL_HWHEEL ), (std::vector<std::int32_t > {-1 }));
672+ #if defined(REL_WHEEL_HI_RES)
673+ EXPECT_EQ (event_values (REL_WHEEL_HI_RES ), (std::vector<std::int32_t > {60 , 60 }));
674+ #endif
675+ #if defined(REL_HWHEEL_HI_RES)
676+ EXPECT_EQ (event_values (REL_HWHEEL_HI_RES ), (std::vector<std::int32_t > {-60 , -60 }));
677+ #endif
678+ EXPECT_EQ (
679+ std::ranges::count_if (result.events , [](const auto &event) {
680+ return event.type == EV_SYN && event.code == SYN_REPORT ;
681+ }),
682+ 4
683+ );
638684}
639685
640686TEST_F (LinuxBackendTest, PipeBackedUinputTouchDevicesEmitEvents) {
@@ -1129,6 +1175,14 @@ TEST_F(LinuxBackendTest, FakeUinputConstructionCoversCapabilitiesAndFailureBranc
11291175 EXPECT_TRUE (has_type (mouse, EV_ABS ));
11301176 EXPECT_NE (find_code (mouse, EV_KEY , BTN_LEFT ), nullptr );
11311177 EXPECT_NE (find_code (mouse, EV_REL , REL_X ), nullptr );
1178+ EXPECT_NE (find_code (mouse, EV_REL , REL_WHEEL ), nullptr );
1179+ EXPECT_NE (find_code (mouse, EV_REL , REL_HWHEEL ), nullptr );
1180+ #if defined(REL_WHEEL_HI_RES)
1181+ EXPECT_NE (find_code (mouse, EV_REL , REL_WHEEL_HI_RES ), nullptr );
1182+ #endif
1183+ #if defined(REL_HWHEEL_HI_RES)
1184+ EXPECT_NE (find_code (mouse, EV_REL , REL_HWHEEL_HI_RES ), nullptr );
1185+ #endif
11321186 const auto *mouse_x = find_code (mouse, EV_ABS , ABS_X );
11331187 ASSERT_NE (mouse_x, nullptr );
11341188 EXPECT_TRUE (mouse_x->has_absinfo );
0 commit comments