The question is simple: is it there an EventController or a Gesture class in Gtk3 that allows to manage single and double click events? I tried with Gtk.GestureSingle() but can’t find a constructor, and my tests in JavaScript do odd things, like returning a Gtk.ApplicationWindow instead of a GestureSingle object…
I ask because I have a Gtk3 code and want to port it to Gtk4, but being quite big I want to go step by step, migrating first code to things that work both in Gtk3 and Gtk4.
EDIT: I tried with clickGesture = new Gtk.GestureSingle(); and it returned a Gtk.GestureSingle object, but if I try to assign a window to it, I receive gtk_gesture_set_window: assertion 'window_widget == gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture))' failed (it is a Gdk.WaylandWindow obtained from the Gtk.ApplicationWindow, and it is realized).
GtkGestureSingle is not an instantiatable class; if you want to track pointer clicks in GTK3, you want GtkGestureMultiPress. The naming is unfortunate, which is why it was renamed to GtkGestureClick in GTK4.
Unlike GTK4, event controllers in GTK3 require a reference to the widget, so you must pass the widget property at construction time:
// Let's assume "this" is the widget you are implementing
this.gesture = new Gtk.GestureMultiPress({ widget: self });
this.gesture.set_button(Gdk.BUTTON_PRIMARY);
this.gesture.connect('pressed', this._onButtonPressed.bind(this));
this.gesture.connect('released', this._onButtonReleased.bind(this));
this.gesture.connect('update', this._onButtonUpdate.bind(this));
this.gesture.connect('cancel', this._onButtonCancel.bind(this));
This is horrifying; what are you actually trying to achieve? You don’t need to assign a window unless your widget has different GdkWindow instances for drawing and input.
Yes, it is horrible the reason was that passing a GTK.Window it showed an error, because it seems that it expected a gdk.Window. but I presume that the problem is that it wasn’t an instantiable class.