GNOME Bugzilla – Bug 789218
gtk_gesture_get_last_event() missing (nullable) annotation for GDKEventSequence arg
Last modified: 2018-05-02 19:20:58 UTC
In Maps I've tried to implement support for bringing up the context menu on long-press on the view on touch screens with the following code: this._longPressGesture = new Gtk.GestureLongPress({ widget: this._mapView }); this._longPressGesture.connect('pressed', (function(gesture, x, y) { Mainloop.idle_add((function() { let sequence = gesture.get_last_updated_sequence(); this.popup_at_pointer(gesture.get_last_event(sequence)); }).bind(this)); }).bind(this)); (the idle_add call is to avoid event lock-ups in Clutter). This currently gives a GIR error as the @sequence argument for gtk_gesture_get_last_event() is not annotated with null, even though gtk_gesture_get_last_updated_sequence() can return null. Adding the correct GIR annotation in gtkgesture.c fixes this.
Created attachment 361902 [details] [review] GtkGesture: Add (nullable) on argument for _get_last_event() gtk_gesture_get_last_event() lacks a (nullable) annotation for the sequence parameter, even though it can in some circumstances be null.
If the parameter is nullable, the docs should say what a NULL value means.
(In reply to Timm Bäder from comment #2) > If the parameter is nullable, the docs should say what a NULL value means. Good point. I guess the return of gtk_gesture_get_last_updated_sequence() should also mention the possible null return and what it implies.
Are we sure that the given use case is supported, i.e. that we want to formally make @sequence nullable - rather than requiring the user to check whether get_last_updated_sequence() returns NULL and not call get_last_event() if so?
(In reply to Daniel Boles from comment #4) > Are we sure that the given use case is supported, i.e. that we want to > formally make @sequence nullable - rather than requiring the user to check > whether get_last_updated_sequence() returns NULL and not call > get_last_event() if so? OK, maybe not. But in that case, is the code-snippet above the wrong approach? Or how would I get hold of the event triggering the gesture. Or hmm, maybe .popup_at_pointer() should be called with null as the event in that case (the docs says "NULL if it's the current event".
if get_last_updated_sequence returns NULL, that certainly means there is no event sequence to get the last event from...
Matthias, not true, at least in the case of GtkGestureDrag, which returns a perfectly good event from gtk_gesture_get_last_event inside the drag-begin handler even though the current sequence is NULL. Without a nullable annotation on functions that accept GDKEventSequence arguments, there is no way for language bindings to use the gesture facility correctly.
And FWIW, in this context, gtk_gesture_get_sequences() returns a list with a single NULL element. Either NULL needs to be acknowledged as a valid sequence identifier or the gesture code needs to be modified to return some non-NULL sentinel in this context.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/955.