When scrolling on a wxGLCanvas on wxGTK with X11 (I have not tested wayland/xwayland), the canvas gets duplicated scroll events:
GetWheelRotation()
values are sent (representing the smooth touchpad scroll), but occasionally (maybe twice a second when scrolling slowly) events with a full rotation of 120
are sent as well.This makes it hard to implement smooth custom scrolling behavior on a wxGLCanvas.
This issue seems to be specific to wxGLCanvas, it does not seem to happen with other windows.
The following diff can be used to patch the example problems to log the events to stdout:
diff --git a/samples/opengl/pyramid/pyramid.cpp b/samples/opengl/pyramid/pyramid.cpp index ae953eb474..5be419773b 100644 --- a/samples/opengl/pyramid/pyramid.cpp +++ b/samples/opengl/pyramid/pyramid.cpp @@ -379,6 +379,7 @@ wxBEGIN_EVENT_TABLE(MyGLCanvas, wxGLCanvas) EVT_PAINT(MyGLCanvas::OnPaint) EVT_SIZE(MyGLCanvas::OnSize) EVT_MOUSE_EVENTS(MyGLCanvas::OnMouse) + EVT_MOUSEWHEEL(MyGLCanvas::OnScroll) wxEND_EVENT_TABLE() //We create a wxGLContext in this constructor. @@ -595,3 +596,8 @@ void MyGLCanvas::OnMouse(wxMouseEvent& event) } } +void MyGLCanvas::OnScroll(wxMouseEvent &event) +{ + printf("Scroll by %d\n", event.GetWheelRotation()); +} + diff --git a/samples/opengl/pyramid/pyramid.h b/samples/opengl/pyramid/pyramid.h index 7f84b22a79..13fff57368 100644 --- a/samples/opengl/pyramid/pyramid.h +++ b/samples/opengl/pyramid/pyramid.h @@ -64,6 +64,7 @@ public: void OnPaint(wxPaintEvent& event); void OnSize(wxSizeEvent& event); void OnMouse(wxMouseEvent& event); + void OnScroll(wxMouseEvent& event); private: // Members diff --git a/samples/scroll/scroll.cpp b/samples/scroll/scroll.cpp index c709332286..e8ab0505dc 100644 --- a/samples/scroll/scroll.cpp +++ b/samples/scroll/scroll.cpp @@ -704,11 +704,12 @@ void MyCanvas::OnMouseWheel( wxMouseEvent &event ) wxPoint pt( event.GetPosition() ); int x,y; CalcUnscrolledPosition( pt.x, pt.y, &x, &y ); - wxLogMessage( "Mouse wheel event at: %d %d, scrolled: %d %d\n" - "Rotation: %d, delta: %d, inverted: %d", - pt.x, pt.y, x, y, - event.GetWheelRotation(), event.GetWheelDelta(), - event.IsWheelInverted() ); + printf("Scroll by %d\n", event.GetWheelRotation()); + // wxLogMessage( "Mouse wheel event at: %d %d, scrolled: %d %d\n" + // "Rotation: %d, delta: %d, inverted: %d", + // pt.x, pt.y, x, y, + // event.GetWheelRotation(), event.GetWheelDelta(), + // event.IsWheelInverted() ); event.Skip(); }
samples/scroll/scroll
and open Test > Scrolled window with childrensamples/scroll/scroll
and open samples/opengl/pyramid/pyramid
For step 3), observe that scroll events are sent as normal:
3a):
[scroll the mouse wheel one discrete step]
Scroll by -120
[scroll the mouse wheel one discrete step]
Scroll by -120
[scroll the mouse wheel one discrete step]
Scroll by -120
3b):
Scroll by -9
Scroll by -17
Scroll by -17
Scroll by -25
Scroll by -29
Scroll by -34
[...]
For step 5), observe the duplicate scroll events:
5a):
[scroll the mouse wheel one discrete step]
Scroll by -120
[scroll the mouse wheel one discrete step]
Scroll by -120
Scroll by -120
[scroll the mouse wheel one discrete step]
Scroll by -120
Scroll by -120
5b):
Scroll by 3
Scroll by 3
Scroll by 3
Scroll by 3
Scroll by 3
Scroll by 3
Scroll by -3
Scroll by 1
Scroll by -4
Scroll by -4
Scroll by -6
Scroll by -3
Scroll by -4
Scroll by -3
Scroll by -6
Scroll by 1
Scroll by -3
Scroll by -6
Scroll by -3
Scroll by -6
Scroll by -3
Scroll by -6
Scroll by -6
Scroll by -3
Scroll by -6
Scroll by -3
Scroll by -1
Scroll by -1
Scroll by -1
Scroll by -3
Scroll by -1
Scroll by -1
Scroll by -1
Scroll by -1
Scroll by -120 [ <----- note this extra event ]
Scroll by 1
Scroll by -3
Scroll by -1
Scroll by -4
Scroll by -3
Scroll by -6
It seems that wxGTK sends only GDK_SCROLL_SMOOTH
events to normal windows, but sends both GDK_SCROLL_SMOOTH
and GDK_SCROLL_{UP,DOWN,LEFT,RIGHT}
events to wxGLCanvases. wxWidgets then converts both of these to the same scroll events (which, unfortunately, makes it hard to distinguish them and drop the duplicate ones).
I'm not yet sure if the bug is in wxWidgets or in gtk, or even in x11, and I also don't know why it's specific to wxGLCanvases, but I'm stopping to open this issue before investigating further.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
Thanks for the analysis! I guess we'll have to ignore either GDK_SCROLL_SMOOTH
or all the other GDK scroll events in wxGLCanvas
, right? And, if so, which ones are more "valuable"? Again, I'd guess it would be GDK_SCROLL_SMOOTH
ones, but I haven't tested this yet.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
I had the chance to test on wayland now, and it does not seem to happen there (except with GDK_BACKEND=x11
). So it looks like this indeed comes all the way from x11.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.