wxGTK: GTK3 gesture cancellation results in spurious GestureEnd events (Issue #26211)

4 views
Skip to first unread message

filip-hejsek

unread,
8:31 AM (14 hours ago) 8:31 AM
to wx-...@googlegroups.com, Subscribed
filip-hejsek created an issue (wxWidgets/wxWidgets#26211)

Description

Bug description:

Spurious gesture end events are generated whenever wxGTK receives a Gtk.Gesture::cancel signal.

GTK3 sometimes generates cancel signals even if no gesture is active, for example when a grab is started.

I have also observed GTK3 generating both a cancel and an end signal for a gesture, resulting in a duplicate wxWidgets GestureEnd event.

The cause of the problem is that wxGTK registers the same handler for both Gtk.Gesture::cancel and Gtk.Gesture::end, and doesn't check if a gesture is active before dispatching a wx event:

https://github.com/wxWidgets/wxWidgets/blob/11e5cae93a57bf3c31011c32d3e47bbca7cacea8/src/gtk/window.cpp#L4046-L4049

Observed behaviour:

When a menu is opened by calling PopupMenu(), a spurious wxGestureEvent with IsGestureEnd() == true is dispatched in response to a Gtk.Gesture::cancel signal.

Expected behaviour:

No gesture end events dispatched when gesture isn't active.

Patch or snippet allowing to reproduce the problem:

diff --git a/samples/event/gestures.cpp b/samples/event/gestures.cpp
index e58227358a..ff5a1faee1 100644
--- a/samples/event/gestures.cpp
+++ b/samples/event/gestures.cpp
@@ -144,6 +144,12 @@ MyGestureFrame::MyGestureFrame()
     myPanel->Bind(wxEVT_LONG_PRESS, &MyGestureFrame::OnGesture, this);
     myPanel->Bind(wxEVT_PRESS_AND_TAP, &MyGestureFrame::OnGesture, this);
 
+    myPanel->Bind(wxEVT_CONTEXT_MENU, [myPanel](auto &) {
+        wxMenu menu;
+        menu.Append(wxID_ANY, "Menu Item");
+        myPanel->PopupMenu(&menu);
+    });
+
     Bind(wxEVT_CLOSE_WINDOW, &MyGestureFrame::OnQuit, this);
 }

To Reproduce:

  1. Build and run the event sample with the above patch
  2. Open the Gesture events window (Ctrl+G)
  3. Right click to open context menu
  4. See output like this in the event log:
    14:29:33: Zoom gesture performed with zoom center at (0, 0) and zoom Factor = 1.000000
    14:29:33: Zoom gesture ended
    14:29:33: Rotate gesture performed with rotation center at (0, 0) and cumulative rotation angle = 0.000000
    14:29:33: Rotate gesture ended
    

Platform and version information

  • wxWidgets version: master (11e5cae)
  • wxWidgets port: wxGTK
  • OS: Arch Linux
    • GTK version: 3.24.51
    • GDK backend: Wayland
    • Desktop environment: GNOME


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26211@github.com>

VZ

unread,
8:43 AM (14 hours ago) 8:43 AM
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#26211)

It looks like this should be relatively simple to fix, but I have no way to test it, so any patches would be very welcome!


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26211/3934769490@github.com>

filip-hejsek

unread,
9:02 AM (14 hours ago) 9:02 AM
to wx-...@googlegroups.com, Subscribed
filip-hejsek left a comment (wxWidgets/wxWidgets#26211)

I think I can do something like adding gs_zoomGestureActive and gs_rotateGestureActive and check them before dispatching the event.

But before I do that, can I ask why these are all global?

// This is true when the gesture has just started (currently used for pan gesture only)
static bool gs_gestureStart = false;

// Last offset for the pan gesture, this is used to calculate deltas for pan gesture event
static double gs_lastOffset = 0;

// Last scale provided by GTK
static gdouble gs_lastScale = 1.0;

// This is used to set the angle when rotate gesture ends.
static gdouble gs_lastAngle = 0;

// Last Zoom/Rotate gesture point
static wxPoint gs_lastGesturePoint;

It seems to me that sharing this state among all windows could cause problems, e.g. if I add gs_zoomGestureActive, then GTK cancelling a gesture in one window would set gs_zoomGestureActive to false, even though as I understand it a gesture in another window could still be active.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26211/3934961714@github.com>

VZ

unread,
9:06 AM (13 hours ago) 9:06 AM
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#26211)

This code was added back in 261b04b (Merge multi-touch gestures event branch, 2017-09-10) and I am not sure why it was done like this, but I guess it was the simplest solution and the original author thought that there could be only one gesture in progress at any time (which seems plausible but I'm not sure if this is actually true).


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26211/3935009936@github.com>

filip-hejsek

unread,
9:09 AM (13 hours ago) 9:09 AM
to wx-...@googlegroups.com, Subscribed
filip-hejsek left a comment (wxWidgets/wxWidgets#26211)

which seems plausible but I'm not sure if this is actually true

I don't really know. In my limited testing I wasn't able to trigger multiple gestures at once, but I'm not sure if I can rule it out in crazy situations like using a touchscreen and a touchpad at the same time, or using weird Wayland compositors.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/26211/3935037911@github.com>

Reply all
Reply to author
Forward
0 new messages