Class Gesture
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
Gesture.Gesture$Impl,GestureRotate,GestureSingle,GestureZoom
Although GtkGesture 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 null GdkEventSequence
value for these).
The number of touches that a GtkGesture need to be recognized is
controlled by the Gtk.Gesture: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, it will check
regularly if it is recognized, the criteria to consider a gesture as
"recognized" is left to GtkGesture subclasses.
A recognized gesture will then emit the following signals:
Gtk.Gesture::beginwhen the gesture is recognized.Gtk.Gesture::update, whenever an input event is processed.Gtk.Gesture::endwhen the gesture is no longer recognized.
Event propagation
In order to receive events, a gesture needs to set a propagation phase
through EventController.setPropagationPhase(org.gnome.gtk.PropagationPhase).
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.
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 GtkGestures, 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
GdkEventSequences triggering those.
Within a widget, gestures can be grouped through group(org.gnome.gtk.Gesture).
Grouped gestures synchronize the state of sequences, so calling
setState(org.gnome.gtk.EventSequenceState) on one will effectively propagate
the state throughout the group.
By default, all sequences start out in the EventSequenceState.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 EventSequenceState.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 EventSequenceState.CLAIMED state, the gesture
group will grab all interaction on the sequence, by:
- Setting the same sequence to
EventSequenceState.DENIEDon every other gesture group within the widget, and every gesture on parent widgets in the propagation chain. - Emitting
Gtk.Gesture::cancelon 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 EventSequenceState.CLAIMED on
EventType.TOUCH_BEGIN/EventType.BUTTON_PRESS (so those events are captured before
reaching the event widget, this implies PropagationPhase.CAPTURE), one similar
event will be emulated if the sequence changes to EventSequenceState.DENIED.
This way event coherence is preserved before event propagation is unstopped
again.
Sequence states can't be changed freely.
See setState(org.gnome.gtk.EventSequenceState) to know about the possible
lifetimes of a GdkEventSequence.
Touchpad gestures
On the platforms that support it, GtkGesture will handle transparently
touchpad gesture events. The only precautions users of GtkGesture should
do to enable this support are:
- If the gesture has
PropagationPhase.NONE, ensuring events of typeEventType.TOUCHPAD_SWIPEandEventType.TOUCHPAD_PINCHare handled by theGtkGesture
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface declaration of theBeginCallbackcallback.static classGesture.Builder<B extends Gesture.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theCancelCallbackcallback.static interfaceFunctional interface declaration of theEndCallbackcallback.static classThe Gesture$Impl type represents a native instance of the abstract Gesture class.static classstatic interfaceFunctional interface declaration of theSequenceStateChangedCallbackcallback.static interfaceFunctional interface declaration of theUpdateCallbackcallback.Nested classes/interfaces inherited from class org.gnome.gtk.EventController
EventController.EventController$Impl, EventController.EventControllerClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionGesture()Creates a new Gesture.Gesture(MemorySegment address) Create a Gesture proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected GestureasParent()Returns this instance as if it were its parent type.voidemitBegin(@Nullable EventSequence sequence) Emits the "begin" signal.voidemitCancel(@Nullable EventSequence sequence) Emits the "cancel" signal.voidemitEnd(@Nullable EventSequence sequence) Emits the "end" signal.voidemitSequenceStateChanged(@Nullable EventSequence sequence, EventSequenceState state) Emits the "sequence-state-changed" signal.voidemitUpdate(@Nullable EventSequence sequence) Emits the "update" signal.booleangetBoundingBox(Rectangle rect) If there are touch sequences being currently handled bygesture,returnstrueand fills inrectwith the bounding box containing all active touches.booleangetBoundingBoxCenter(Out<Double> x, Out<Double> y) If there are touch sequences being currently handled bygesture,returnstrueand fills inxandywith the center of the bounding box containing all active touches.@Nullable DeviceReturns the logicalGdkDevicethat is currently operating ongesture.getGroup()Returns all gestures in the group of this Gesture@Nullable EventgetLastEvent(@Nullable EventSequence sequence) Returns the last event that was processed forsequence.@Nullable EventSequenceReturns theGdkEventSequencethat was last updated ongesture.booleanIfsequenceis currently being interpreted bygesture,returnstrueand fills inxandywith the last coordinates stored for that event sequence.Returns the list ofGdkEventSequencescurrently being interpreted bygesture.getSequenceState(EventSequence sequence) Returns thesequencestate, as seen bygesture.static @Nullable TypegetType()Get the GType of the Gesture classvoidAddsgestureto the same group thangroupGesture.booleanhandlesSequence(@Nullable EventSequence sequence) Returnstrueif this Gesture is currently handling events corresponding tosequence.booleanisActive()Returnstrueif the gesture is currently active.booleanisGroupedWith(Gesture other) Returnstrueif both gestures pertain to the same group.booleanReturnstrueif the gesture is currently recognized.onBegin(Gesture.BeginCallback handler) Emitted when the gesture is recognized.onCancel(Gesture.CancelCallback handler) Emitted whenever a sequence is cancelled.onEnd(Gesture.EndCallback handler) Emitted whengestureeither stopped recognizing the event sequences as something to be handled, or the number of touch sequences became higher or lower thanGtk.Gesture:n-points.Emitted whenever a sequence state changes.onUpdate(Gesture.UpdateCallback handler) Emitted whenever an event is handled while the gesture is recognized.booleansetSequenceState(EventSequence sequence, EventSequenceState state) Deprecated.booleansetState(EventSequenceState state) Sets the state of all sequences that this Gesture is currently interacting with.voidungroup()Separates this Gesture into an isolated group.Methods inherited from class org.gnome.gtk.EventController
getCurrentEvent, getCurrentEventDevice, getCurrentEventState, getCurrentEventTime, getName, getPropagationLimit, getPropagationPhase, getWidget, reset, setName, setPropagationLimit, setPropagationPhase, setStaticNameMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, builder, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Gesture
Create a Gesture proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Gesture
public Gesture()Creates a new Gesture.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type.- Overrides:
asParentin classEventController
-
getBoundingBox
If there are touch sequences being currently handled bygesture,returnstrueand fills inrectwith the bounding box containing all active touches.Otherwise,
falsewill be returned.Note: This function will yield unexpected results on touchpad gestures. Since there is no correlation between physical and pixel distances, these will look as if constrained in an infinitely small area,
rectwidth and height will thus be 0 regardless of the number of touchpoints.- Parameters:
rect- bounding box containing all active touches.- Returns:
trueif there are active touches,falseotherwise
-
getBoundingBoxCenter
If there are touch sequences being currently handled bygesture,returnstrueand fills inxandywith the center of the bounding box containing all active touches.Otherwise,
falsewill be returned.- Parameters:
x- X coordinate for the bounding box centery- Y coordinate for the bounding box center- Returns:
falseif no active touches are present,trueotherwise
-
getDevice
Returns the logicalGdkDevicethat is currently operating ongesture.This returns
nullif the gesture is not being interacted.- Returns:
- a
GdkDevice
-
getGroup
-
getLastEvent
Returns the last event that was processed forsequence.Note that the returned pointer is only valid as long as the
sequenceis still interpreted by thegesture.If in doubt, you should make a copy of the event.- Parameters:
sequence- aGdkEventSequence- Returns:
- The last event from
sequence
-
getLastUpdatedSequence
Returns theGdkEventSequencethat was last updated ongesture.- Returns:
- The last updated sequence
-
getPoint
public boolean getPoint(@Nullable EventSequence sequence, @Nullable Out<Double> x, @Nullable Out<Double> y) Ifsequenceis currently being interpreted bygesture,returnstrueand fills inxandywith the last coordinates stored for that event sequence.The coordinates are always relative to the widget allocation.
- Parameters:
sequence- aGdkEventSequence, ornullfor pointer eventsx- return location for X axis of the sequence coordinatesy- return location for Y axis of the sequence coordinates- Returns:
trueifsequenceis currently interpreted
-
getSequenceState
Returns thesequencestate, as seen bygesture.- Parameters:
sequence- aGdkEventSequence- Returns:
- The sequence state in this Gesture
-
getSequences
Returns the list ofGdkEventSequencescurrently being interpreted bygesture.- Returns:
- A list
of
GdkEventSequence, the list elements are owned by GTK and must not be freed or modified, the list itself must be deleted through g_list_free()
-
group
Addsgestureto the same group thangroupGesture.Gestures are by default isolated in their own groups.
Both gestures must have been added to the same widget before they can be grouped.
When gestures are grouped, the state of
GdkEventSequencesis kept in sync for all of those, so callingsetSequenceState(org.gnome.gdk.EventSequence, org.gnome.gtk.EventSequenceState), on one will transfer the same value to the others.Groups also perform an "implicit grabbing" of sequences, if a
GdkEventSequencestate is set toEventSequenceState.CLAIMEDon one group, every other gesture group attached to the sameGtkWidgetwill switch the state for that sequence toEventSequenceState.DENIED.- Parameters:
gesture- aGtkGesture
-
handlesSequence
Returnstrueif this Gesture is currently handling events corresponding tosequence.- Parameters:
sequence- aGdkEventSequence- Returns:
trueif this Gesture is handlingsequence,falseotherwise
-
isActive
public boolean isActive()Returnstrueif the gesture is currently active.A gesture is active while there are touch sequences interacting with it.
- Returns:
trueif gesture is active
-
isGroupedWith
Returnstrueif both gestures pertain to the same group.- Parameters:
other- anotherGtkGesture- Returns:
- whether the gestures are grouped
-
isRecognized
public boolean isRecognized()Returnstrueif the gesture is currently recognized.A gesture is recognized if there are as many interacting touch sequences as required by
gesture.- Returns:
trueif gesture is recognized
-
setSequenceState
Deprecated.Sets the state ofsequenceingesture.Sequences start in state
EventSequenceState.NONE, and whenever they change state, they can never go back to that state. Likewise, sequences in stateEventSequenceState.DENIEDcannot turn back to a not denied state. With these rules, the lifetime of an event sequence is constrained to the next four:- None
- None → Denied
- None → Claimed
- None → Claimed → Denied
Note: Due to event handling ordering, it may be unsafe to set the state on another gesture within a
Gtk.Gesture::beginsignal handler, as the callback might be executed before the other gesture knows about the sequence. A safe way to perform this could be:static void first_gesture_begin_cb (GtkGesture *first_gesture, GdkEventSequence *sequence, gpointer user_data) { gtk_gesture_set_sequence_state (first_gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED); gtk_gesture_set_sequence_state (second_gesture, sequence, GTK_EVENT_SEQUENCE_DENIED); } static void second_gesture_begin_cb (GtkGesture *second_gesture, GdkEventSequence *sequence, gpointer user_data) { if (gtk_gesture_get_sequence_state (first_gesture, sequence) == GTK_EVENT_SEQUENCE_CLAIMED) gtk_gesture_set_sequence_state (second_gesture, sequence, GTK_EVENT_SEQUENCE_DENIED); }If both gestures are in the same group, just set the state on the gesture emitting the event, the sequence will be already be initialized to the group's global state when the second gesture processes the event.
- Parameters:
sequence- aGdkEventSequencestate- the sequence state- Returns:
trueifsequenceis handled bygesture,and the state is changed successfully
-
setState
Sets the state of all sequences that this Gesture is currently interacting with.Sequences start in state
EventSequenceState.NONE, and whenever they change state, they can never go back to that state. Likewise, sequences in stateEventSequenceState.DENIEDcannot turn back to a not denied state. With these rules, the lifetime of an event sequence is constrained to the next four:- None
- None → Denied
- None → Claimed
- None → Claimed → Denied
Note: Due to event handling ordering, it may be unsafe to set the state on another gesture within a
Gtk.Gesture::beginsignal handler, as the callback might be executed before the other gesture knows about the sequence. A safe way to perform this could be:static void first_gesture_begin_cb (GtkGesture *first_gesture, GdkEventSequence *sequence, gpointer user_data) { gtk_gesture_set_state (first_gesture, GTK_EVENT_SEQUENCE_CLAIMED); gtk_gesture_set_state (second_gesture, GTK_EVENT_SEQUENCE_DENIED); } static void second_gesture_begin_cb (GtkGesture *second_gesture, GdkEventSequence *sequence, gpointer user_data) { if (gtk_gesture_get_sequence_state (first_gesture, sequence) == GTK_EVENT_SEQUENCE_CLAIMED) gtk_gesture_set_state (second_gesture, GTK_EVENT_SEQUENCE_DENIED); }If both gestures are in the same group, just set the state on the gesture emitting the event, the sequence will be already be initialized to the group's global state when the second gesture processes the event.
- Parameters:
state- the sequence state- Returns:
trueif the state of at least one sequence was changed successfully
-
ungroup
public void ungroup()Separates this Gesture into an isolated group. -
onBegin
Emitted when the gesture is recognized.This means the number of touch sequences matches
Gtk.Gesture:n-points.Note: These conditions may also happen when an extra touch (eg. a third touch on a 2-touches gesture) is lifted, in that situation
sequencewon't pertain to the current set of active touches, so don't rely on this being true.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitBegin
Emits the "begin" signal. SeeonBegin(org.gnome.gtk.Gesture.BeginCallback). -
onCancel
Emitted whenever a sequence is cancelled.This usually happens on active touches when
EventController.reset()is called ongesture(manually, due to grabs...), or the individualsequencewas claimed by parent widgets' controllers (seesetSequenceState(org.gnome.gdk.EventSequence, org.gnome.gtk.EventSequenceState)).gesturemust forget everything aboutsequenceas in response to this signal.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitCancel
Emits the "cancel" signal. SeeonCancel(org.gnome.gtk.Gesture.CancelCallback). -
onEnd
Emitted whengestureeither stopped recognizing the event sequences as something to be handled, or the number of touch sequences became higher or lower thanGtk.Gesture:n-points.Note:
sequencemight not pertain to the group of sequences that were previously triggering recognition ongesture(ie. a just pressed touch sequence that exceedsGtk.Gesture:n-points). This situation may be detected by checking throughhandlesSequence(org.gnome.gdk.EventSequence).- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitEnd
Emits the "end" signal. SeeonEnd(org.gnome.gtk.Gesture.EndCallback). -
onSequenceStateChanged
public SignalConnection<Gesture.SequenceStateChangedCallback> onSequenceStateChanged(Gesture.SequenceStateChangedCallback handler) Emitted whenever a sequence state changes.See
setSequenceState(org.gnome.gdk.EventSequence, org.gnome.gtk.EventSequenceState)to know more about the expectable sequence lifetimes.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitSequenceStateChanged
Emits the "sequence-state-changed" signal. SeeonSequenceStateChanged(org.gnome.gtk.Gesture.SequenceStateChangedCallback). -
onUpdate
Emitted whenever an event is handled while the gesture is recognized.sequenceis guaranteed to pertain to the set of active touches.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitUpdate
Emits the "update" signal. SeeonUpdate(org.gnome.gtk.Gesture.UpdateCallback).
-
setState(org.gnome.gtk.EventSequenceState)