@@ -531,6 +531,14 @@ namespace lvh::detail {
531531 CGEventType up_event {}; // /< CoreGraphics up event type.
532532 };
533533
534+ /* *
535+ * @brief CoreGraphics metadata for a mouse motion event.
536+ */
537+ struct MacosMouseMotion {
538+ CGMouseButton button {}; // /< CoreGraphics button associated with the motion.
539+ CGEventType event_type {}; // /< CoreGraphics motion event type.
540+ };
541+
534542 /* *
535543 * @brief Translate a portable mouse button to CoreGraphics metadata.
536544 *
@@ -555,6 +563,25 @@ namespace lvh::detail {
555563 return std::nullopt ;
556564 }
557565
566+ /* *
567+ * @brief Select CoreGraphics motion metadata for the currently held mouse buttons.
568+ *
569+ * @param mouse_down Local left, right, and middle button state.
570+ * @return Matching CoreGraphics button and motion event type.
571+ */
572+ inline MacosMouseMotion macos_mouse_motion (const std::array<bool , 3 > &mouse_down) {
573+ if (mouse_down[0 ]) {
574+ return {kCGMouseButtonLeft , kCGEventLeftMouseDragged };
575+ }
576+ if (mouse_down[1 ]) {
577+ return {kCGMouseButtonRight , kCGEventRightMouseDragged };
578+ }
579+ if (mouse_down[2 ]) {
580+ return {kCGMouseButtonCenter , kCGEventOtherMouseDragged };
581+ }
582+ return {kCGMouseButtonLeft , kCGEventMouseMoved };
583+ }
584+
558585 /* *
559586 * @brief Backend mouse backed by CoreGraphics mouse and scroll events.
560587 */
@@ -613,19 +640,6 @@ namespace lvh::detail {
613640 return current;
614641 }
615642
616- CGEventType event_type_for_current_buttons () const {
617- if (mouse_down_[0 ]) {
618- return kCGEventLeftMouseDragged ;
619- }
620- if (mouse_down_[1 ]) {
621- return kCGEventOtherMouseDragged ;
622- }
623- if (mouse_down_[2 ]) {
624- return kCGEventRightMouseDragged ;
625- }
626- return kCGEventMouseMoved ;
627- }
628-
629643 OperationStatus post_mouse (
630644 CGMouseButton button,
631645 CGEventType type,
@@ -660,13 +674,15 @@ namespace lvh::detail {
660674 OperationStatus submit_relative_motion (std::int32_t delta_x, std::int32_t delta_y) {
661675 const auto current = current_location ();
662676 const auto location = CGPoint {current.x + delta_x, current.y + delta_y};
663- return post_mouse (kCGMouseButtonLeft , event_type_for_current_buttons (), location, current, 0 );
677+ const auto motion = macos_mouse_motion (mouse_down_);
678+ return post_mouse (motion.button , motion.event_type , location, current, 0 );
664679 }
665680
666681 OperationStatus submit_absolute_motion (const MouseEvent &event) {
667682 const auto display_bounds = CGDisplayBounds (state_->display );
668683 const auto location = absolute_mouse_location (event, display_bounds);
669- return post_mouse (kCGMouseButtonLeft , event_type_for_current_buttons (), location, current_location (), 0 );
684+ const auto motion = macos_mouse_motion (mouse_down_);
685+ return post_mouse (motion.button , motion.event_type , location, current_location (), 0 );
670686 }
671687
672688 OperationStatus submit_button (const MouseEvent &event) {
0 commit comments