From 9ca836d1ea17af8888e89925750447996c9860ff Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Fri, 24 Sep 2021 13:14:08 -0400 Subject: [PATCH] Tools: Respect system drag Also remove the time-based aspect. We aren't all super speed clickers. Fixes: https://gitlab.com/kicad/code/kicad/-/issues/8765 --- common/tool/tool_dispatcher.cpp | 42 ++++++++++++++++----------------- include/tool/tool_dispatcher.h | 6 +++++ 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp index 2382e81ffd..26e69d1477 100644 --- a/common/tool/tool_dispatcher.cpp +++ b/common/tool/tool_dispatcher.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include @@ -52,7 +53,6 @@ struct TOOL_DISPATCHER::BUTTON_STATE const wxEventType& aUpEvent, const wxEventType& aDblClickEvent ) : dragging( false ), pressed( false ), - dragMaxDelta( 0.0f ), button( aButton ), downEvent( aDownEvent ), upEvent( aUpEvent ), @@ -71,10 +71,6 @@ struct TOOL_DISPATCHER::BUTTON_STATE ///< Point where click event has occurred. VECTOR2D downPosition; - ///< Difference between drag origin point and current mouse position (expressed as distance in - ///< pixels). - double dragMaxDelta; - ///< Determines the mouse button for which information are stored. TOOL_MOUSE_BUTTONS button; @@ -126,6 +122,12 @@ struct TOOL_DISPATCHER::BUTTON_STATE TOOL_DISPATCHER::TOOL_DISPATCHER( TOOL_MANAGER* aToolMgr ) : m_toolMgr( aToolMgr ) { + m_sysDragMinX = wxSystemSettings::GetMetric( wxSYS_DRAG_X ); + m_sysDragMinY = wxSystemSettings::GetMetric( wxSYS_DRAG_Y ); + + m_sysDragMinX = m_sysDragMinX != -1 ? m_sysDragMinX : DragDistanceThreshold; + m_sysDragMinY = m_sysDragMinY != -1 ? m_sysDragMinY : DragDistanceThreshold; + m_buttons.push_back( new BUTTON_STATE( BUT_LEFT, wxEVT_LEFT_DOWN, wxEVT_LEFT_UP, wxEVT_LEFT_DCLICK ) ); m_buttons.push_back( new BUTTON_STATE( BUT_RIGHT, wxEVT_RIGHT_DOWN, @@ -192,7 +194,6 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti st->dragOrigin = m_lastMousePos; st->downPosition = m_lastMousePos; - st->dragMaxDelta = 0; st->pressed = true; evt = TOOL_EVENT( TC_MOUSE, TA_MOUSE_DOWN, args ); } @@ -201,16 +202,7 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti st->pressed = false; if( st->dragging ) - { - wxLongLong t = wxGetLocalTimeMillis(); - - // Determine if it was just a single click or beginning of dragging - if( t - st->downTimestamp < DragTimeThreshold && - st->dragMaxDelta < DragDistanceThreshold ) - isClick = true; - else - evt = TOOL_EVENT( TC_MOUSE, TA_MOUSE_UP, args ); - } + evt = TOOL_EVENT( TC_MOUSE, TA_MOUSE_UP, args ); else isClick = true; @@ -226,14 +218,20 @@ bool TOOL_DISPATCHER::handleMouseButton( wxEvent& aEvent, int aIndex, bool aMoti if( st->pressed && aMotion ) { - st->dragging = true; - double dragPixelDistance = - getView()->ToScreen( m_lastMousePos - st->dragOrigin, false ).EuclideanNorm(); - st->dragMaxDelta = std::max( st->dragMaxDelta, dragPixelDistance ); + if( !st->dragging ) + { +#ifdef __WXMAC__ + if( wxGetLocalTimeMillis() - st->downTimestamp > DragTimeThreshold ) + st->dragging = true; +#else + VECTOR2D offset = getView()->ToScreen( m_lastMousePos - st->dragOrigin, false ); - wxLongLong t = wxGetLocalTimeMillis(); + if( abs( offset.x ) > m_sysDragMinX || abs( offset.y ) > m_sysDragMinY ) + st->dragging = true; +#endif + } - if( t - st->downTimestamp > DragTimeThreshold || st->dragMaxDelta > DragDistanceThreshold ) + if( st->dragging ) { evt = TOOL_EVENT( TC_MOUSE, TA_MOUSE_DRAG, args ); evt->setMouseDragOrigin( st->dragOrigin ); diff --git a/include/tool/tool_dispatcher.h b/include/tool/tool_dispatcher.h index 95bccac563..5ef74100b6 100644 --- a/include/tool/tool_dispatcher.h +++ b/include/tool/tool_dispatcher.h @@ -86,8 +86,14 @@ private: ///< The distance threshold for mouse cursor that distinguishes between a single mouse click ///< and a beginning of drag event (expressed in screen pixels). + ///< System drag preferences take precedence if available static const int DragDistanceThreshold = 8; + ///< Mininum distance before drag is activated in the X axis + int m_sysDragMinX; + ///< Maximum distance before drag is activated in the Y axis + int m_sysDragMinY; + ///< Handles mouse related events (click, motion, dragging). bool handleMouseButton( wxEvent& aEvent, int aIndex, bool aMotion );