If I have a GtkGestureDrag, how can i distinguish inside the "drag-end" signal handler between it being called because the dragging ended normally or because gtk_event_controller_reset() was called?
In both cases gtk_gesture_is_active() and gtk_gesture_is_recognized() return FALSE.
The use-case here is to be able to “reject” or cancel the drag gesture. I see that GtkGesture has a "cancel" signal for this, but it would be useful to know whether this happened directly from the gesture inside its other signal handlers.
GtkGesture::cancel is the generic way to get notified about that. I’m not sure if we could make this state API (or one that is not with a big “use only inside ::end/::cancel” note).
I understand though that peeking for low level signals is not great, subclasses can help abstract this away too. Maybe having a GtkGestureDrag::drag-cancelled that is mutually exclusive with ::drag-end might work better?
That would work better as otherwise the application would have to keep state around to distinguish these two cases, or having some boolean stored inside the gesture to distinguish that.
The gesture already stores the start point and end point, whether it’s active / recognized. It would seem like a useless complication for applications if all they need to know is already stored inside the gesture apart from the information whether the gesture finished successfully or was cancelled.
To give some more background, I’m currently storing the GtkGestureDrag in my application state and whenever I’m rendering I check if it’s active and in that case render a rectangle based on the start/offset the gesture keeps track of.
Then when the gesture is actually finished in drag-end I would like to make the operation connected to that gesture happen, but only if it was not cancelled. Right now I would need to keep another boolean around in addition to the gesture to do this, while all the other information I need is actually stored inside the gesture already.
I was about to propose a was_cancelled() method. For GTK4 there’s even the option of adding a boolean was_cancelled argument to the drag-end signal, if we don’t want out of band methods.
Yeah that’s what I meant with “or having some boolean stored inside the gesture to distinguish that”. That would work equally well for me and seems consistent with the other getters on the gestures.