GestureProtocol
public protocol GestureProtocol : EventControllerProtocol
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 nil
GdkEventSequence
value for these).
The number of touches that a GtkGesture
need to be recognized is
controlled by the [propertyGtk.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:
- [signal
Gtk.Gesture::begin
] when the gesture is recognized. - [signal
Gtk.Gesture::update
], whenever an input event is processed. - [signal
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 [methodGtk.EventController.set_propagation_phase
].
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 [methodGtk.Gesture.group
].
Grouped gestures synchronize the state of sequences, so calling
[methodGtk.Gesture.set_sequence_state
] on one will effectively propagate
the state throughout the group.
By default, all sequences start out in the GTK_EVENT_SEQUENCE_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 GTK_EVENT_SEQUENCE_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 GTK_EVENT_SEQUENCE_CLAIMED
state, the gesture
group will grab all interaction on the sequence, by:
- Setting the same sequence to
GTK_EVENT_SEQUENCE_DENIED
on every other gesture group within the widget, and every gesture on parent widgets in the propagation chain. - Emitting [signal
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 GTK_EVENT_SEQUENCE_CLAIMED
on
GDK_TOUCH_BEGIN
/GDK_BUTTON_PRESS
(so those events are captured before
reaching the event widget, this implies GTK_PHASE_CAPTURE
), one similar
event will emulated if the sequence changes to GTK_EVENT_SEQUENCE_DENIED
.
This way event coherence is preserved before event propagation is unstopped
again.
Sequence states can’t be changed freely.
See [methodGtk.Gesture.set_sequence_state
] 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
GTK_PHASE_NONE
, ensuring events of typeGDK_TOUCHPAD_SWIPE
andGDK_TOUCHPAD_PINCH
are handled by theGtkGesture
The GestureProtocol
protocol exposes the methods and properties of an underlying GtkGesture
instance.
The default implementation of these can be found in the protocol extension below.
For a concrete class that implements these methods and properties, see Gesture
.
Alternatively, use GestureRef
as a lighweight, unowned
reference if you already have an instance you just want to use.
-
Untyped pointer to the underlying
GtkGesture
instance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get }
-
gesture_ptr
Default implementationTyped pointer to the underlying
GtkGesture
instance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkGesture
instance.Declaration
Swift
var gesture_ptr: UnsafeMutablePointer<GtkGesture>! { get }
-
Required Initialiser for types conforming to
GestureProtocol
Declaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:
Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
GesturePropertyName
source property to a given target object.Declaration
Swift
@discardableResult @inlinable func bind<Q, T>(property source_property: GesturePropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocol
Parameters
source_property
the source property to bind
target
the target object to bind to
target_property
the target property to bind to
flags
the flags to pass to the
Binding
transform_from
ValueTransformer
to use for forward transformationtransform_to
ValueTransformer
to use for backwards transformationReturn Value
binding reference or
nil
in case of an error -
get(property:
Extension method) Get the value of a Gesture property
Declaration
Swift
@inlinable func get(property: GesturePropertyName) -> GLibObject.Value
Parameters
property
the property to get the value for
Return Value
the value of the named property
-
set(property:
Extension methodvalue: ) Set the value of a Gesture property. Note that this will only have an effect on properties that are writable and not construct-only!
Declaration
Swift
@inlinable func set(property: GesturePropertyName, value v: GLibObject.Value)
Parameters
property
the property to get the value for
Return Value
the value of the named property
-
connect(signal:
Extension methodflags: handler: ) Connect a Swift signal handler to the given, typed
GestureSignalName
signalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: GestureSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> Int
Parameters
signal
The signal to connect
flags
The connection flags to use
data
A pointer to user data to provide to the callback
destroyData
A
GClosureNotify
C function to destroy the data pointed to byuserData
handler
The Swift signal handler (function or callback) to invoke on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
connect(signal:
Extension methodflags: data: destroyData: signalHandler: ) Connect a C signal handler to the given, typed
GestureSignalName
signalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: GestureSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> Int
Parameters
signal
The signal to connect
flags
The connection flags to use
data
A pointer to user data to provide to the callback
destroyData
A
GClosureNotify
C function to destroy the data pointed to byuserData
signalHandler
The C function to be called on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
onBegin(flags:
Extension methodhandler: ) Emitted when the gesture is recognized.
This means the number of touch sequences matches [property
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.Note
This represents the underlyingbegin
signalDeclaration
Swift
@discardableResult @inlinable func onBegin(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: GestureRef, _ sequence: Gdk.EventSequenceRef?) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
sequence
the
GdkEventSequence
that made the gesture to be recognizedhandler
The signal handler to call Run the given callback whenever the
begin
signal is emitted -
beginSignal
Extension methodTyped
begin
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var beginSignal: GestureSignalName { get }
-
onCancel(flags:
Extension methodhandler: ) Emitted whenever a sequence is cancelled.
This usually happens on active touches when [method
Gtk.EventController.reset
] is called ongesture
(manually, due to grabs…), or the individualsequence
was claimed by parent widgets’ controllers (see [methodGtk.Gesture.set_sequence_state
]).gesture
must forget everything aboutsequence
as in response to this signal.Note
This represents the underlyingcancel
signalDeclaration
Swift
@discardableResult @inlinable func onCancel(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: GestureRef, _ sequence: Gdk.EventSequenceRef?) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
sequence
the
GdkEventSequence
that was cancelledhandler
The signal handler to call Run the given callback whenever the
cancel
signal is emitted -
cancelSignal
Extension methodTyped
cancel
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var cancelSignal: GestureSignalName { get }
-
onEnd(flags:
Extension methodhandler: ) Emitted when
gesture
either stopped recognizing the event sequences as something to be handled, or the number of touch sequences became higher or lower than [propertyGtk.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 exceeds [propertyGtk.Gesture:n-points
]). This situation may be detected by checking through [methodGtk.Gesture.handles_sequence
].Note
This represents the underlyingend
signalDeclaration
Swift
@discardableResult @inlinable func onEnd(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: GestureRef, _ sequence: Gdk.EventSequenceRef?) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
sequence
the
GdkEventSequence
that made gesture recognition to finishhandler
The signal handler to call Run the given callback whenever the
end
signal is emitted -
endSignal
Extension methodTyped
end
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var endSignal: GestureSignalName { get }
-
onSequenceStateChanged(flags:
Extension methodhandler: ) Emitted whenever a sequence state changes.
See [method
Gtk.Gesture.set_sequence_state
] to know more about the expectable sequence lifetimes.Note
This represents the underlyingsequence-state-changed
signalDeclaration
Swift
@discardableResult @inlinable func onSequenceStateChanged(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: GestureRef, _ sequence: Gdk.EventSequenceRef?, _ state: EventSequenceState) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
sequence
the
GdkEventSequence
that was cancelledstate
the new sequence state
handler
The signal handler to call Run the given callback whenever the
sequenceStateChanged
signal is emitted -
sequenceStateChangedSignal
Extension methodTyped
sequence-state-changed
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var sequenceStateChangedSignal: GestureSignalName { get }
-
onUpdate(flags:
Extension methodhandler: ) Emitted whenever an event is handled while the gesture is recognized.
sequence
is guaranteed to pertain to the set of active touches.Note
This represents the underlyingupdate
signalDeclaration
Swift
@discardableResult @inlinable func onUpdate(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: GestureRef, _ sequence: Gdk.EventSequenceRef?) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
sequence
the
GdkEventSequence
that was updatedhandler
The signal handler to call Run the given callback whenever the
update
signal is emitted -
updateSignal
Extension methodTyped
update
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var updateSignal: GestureSignalName { get }
-
onNotifyNPoints(flags:
Extension methodhandler: ) The notify signal is emitted on an object when one of its properties has its value set through
g_object_set_property()
,g_object_set()
, et al.Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with
G_PARAM_EXPLICIT_NOTIFY
, then any call tog_object_set_property()
results innotify
being emitted, even if the new value is the same as the old. If they did passG_PARAM_EXPLICIT_NOTIFY
, then this signal is emitted only when they explicitly callg_object_notify()
org_object_notify_by_pspec()
, and common practice is to do that only when the value has actually changed.This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the
g_signal_connect()
call, like this:(C Language Example):
g_signal_connect (text_view->buffer, "notify::paste-target-list", G_CALLBACK (gtk_text_view_target_list_notify), text_view)
It is important to note that you must use canonical parameter names as detail strings for the notify signal.
Note
This represents the underlyingnotify::n-points
signalDeclaration
Swift
@discardableResult @inlinable func onNotifyNPoints(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: GestureRef, _ pspec: ParamSpecRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
pspec
the
GParamSpec
of the property which changed.handler
The signal handler to call Run the given callback whenever the
notifyNPoints
signal is emitted -
notifyNPointsSignal
Extension methodTyped
notify::n-points
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var notifyNPointsSignal: GestureSignalName { get }
-
getBoundingBox(rect:
Extension method) If there are touch sequences being currently handled by
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.Declaration
Swift
@inlinable func getBoundingBox<RectangleT>(rect: RectangleT) -> Bool where RectangleT : RectangleProtocol
-
getBoundingBoxCenter(x:
Extension methody: ) If there are touch sequences being currently handled by
gesture
, returnstrue
and fills inx
andy
with the center of the bounding box containing all active touches.Otherwise,
false
will be returned.Declaration
Swift
@inlinable func getBoundingBoxCenter(x: UnsafeMutablePointer<CDouble>!, y: UnsafeMutablePointer<CDouble>!) -> Bool
-
getDevice()
Extension methodReturns the logical
GdkDevice
that is currently operating ongesture
.This returns
nil
if the gesture is not being interacted.Declaration
Swift
@inlinable func getDevice() -> Gdk.DeviceRef!
-
getGroup()
Extension methodReturns all gestures in the group of
gesture
Declaration
Swift
@inlinable func getGroup() -> GLib.ListRef!
-
getLastEvent(sequence:
Extension method) Returns the last event that was processed for
sequence
.Note that the returned pointer is only valid as long as the
sequence
is still interpreted by thegesture
. If in doubt, you should make a copy of the event.Declaration
Swift
@inlinable func getLastEvent(sequence: Gdk.EventSequenceRef? = nil) -> Gdk.EventRef!
-
getLastEvent(sequence:
Extension method) Returns the last event that was processed for
sequence
.Note that the returned pointer is only valid as long as the
sequence
is still interpreted by thegesture
. If in doubt, you should make a copy of the event.Declaration
Swift
@inlinable func getLastEvent<EventSequenceT>(sequence: EventSequenceT?) -> Gdk.EventRef! where EventSequenceT : EventSequenceProtocol
-
getLastUpdatedSequence()
Extension methodReturns the
GdkEventSequence
that was last updated ongesture
.Declaration
Swift
@inlinable func getLastUpdatedSequence() -> Gdk.EventSequenceRef!
-
getPoint(sequence:
Extension methodx: y: ) If
sequence
is currently being interpreted bygesture
, returnstrue
and fills inx
andy
with the last coordinates stored for that event sequence.The coordinates are always relative to the widget allocation.
Declaration
Swift
@inlinable func getPoint(sequence: Gdk.EventSequenceRef? = nil, x: UnsafeMutablePointer<CDouble>! = nil, y: UnsafeMutablePointer<CDouble>! = nil) -> Bool
-
getPoint(sequence:
Extension methodx: y: ) If
sequence
is currently being interpreted bygesture
, returnstrue
and fills inx
andy
with the last coordinates stored for that event sequence.The coordinates are always relative to the widget allocation.
Declaration
Swift
@inlinable func getPoint<EventSequenceT>(sequence: EventSequenceT?, x: UnsafeMutablePointer<CDouble>! = nil, y: UnsafeMutablePointer<CDouble>! = nil) -> Bool where EventSequenceT : EventSequenceProtocol
-
getSequenceState(sequence:
Extension method) Returns the
sequence
state, as seen bygesture
.Declaration
Swift
@inlinable func getSequenceState<EventSequenceT>(sequence: EventSequenceT) -> GtkEventSequenceState where EventSequenceT : EventSequenceProtocol
-
getSequences()
Extension methodReturns the list of
GdkEventSequences
currently being interpreted bygesture
.Declaration
Swift
@inlinable func getSequences() -> GLib.ListRef!
-
getGroup(gesture:
Extension method) Adds
gesture
to the same group thangroup_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 calling [methodGtk.Gesture.set_sequence_state
], on one will transfer the same value to the others.Groups also perform an “implicit grabbing” of sequences, if a
GdkEventSequence
state is set toGTK_EVENT_SEQUENCE_CLAIMED
on one group, every other gesture group attached to the sameGtkWidget
will switch the state for that sequence toGTK_EVENT_SEQUENCE_DENIED
.Declaration
Swift
@inlinable func getGroup<GestureT>(gesture: GestureT) where GestureT : GestureProtocol
-
handles(sequence:
Extension method) Returns
true
ifgesture
is currently handling events corresponding tosequence
.Declaration
Swift
@inlinable func handles(sequence: Gdk.EventSequenceRef? = nil) -> Bool
-
handles(sequence:
Extension method) Returns
true
ifgesture
is currently handling events corresponding tosequence
.Declaration
Swift
@inlinable func handles<EventSequenceT>(sequence: EventSequenceT?) -> Bool where EventSequenceT : EventSequenceProtocol
-
isGroupedWith(other:
Extension method) Returns
true
if both gestures pertain to the same group.Declaration
Swift
@inlinable func isGroupedWith<GestureT>(other: GestureT) -> Bool where GestureT : GestureProtocol
-
setSequenceState(sequence:
Extension methodstate: ) Sets the state of
sequence
ingesture
.Sequences start in state
GTK_EVENT_SEQUENCE_NONE
, and whenever they change state, they can never go back to that state. Likewise, sequences in stateGTK_EVENT_SEQUENCE_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 [signal
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.
Declaration
Swift
@inlinable func setSequenceState<EventSequenceT>(sequence: EventSequenceT, state: GtkEventSequenceState) -> Bool where EventSequenceT : EventSequenceProtocol
-
set(state:
Extension method) Sets the state of all sequences that
gesture
is currently interacting with.See [method
Gtk.Gesture.set_sequence_state
] for more details on sequence states.Declaration
Swift
@inlinable func set(state: GtkEventSequenceState) -> Bool
-
ungroup()
Extension methodSeparates
gesture
into an isolated group.Declaration
Swift
@inlinable func ungroup()
-
device
Extension methodReturns the logical
GdkDevice
that is currently operating ongesture
.This returns
nil
if the gesture is not being interacted.Declaration
Swift
@inlinable var device: Gdk.DeviceRef! { get }
-
group
Extension methodReturns all gestures in the group of
gesture
Declaration
Swift
@inlinable var group: GLib.ListRef! { get }
-
isActive
Extension methodReturns
true
if the gesture is currently active.A gesture is active while there are touch sequences interacting with it.
Declaration
Swift
@inlinable var isActive: Bool { get }
-
isRecognized
Extension methodReturns
true
if the gesture is currently recognized.A gesture is recognized if there are as many interacting touch sequences as required by
gesture
.Declaration
Swift
@inlinable var isRecognized: Bool { get }
-
lastUpdatedSequence
Extension methodReturns the
GdkEventSequence
that was last updated ongesture
.Declaration
Swift
@inlinable var lastUpdatedSequence: Gdk.EventSequenceRef! { get }
-
sequences
Extension methodReturns the list of
GdkEventSequences
currently being interpreted bygesture
.Declaration
Swift
@inlinable var sequences: GLib.ListRef! { get }