From 1f62a2d78447314bacacd278071cbeecbab4d176 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 5 Dec 2018 19:23:32 -0700 Subject: [PATCH] gtk3: prevent double scroll events GTK3 smooth scrolling is enabled by wxWidgets but not to the exclusion of normal scroll up/down events. wxWidgets maps these both to the same scroll handler and will fire them both if they are not handled before being queued. Testing timestamps allows us to mark and ignore the dupes. This is set to GTK3 only for now as it isn't listed as a problem for other platforms. But it shouldn't cause issues if it is enabled elsewhere in the future. --- common/view/wx_view_controls.cpp | 12 +++++++++++- include/view/wx_view_controls.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 7ed899165e..85e2ac8cc3 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -52,7 +52,7 @@ static std::unique_ptr GetZoomControllerForPlatform() WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, wxScrolledCanvas* aParentPanel ) : VIEW_CONTROLS( aView ), m_state( IDLE ), m_parentPanel( aParentPanel ), - m_scrollScale( 1.0, 1.0 ), m_cursorPos( 0, 0 ), m_updateCursor( true ) + m_scrollScale( 1.0, 1.0 ), m_lastTimestamp( 0 ), m_cursorPos( 0, 0 ), m_updateCursor( true ) { m_parentPanel->Connect( wxEVT_MOTION, wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), NULL, this ); @@ -133,6 +133,16 @@ void WX_VIEW_CONTROLS::onWheel( wxMouseEvent& aEvent ) { const double wheelPanSpeed = 0.001; +#ifdef __WXGTK3__ + if( aEvent.GetTimestamp() == m_lastTimestamp ) + { + aEvent.Skip( false ); + return; + } + + m_lastTimestamp = aEvent.GetTimestamp(); +#endif + // mousewheelpan disabled: // wheel + ctrl -> horizontal scrolling; // wheel + shift -> vertical scrolling; diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index d3b7d07335..755e69dee1 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -159,6 +159,9 @@ private: /// Current scrollbar position VECTOR2I m_scrollPos; + /// Last event timestamp to remove duplicates + long int m_lastTimestamp; + /// Current cursor position (world coordinates) VECTOR2D m_cursorPos;