Gtk.Gesture¶
- Subclasses:
Methods¶
- Inherited:
- Structs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w/co |
Number of points needed to trigger the gesture |
||
r/w |
|
Signals¶
- Inherited:
Name |
Short Description |
---|---|
This signal is emitted when the gesture is recognized. |
|
This signal is emitted whenever a sequence is cancelled. |
|
This signal is emitted when gesture either stopped recognizing the event sequences as something to be handled (the |
|
This signal is emitted whenever a sequence state changes. |
|
This signal is emitted whenever an event is handled while the gesture is recognized. |
Fields¶
- Inherited:
Class Details¶
- class Gtk.Gesture(**kwargs)¶
- Bases:
- Abstract:
Yes
- Structure:
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 specialNone
Gdk.EventSequence
value for these).The number of touches that a
Gtk.Gesture
need to be recognized is controlled by theGtk.Gesture
:n-points
property, if a gesture is keeping track of less or more than that number of sequences, it won’t check wether the gesture is recognized.As soon as the gesture has the expected number of touches, the gesture will run the
Gtk.Gesture
::check
signal regularly on input events until the gesture is recognized, the criteria to consider a gesture as “recognized” is left toGtk.Gesture
subclasses.A recognized gesture will then emit the following signals:
Gtk.Gesture
::begin
when the gesture is recognized.A number of
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 either set a propagation phase through
Gtk.EventController.set_propagation_phase
(), or feed those manually throughGtk.EventController.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
Gtk.Widget
::button-press-event
,Gtk.Widget
::button-release-event
,Gtk.Widget
::touch-event
, etc signals. Gestures with theGtk.PropagationPhase.TARGET
phase are fed events from the defaultGtk.Widget
::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 theGdk.EventSequences
triggering those.Within a widget, gestures can be grouped through
Gtk.Gesture.group
(), grouped gestures synchronize the state of sequences, so callingGtk.Gesture.set_sequence_state
() on one will effectively propagate the state throughout the group.By default, all sequences start out in the
Gtk.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
Gtk.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
Gtk.EventSequenceState.CLAIMED
state, the gesture group will grab all interaction on the sequence, by:Setting the same sequence to
Gtk.EventSequenceState.DENIED
on every other gesture group within the widget, and every gesture on parent widgets in the propagation chain.calling
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.EventSequenceState.CLAIMED
onGdk.EventType.TOUCH_BEGIN
/Gdk.EventType.BUTTON_PRESS
(so those events are captured before reaching the event widget, this impliesGtk.PropagationPhase.CAPTURE
), one similar event will emulated if the sequence changes toGtk.EventSequenceState.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 aGdk.EventSequence
.- Touchpad gestures
On the platforms that support it,
Gtk.Gesture
will handle transparently touchpad gesture events. The only precautions users ofGtk.Gesture
should do to enable this support are:Enabling
Gdk.EventMask.TOUCHPAD_GESTURE_MASK
on theirGdk.Windows
If the gesture has
Gtk.PropagationPhase.NONE
, ensuring events of typeGdk.EventType.TOUCHPAD_SWIPE
andGdk.EventType.TOUCHPAD_PINCH
are handled by theGtk.Gesture
- get_bounding_box()[source]¶
- Returns:
True
if there are active touches,False
otherwise- rect:
bounding box containing all active touches.
- Return type:
(
bool
, rect:Gdk.Rectangle
)
If there are touch sequences being currently handled by self, this function returns
True
and fills in rect 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.
New in version 3.14.
- get_bounding_box_center()[source]¶
- Returns:
False
if no active touches are present,True
otherwise- x:
X coordinate for the bounding box center
- y:
Y coordinate for the bounding box center
- Return type:
If there are touch sequences being currently handled by self, this function returns
True
and fills in x and y with the center of the bounding box containing all active touches. Otherwise,False
will be returned.New in version 3.14.
- get_device()[source]¶
- Returns:
a
Gdk.Device
, orNone
- Return type:
Gdk.Device
orNone
Returns the master
Gdk.Device
that is currently operating on self, orNone
if the gesture is not being interacted.New in version 3.14.
- get_group()[source]¶
- Returns:
The list of
Gtk.Gestures
, free with g_list_free()- Return type:
Returns all gestures in the group of self
New in version 3.14.
- get_last_event(sequence)[source]¶
- Parameters:
sequence (
Gdk.EventSequence
orNone
) – aGdk.EventSequence
- Returns:
The last event from sequence
- Return type:
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 the self. If in doubt, you should make a copy of the event.
- get_last_updated_sequence()[source]¶
- Returns:
The last updated sequence
- Return type:
Returns the
Gdk.EventSequence
that was last updated on self.New in version 3.14.
- get_point(sequence)[source]¶
- Parameters:
sequence (
Gdk.EventSequence
orNone
) – aGdk.EventSequence
, orNone
for pointer events- Returns:
True
if sequence is currently interpreted- x:
return location for X axis of the sequence coordinates
- y:
return location for Y axis of the sequence coordinates
- Return type:
If sequence is currently being interpreted by self, this function returns
True
and fills in x and y with the last coordinates stored for that event sequence. The coordinates are always relative to the widget allocation.New in version 3.14.
- get_sequence_state(sequence)[source]¶
- Parameters:
sequence (
Gdk.EventSequence
) – aGdk.EventSequence
- Returns:
The sequence state in self
- Return type:
Returns the sequence state, as seen by self.
New in version 3.14.
- get_sequences()[source]¶
- Returns:
A list of
Gdk.EventSequences
, the list elements are owned by GTK+ and must not be freed or modified, the list itself must be deleted through g_list_free()- Return type:
Returns the list of
Gdk.EventSequences
currently being interpreted by self.New in version 3.14.
- get_window()[source]¶
- Returns:
the user defined window, or
None
if none- Return type:
Gdk.Window
orNone
Returns the user-defined window that receives the events handled by self. See
Gtk.Gesture.set_window
() for more information.New in version 3.14.
- group(gesture)[source]¶
- Parameters:
gesture (
Gtk.Gesture
) – aGtk.Gesture
Adds gesture to the same group than self. Gestures are by default isolated in their own groups.
When gestures are grouped, the state of
Gdk.EventSequences
is kept in sync for all of those, so callingGtk.Gesture.set_sequence_state
(), on one will transfer the same value to the others.Groups also perform an “implicit grabbing” of sequences, if a
Gdk.EventSequence
state is set toGtk.EventSequenceState.CLAIMED
on one group, every other gesture group attached to the sameGtk.Widget
will switch the state for that sequence toGtk.EventSequenceState.DENIED
.New in version 3.14.
- handles_sequence(sequence)[source]¶
- Parameters:
sequence (
Gdk.EventSequence
orNone
) – aGdk.EventSequence
orNone
- Returns:
- Return type:
Returns
True
if self is currently handling events corresponding to sequence.New in version 3.14.
- is_active()[source]¶
-
Returns
True
if the gesture is currently active. A gesture is active meanwhile there are touch sequences interacting with it.New in version 3.14.
- is_grouped_with(other)[source]¶
- Parameters:
other (
Gtk.Gesture
) – anotherGtk.Gesture
- Returns:
whether the gestures are grouped
- Return type:
Returns
True
if both gestures pertain to the same group.New in version 3.14.
- is_recognized()[source]¶
-
Returns
True
if the gesture is currently recognized. A gesture is recognized if there are as many interacting touch sequences as required by self, andGtk.Gesture
::check
returnedTrue
for the sequences being currently interpreted.New in version 3.14.
- set_sequence_state(sequence, state)[source]¶
- Parameters:
sequence (
Gdk.EventSequence
) – aGdk.EventSequence
state (
Gtk.EventSequenceState
) – the sequence state
- Returns:
True
if sequence is handled by self, and the state is changed successfully- Return type:
Sets the state of sequence in self. Sequences start in state
Gtk.EventSequenceState.NONE
, and whenever they change state, they can never go back to that state. Likewise, sequences in stateGtk.EventSequenceState.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.
New in version 3.14.
- set_state(state)[source]¶
- Parameters:
state (
Gtk.EventSequenceState
) – the sequence state- Returns:
True
if the state of at least one sequence was changed successfully- Return type:
Sets the state of all sequences that self is currently interacting with. See
Gtk.Gesture.set_sequence_state
() for more details on sequence states.New in version 3.14.
- set_window(window)[source]¶
- Parameters:
window (
Gdk.Window
orNone
) – aGdk.Window
, orNone
Sets a specific window to receive events about, so self will effectively handle only events targeting window, or a child of it. window must pertain to
Gtk.EventController.get_widget
().New in version 3.14.
Signal Details¶
- Gtk.Gesture.signals.begin(gesture, sequence)¶
- Signal Name:
begin
- Flags:
- Parameters:
gesture (
Gtk.Gesture
) – The object which received the signalsequence (
Gdk.EventSequence
orNone
) – theGdk.EventSequence
that made the gesture to be recognized
This signal is emitted when the gesture is recognized. This means the number of touch sequences matches
Gtk.Gesture
:n-points
, and theGtk.Gesture
::check
handler(s) returnedTrue
.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.
New in version 3.14.
- Gtk.Gesture.signals.cancel(gesture, sequence)¶
- Signal Name:
cancel
- Flags:
- Parameters:
gesture (
Gtk.Gesture
) – The object which received the signalsequence (
Gdk.EventSequence
orNone
) – theGdk.EventSequence
that was cancelled
This signal is emitted whenever a sequence is cancelled. This usually happens on active touches when
Gtk.EventController.reset
() is called on gesture (manually, due to grabs…), or the individual sequence was claimed by parent widgets’ controllers (seeGtk.Gesture.set_sequence_state
()).gesture must forget everything about sequence as a reaction to this signal.
New in version 3.14.
- Gtk.Gesture.signals.end(gesture, sequence)¶
- Signal Name:
end
- Flags:
- Parameters:
gesture (
Gtk.Gesture
) – The object which received the signalsequence (
Gdk.EventSequence
orNone
) – theGdk.EventSequence
that made gesture recognition to finish
This signal is emitted when gesture either stopped recognizing the event sequences as something to be handled (the
Gtk.Gesture
::check
handler returnedFalse
), 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 on gesture (ie. a just pressed touch sequence that exceeds
Gtk.Gesture
:n-points
). This situation may be detected by checking throughGtk.Gesture.handles_sequence
().New in version 3.14.
- Gtk.Gesture.signals.sequence_state_changed(gesture, sequence, state)¶
- Signal Name:
sequence-state-changed
- Flags:
- Parameters:
gesture (
Gtk.Gesture
) – The object which received the signalsequence (
Gdk.EventSequence
orNone
) – theGdk.EventSequence
that was cancelledstate (
Gtk.EventSequenceState
) – the new sequence state
This signal is emitted whenever a sequence state changes. See
Gtk.Gesture.set_sequence_state
() to know more about the expectable sequence lifetimes.New in version 3.14.
- Gtk.Gesture.signals.update(gesture, sequence)¶
- Signal Name:
update
- Flags:
- Parameters:
gesture (
Gtk.Gesture
) – The object which received the signalsequence (
Gdk.EventSequence
orNone
) – theGdk.EventSequence
that was updated
This signal is emitted whenever an event is handled while the gesture is recognized. sequence is guaranteed to pertain to the set of active touches.
New in version 3.14.
Property Details¶
- Gtk.Gesture.props.n_points¶
- Name:
n-points
- Type:
- Default Value:
1
- Flags:
The number of touch points that trigger recognition on this gesture,
New in version 3.14.
- Gtk.Gesture.props.window¶
- Name:
window
- Type:
- Default Value:
- Flags:
If non-
None
, the gesture will only listen for events that happen on thisGdk.Window
, or a child of it.New in version 3.14.