Class Gesture
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
Gesture.GestureImpl
,GestureRotate
,GestureSingle
,GestureZoom
GtkGesture
is the base class for gesture recognition.
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::begin
when the gesture is recognized.Gtk.Gesture::update
, whenever an input event is processed.Gtk.Gesture::end
when 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 GtkGesture
s, 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
GdkEventSequence
s 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.DENIED
on every other gesture group within the widget, and every gesture on parent widgets in the propagation chain. - Emitting
Gtk.Gesture::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 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_SWIPE
andEventType.TOUCHPAD_PINCH
are handled by theGtkGesture
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Functional interface declaration of theBeginCallback
callback.static class
Gesture.Builder<B extends Gesture.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theCancelCallback
callback.static interface
Functional interface declaration of theEndCallback
callback.static class
static class
The GestureImpl type represents a native instance of the abstract Gesture class.static interface
Functional interface declaration of theSequenceStateChangedCallback
callback.static interface
Functional interface declaration of theUpdateCallback
callback.Nested classes/interfaces inherited from class org.gnome.gtk.EventController
EventController.EventControllerClass, EventController.EventControllerImpl
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionGesture
(MemorySegment address) Create a Gesture proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected Gesture
asParent()
Returns this instance as if it were its parent type.static Gesture.Builder
<? extends Gesture.Builder> builder()
AGesture.Builder
object constructs aGesture
with the specified properties.void
emitBegin
(@Nullable EventSequence sequence) Emits the "begin" signal.void
emitCancel
(@Nullable EventSequence sequence) Emits the "cancel" signal.void
emitEnd
(@Nullable EventSequence sequence) Emits the "end" signal.void
emitSequenceStateChanged
(@Nullable EventSequence sequence, EventSequenceState state) Emits the "sequence-state-changed" signal.void
emitUpdate
(@Nullable EventSequence sequence) Emits the "update" signal.boolean
getBoundingBox
(Rectangle rect) If there are touch sequences being currently handled by this Gesture, returnstrue
and fills inrect
with the bounding box containing all active touches.boolean
getBoundingBoxCenter
(Out<Double> x, Out<Double> y) If there are touch sequences being currently handled by this Gesture, returnstrue
and fills inx
andy
with the center of the bounding box containing all active touches.Returns the logicalGdkDevice
that is currently operating on this Gesture.getGroup()
Returns all gestures in the group of this GesturegetLastEvent
(@Nullable EventSequence sequence) Returns the last event that was processed forsequence
.Returns theGdkEventSequence
that was last updated on this Gesture.boolean
Ifsequence
is currently being interpreted by this Gesture, returnstrue
and fills inx
andy
with the last coordinates stored for that event sequence.Returns the list ofGdkEventSequences
currently being interpreted by this Gesture.getSequenceState
(EventSequence sequence) Returns thesequence
state, as seen by this Gesture.static Type
getType()
Get the GType of the Gesture classvoid
Addsgesture
to the same group than this Gesture.boolean
handlesSequence
(@Nullable EventSequence sequence) Returnstrue
if this Gesture is currently handling events corresponding tosequence
.boolean
isActive()
Returnstrue
if the gesture is currently active.boolean
isGroupedWith
(Gesture other) Returnstrue
if both gestures pertain to the same group.boolean
Returnstrue
if 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 whengesture
either 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.boolean
setSequenceState
(EventSequence sequence, EventSequenceState state) Deprecated.boolean
setState
(EventSequenceState state) Sets the state of all sequences that this Gesture is currently interacting with.void
ungroup()
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, setStaticName
Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, 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, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.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
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, 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:
asParent
in classEventController
-
getBoundingBox
If there are touch sequences being currently handled by this Gesture, returnstrue
and fills inrect
with the bounding box containing all active touches.Otherwise,
false
will 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,
rect
width and height will thus be 0 regardless of the number of touchpoints.- Parameters:
rect
- bounding box containing all active touches.- Returns:
true
if there are active touches,false
otherwise
-
getBoundingBoxCenter
If there are touch sequences being currently handled by this Gesture, returnstrue
and fills inx
andy
with the center of the bounding box containing all active touches.Otherwise,
false
will be returned.- Parameters:
x
- X coordinate for the bounding box centery
- Y coordinate for the bounding box center- Returns:
false
if no active touches are present,true
otherwise
-
getDevice
Returns the logicalGdkDevice
that is currently operating on this Gesture.This returns
null
if 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
sequence
is still interpreted by the this Gesture. If in doubt, you should make a copy of the event.- Parameters:
sequence
- aGdkEventSequence
- Returns:
- The last event from
sequence
-
getLastUpdatedSequence
Returns theGdkEventSequence
that was last updated on this Gesture.- Returns:
- The last updated sequence
-
getPoint
public boolean getPoint(@Nullable @Nullable EventSequence sequence, @Nullable @Nullable Out<Double> x, @Nullable @Nullable Out<Double> y) Ifsequence
is currently being interpreted by this Gesture, returnstrue
and fills inx
andy
with the last coordinates stored for that event sequence.The coordinates are always relative to the widget allocation.
- Parameters:
sequence
- aGdkEventSequence
, ornull
for pointer eventsx
- return location for X axis of the sequence coordinatesy
- return location for Y axis of the sequence coordinates- Returns:
true
ifsequence
is currently interpreted
-
getSequenceState
Returns thesequence
state, as seen by this Gesture.- Parameters:
sequence
- aGdkEventSequence
- Returns:
- The sequence state in this Gesture
-
getSequences
Returns the list ofGdkEventSequences
currently being interpreted by this Gesture.- 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
Addsgesture
to the same group than this Gesture.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
GdkEventSequences
is 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
GdkEventSequence
state is set toEventSequenceState.CLAIMED
on one group, every other gesture group attached to the sameGtkWidget
will switch the state for that sequence toEventSequenceState.DENIED
.- Parameters:
gesture
- aGtkGesture
-
handlesSequence
Returnstrue
if this Gesture is currently handling events corresponding tosequence
.- Parameters:
sequence
- aGdkEventSequence
- Returns:
true
if this Gesture is handlingsequence
,false
otherwise
-
isActive
public boolean isActive()Returnstrue
if the gesture is currently active.A gesture is active while there are touch sequences interacting with it.
- Returns:
true
if gesture is active
-
isGroupedWith
Returnstrue
if both gestures pertain to the same group.- Parameters:
other
- anotherGtkGesture
- Returns:
- whether the gestures are grouped
-
isRecognized
public boolean isRecognized()Returnstrue
if the gesture is currently recognized.A gesture is recognized if there are as many interacting touch sequences as required by this Gesture.
- Returns:
true
if gesture is recognized
-
setSequenceState
Deprecated.Sets the state ofsequence
in this Gesture.Sequences start in state
EventSequenceState.NONE
, and whenever they change state, they can never go back to that state. Likewise, sequences in stateEventSequenceState.DENIED
cannot 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::begin
signal 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
- aGdkEventSequence
state
- the sequence state- Returns:
true
ifsequence
is handled by this Gesture, 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.DENIED
cannot 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::begin
signal 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:
true
if 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
sequence
won'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 individualsequence
was claimed by parent widgets' controllers (seesetSequenceState(org.gnome.gdk.EventSequence, org.gnome.gtk.EventSequenceState)
).gesture
must forget everything aboutsequence
as 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 whengesture
either 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:
sequence
might 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
public void emitSequenceStateChanged(@Nullable @Nullable EventSequence sequence, EventSequenceState state) Emits the "sequence-state-changed" signal. SeeonSequenceStateChanged(org.gnome.gtk.Gesture.SequenceStateChangedCallback)
. -
onUpdate
Emitted whenever an event is handled while the gesture is recognized.sequence
is 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)
. -
builder
AGesture.Builder
object constructs aGesture
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withGesture.Builder.build()
.
-
setState(org.gnome.gtk.EventSequenceState)