Skip to content

Ignore gesture events when zoom gesture isn't active#544

Merged
arch1t3cht merged 1 commit intoTypesettingTools:masterfrom
filip-hejsek:zoom_gesture_fix
Feb 20, 2026
Merged

Ignore gesture events when zoom gesture isn't active#544
arch1t3cht merged 1 commit intoTypesettingTools:masterfrom
filip-hejsek:zoom_gesture_fix

Conversation

@filip-hejsek
Copy link
Contributor

On wxGTK+Wayland, right-clicking sends the last GestureEnd event again, which was not caught by the existing workaround.

Instead of trying to pattern-match the false events, let's ignore all events unless we received a GestureStart event first.

(This has a merge conflict with #542. If you merge #542 first, you can use 5548e10. If you merge this first, I will rebase #542.)

@filip-hejsek
Copy link
Contributor Author

I also got a minimal example that reproduces the bug:

#include <wx/wx.h>

class MyApp : public wxApp {
public:
	virtual bool OnInit() {
		auto frame = new wxFrame(NULL, wxID_ANY, "Zoom Gesture Test", wxDefaultPosition, wxSize(300, 200));

		auto myControl = new wxControl(frame, wxID_ANY);
		myControl->EnableTouchEvents(wxTOUCH_ZOOM_GESTURE);

		myControl->Bind(wxEVT_GESTURE_ZOOM, [](auto &event) {
			wxLogDebug("Zoom Gesture%s at (%d, %d) zoom factor %f",
			           event.IsGestureStart() ? " Start" : event.IsGestureEnd() ? " End" : "",
			           event.GetPosition().x, event.GetPosition().y, event.GetZoomFactor());
		});

		myControl->Bind(wxEVT_CONTEXT_MENU, [myControl](auto &) {
			wxMenu menu;
			menu.Append(wxID_ANY, "Menu Item");
			myControl->PopupMenu(&menu);
		});

		frame->Show();

		return true;
	}
};

wxIMPLEMENT_APP(MyApp);

@filip-hejsek
Copy link
Contributor Author

And I found the culprit:

        g_signal_connect (m_zoom_gesture, "begin",
                          G_CALLBACK(zoom_gesture_begin_callback), win);
        g_signal_connect (m_zoom_gesture, "scale-changed",
                          G_CALLBACK(zoom_gesture_callback), win);
        g_signal_connect (m_zoom_gesture, "end",
                          G_CALLBACK(zoom_gesture_end_callback), win);
        g_signal_connect (m_zoom_gesture, "cancel",
                          G_CALLBACK(zoom_gesture_end_callback), win);

wxWidgets treats cancel events the same as end events, and always generates a GestureEnd event for them. But GTK can send cancel events even when a gesture isn't active (and can also send both a cancel and an end event for a gesture).

@arch1t3cht
Copy link
Member

Thanks for debugging this. In that case I'd like to report this upstream first so that the relevant github issue can be linked in a code comment (so future developer can more easily tell whether the issue is still present or has since been fixed).

I'll do that soon unless you want to do it yourself.

@filip-hejsek
Copy link
Contributor Author

On wxGTK+Wayland, right-clicking sends the last GestureEnd event again,
which was not caught by the existing workaround.

Instead of trying to pattern-match the false events, let's ignore all
events unless we received a GestureStart event first.
@filip-hejsek
Copy link
Contributor Author

Rebased and added the link to the comment.

@arch1t3cht
Copy link
Member

Thanks!

@arch1t3cht arch1t3cht merged commit 7597e4c into TypesettingTools:master Feb 20, 2026
7 checks passed
@filip-hejsek filip-hejsek deleted the zoom_gesture_fix branch February 20, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants