Package: gtk

Class gtk-gesture

Superclasses

gtk-event-controller, g-object, common-lisp:standard-object, common-lisp:t

Documented Subclasses

Direct Slots

n-points
The n-points property of type :int (Read / Write)
The number of touch points that trigger recognition on this gesture.
Allowed values: >= 1
Default value: 1
window
The window property of type GdkWindow (Read / Write)
If non-nil, the gesture will only listen for events that happen on this gdk-window, or a child of it.

Details

gtk-gesture is the base object for gesture recognition, although this object is quite generalized to serve as a base for multi-touch gestures, it is suitable to implement single-touch and pointer-based gestures (using the special nil gdk-event-sequence value for these).

The number of touches that a gtk-gesture need to be recognized is controlled by the n-points property, if a gesture is keeping track of less or more than that number of sequences, it won't check whether the gesture is recognized.

As soon as the gesture has the expected number of touches, the gesture will run the "check" signal regularly on input events until the gesture is recognized, the criteria to consider a gesture as "recognized" is left to gtk-gesture subclasses.

A recognized gesture will then emit the following signals:

  • "begin" when the gesture is recognized.
  • A number of "update", whenever an input event is processed.
  • "end" when the gesture is no longer recognized.


Event propagation
In order to receive events, a gesture needs to either set a propagation phase through the function gtk-event-controller-propagation-phase, or feed those manually through the function gtk-event-controller-handle-event.

In the capture phase, events are propagated from the toplevel down to the target widget, and gestures that are attached to containers above the widget get a chance to interact with the event before it reaches the target.

After the capture phase, GTK emits the traditional "button-press-event", "button-release-event", "touch-event", etc signals. Gestures with the :phase-target phase are fed events from the default "event" handlers.

In the bubble phase, events are propagated up from the target widget to the toplevel, and gestures that are attached to containers above the widget get a chance to interact with events that have not been handled yet.

States of a sequence
Whenever input interaction happens, a single event may trigger a cascade of gtk-gestures, both across the parents of the widget receiving the event and in parallel within an individual widget. It is a responsibility of the widgets using those gestures to set the state of touch sequences accordingly in order to enable cooperation of gestures around the gdk-event-sequences triggering those.

Within a widget, gestures can be grouped through the function gtk-gesture-group, grouped gestures synchronize the state of sequences, so calling the function gtk-gesture-set-sequence-state on one will effectively propagate the state throughout the group.

By default, all sequences start out in the :none state, sequences in this state trigger the gesture event handler, but event propagation will continue unstopped by gestures.

If a sequence enters into the :denied state, the gesture group will effectively ignore the sequence, letting events go unstopped through the gesture, but the "slot" will still remain occupied while the touch is active.

If a sequence enters in the :claimed state, the gesture group will grab all interaction on the sequence, by:
  • Setting the same sequence to :denied on every other gesture group within the widget, and every gesture on parent widgets in the propagation chain.
  • calling "cancel" on every gesture in widgets underneath in the propagation chain.
  • Stopping event propagation after the gesture group handles the event.
Note: if a sequence is set early to :claimed on :touch-begin/:button-press (so those events are captured before reaching the event widget, this implies :phase-capture), one similar event will emulated if the sequence changes to :denied. This way event coherence is preserved before event propagation is unstopped again.

Sequence states can't be changed freely, see gtk-gesture-set-sequence-state to know about the possible lifetimes of a gdk-event-sequence.

Touchpad gestures
On the platforms that support it, gtk-gesture will handle transparently touchpad gesture events. The only precautions users of gtk-gesture should do to enable this support are:
  • Enabling GDK_TOUCHPAD_GESTURE_MASK on their gdk-windows
  • If the gesture has :phase-none, ensuring events of type GDK_TOUCHPAD_SWIPE and GDK_TOUCHPAD_PINCH are handled by the gtk-gesture

Signal Details

The "begin" signal
 lambda (gesture sequence)    :run-last      
The signal is emitted when the gesture is recognized. This means the number of touch sequences matches n-points, and the "check" handler(s) returned true. Note: These conditions may also happen when an extra touch, e.g. a third touch on a 2-touches gesture, is lifted, in that situation sequence will not pertain to the current set of active touches, so do not rely on this being true.
gesture
The gtk-gesture object which received the signal.
sequence
The gdk-event-sequence event that made the gesture to be recognized.
The "cancel" signal
 lambda (gesture sequence)    :run-last      
The signal is emitted whenever a sequence is cancelled. This usually happens on active touches when the gtk-event-controller-reset function is called on gesture, manually, due to grabs ..., or the individual sequence was claimed by controllers of the parent widgets, see the gtk-gesture-set-sequence-state) function. The gesture argument must forget everything about sequence as a reaction to the signal.
gesture
The gtk-gesture object which received the signal.
sequence
The gdk-event-sequence event that was cancelled.
The "end" signal
 lambda (gesture sequence)    :run-last      
The signal is emitted when gesture either stopped recognizing the event sequences as something to be handled, the "check" handler returned false, or the number of touch sequences became higher or lower than n-points. Note: The sequence argument might not pertain to the group of sequences that were previously triggering recognition on gesture, i.e. a just pressed touch sequence that exceeds n-points. This situation may be detected by checking through the gtk-gesture-handles-sequence function.
gesture
The gtk-gesture object which received the signal.
sequence
The gdk-event-sequence that made gesture recognition to finish.
The "sequence-state-changed" signal
 lambda (gesture sequence state)    :run-last      
The signal is emitted whenever a sequence state changes. See the gtk-gesture-set-sequence-state function to know more about the expectable sequence lifetimes.
gesture
The gtk-gesture object which received the signal.
sequence
The gdk-event-sequence event that was cancelled.
state
The new gtk-event-sequence-state value.
The "update" signal
 lambda (gesture sequence)    :run-last      
The signal is emitted whenever an event is handled while the gesture is recognized. The sequence argument is guaranteed to pertain to the set of active touches.
gesture
The gtk-gesture object which received the signal.
sequence
The gdk-event-sequence event that was updated.
 

Slot Access Functions

Inherited Slot Access Functions

See also

2020-9-10