Gtk.Gesture¶
| Subclasses: | Gtk.GestureRotate,Gtk.GestureSingle,Gtk.GestureZoom | 
|---|
Methods¶
| Inherited: | Gtk.EventController (5), GObject.Object (37) | 
|---|---|
| Structs: | GObject.ObjectClass (5) | 
| get_bounding_box() | |
| get_bounding_box_center() | |
| get_device() | |
| get_group() | |
| get_last_event(sequence) | |
| get_last_updated_sequence() | |
| get_point(sequence) | |
| get_sequence_state(sequence) | |
| get_sequences() | |
| get_window() | |
| group(gesture) | |
| handles_sequence(sequence) | |
| is_active() | |
| is_grouped_with(other) | |
| is_recognized() | |
| set_sequence_state(sequence, state) | |
| set_state(state) | |
| set_window(window) | |
| ungroup() | 
Virtual Methods¶
| Inherited: | GObject.Object (7) | 
|---|
Properties¶
| Inherited: | Gtk.EventController (2) | 
|---|
| Name | Type | Flags | Short Description | 
|---|---|---|---|
| n-points | int | r/w/co | Number of points needed to trigger the gesture | 
| window | Gdk.Window | r/w | Gdk.Windowto receive events about | 
Signals¶
| Inherited: | GObject.Object (1) | 
|---|
| Name | Short Description | 
|---|---|
| begin | This signal is emitted when the gesture is recognized. | 
| cancel | This signal is emitted whenever a sequence is cancelled. | 
| end | This signal is emitted when gesture either stopped recognizing the event sequences as something to be handled (the Gtk.Gesture::checkhandler returnedFalse), or the number of touch sequences became higher or lower thanGtk.Gesture:n-points. | 
| sequence-state-changed | This signal is emitted whenever a sequence state changes. | 
| update | This signal is emitted whenever an event is handled while the gesture is recognized. | 
Fields¶
| Inherited: | GObject.Object (1) | 
|---|
Class Details¶
- 
class Gtk.Gesture(**kwargs)¶
- Bases: - Gtk.EventController- Abstract: - Yes - Structure: - Gtk.GestureClass- Gtk.Gestureis 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- None- Gdk.EventSequencevalue for these).- The number of touches that a - Gtk.Gestureneed to be recognized is controlled by the- Gtk.Gesture- :n-pointsproperty, 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- ::checksignal regularly on input events until the gesture is recognized, the criteria to consider a gesture as “recognized” is left to- Gtk.Gesturesubclasses.- A recognized gesture will then emit the following signals: - Gtk.Gesture- ::beginwhen the gesture is recognized.
- A number of 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 either set a propagation phase through - Gtk.EventController.set_propagation_phase(), or feed those manually through- Gtk.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 the- Gtk.PropagationPhase.TARGETphase are fed events from the default- Gtk.Widget- ::eventhandlers.- 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.EventSequencestriggering those.- Within a widget, gestures can be grouped through - Gtk.Gesture.group(), grouped gestures synchronize the state of sequences, so calling- Gtk.Gesture.set_sequence_state() on one will effectively propagate the state throughout the group.- By default, all sequences start out in the - Gtk.EventSequenceState.NONEstate, 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.DENIEDstate, 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.CLAIMEDstate, the gesture group will grab all interaction on the sequence, by:- Setting the same sequence to Gtk.EventSequenceState.DENIEDon every other gesture group within the widget, and every gesture on parent widgets in the propagation chain.
- calling 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 - Gtk.EventSequenceState.CLAIMEDon- Gdk.EventType.TOUCH_BEGIN/- Gdk.EventType.BUTTON_PRESS(so those events are captured before reaching the event widget, this implies- Gtk.PropagationPhase.CAPTURE), one similar event will emulated if the sequence changes to- Gtk.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 a- Gdk.EventSequence.- Touchpad gestures
 - On the platforms that support it, - Gtk.Gesturewill handle transparently touchpad gesture events. The only precautions users of- Gtk.Gestureshould do to enable this support are:- Enabling Gdk.EventMask.TOUCHPAD_GESTURE_MASKon theirGdk.Windows
- If the gesture has Gtk.PropagationPhase.NONE, ensuring events of typeGdk.EventType.TOUCHPAD_SWIPEandGdk.EventType.TOUCHPAD_PINCHare handled by theGtk.Gesture
 - 
get_bounding_box()[source]¶
- Returns: - Trueif there are active touches,- Falseotherwise- 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 - Trueand fills in rect with 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, 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: - Falseif no active touches are present,- Trueotherwise- x: - X coordinate for the bounding box center - y: - Y coordinate for the bounding box center - Return type: - ( - bool, x:- float, y:- float)- If there are touch sequences being currently handled by self, this function returns - Trueand fills in x and y with the center of the bounding box containing all active touches. Otherwise,- Falsewill be returned.- New in version 3.14. 
 - 
get_device()[source]¶
- Returns: - a - Gdk.Device, or- None- Return type: - Gdk.Deviceor- None- Returns the master - Gdk.Devicethat is currently operating on self, or- Noneif 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: - [ - Gtk.Gesture]- Returns all gestures in the group of self - New in version 3.14. 
 - 
get_last_event(sequence)[source]¶
- Parameters: - sequence ( - Gdk.EventSequenceor- None) – a- Gdk.EventSequence- Returns: - The last event from sequence - Return type: - Gdk.Eventor- None- 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: - Gdk.EventSequenceor- None- Returns the - Gdk.EventSequencethat was last updated on self.- New in version 3.14. 
 - 
get_point(sequence)[source]¶
- Parameters: - sequence ( - Gdk.EventSequenceor- None) – a- Gdk.EventSequence, or- Nonefor pointer events- Returns: - Trueif 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: - ( - bool, x:- float, y:- float)- If sequence is currently being interpreted by self, this function returns - Trueand 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) – a- Gdk.EventSequence- Returns: - The sequence state in self - Return type: - Gtk.EventSequenceState- 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: - [ - Gdk.EventSequence]- Returns the list of - Gdk.EventSequencescurrently being interpreted by self.- New in version 3.14. 
 - 
get_window()[source]¶
- Returns: - the user defined window, or - Noneif none- Return type: - Gdk.Windowor- None- 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) – a- Gtk.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.EventSequencesis kept in sync for all of those, so calling- Gtk.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.EventSequencestate is set to- Gtk.EventSequenceState.CLAIMEDon one group, every other gesture group attached to the same- Gtk.Widgetwill switch the state for that sequence to- Gtk.EventSequenceState.DENIED.- New in version 3.14. 
 - 
handles_sequence(sequence)[source]¶
- Parameters: - sequence ( - Gdk.EventSequenceor- None) – a- Gdk.EventSequenceor- None- Returns: - Trueif self is handling sequence,- Falseotherwise- Return type: - bool- Returns - Trueif self is currently handling events corresponding to sequence.- New in version 3.14. 
 - 
is_active()[source]¶
- Returns: - Trueif gesture is active- Return type: - bool- Returns - Trueif 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) – another- Gtk.Gesture- Returns: - whether the gestures are grouped - Return type: - bool- Returns - Trueif both gestures pertain to the same group.- New in version 3.14. 
 - 
is_recognized()[source]¶
- Returns: - Trueif gesture is recognized- Return type: - bool- Returns - Trueif the gesture is currently recognized. A gesture is recognized if there are as many interacting touch sequences as required by self, and- Gtk.Gesture- ::checkreturned- Truefor 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: - Trueif 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 state- Gtk.EventSequenceState.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. - New in version 3.14. 
- sequence (
 - 
set_state(state)[source]¶
- Parameters: - state ( - Gtk.EventSequenceState) – the sequence state- Returns: - Trueif the state of at least one sequence was changed successfully- Return type: - bool- 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.Windowor- None) – a- Gdk.Window, or- None- 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 signal
- sequence (Gdk.EventSequenceorNone) – theGdk.EventSequencethat 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 the- Gtk.Gesture- ::checkhandler(s) returned- True.- 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. 
- gesture (
- 
Gtk.Gesture.signals.cancel(gesture, sequence)¶
- Signal Name: - cancel- Flags: - Parameters: - gesture (Gtk.Gesture) – The object which received the signal
- sequence (Gdk.EventSequenceorNone) – theGdk.EventSequencethat 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 (see- Gtk.Gesture.set_sequence_state()).- gesture must forget everything about sequence as a reaction to this signal. - New in version 3.14. 
- gesture (
- 
Gtk.Gesture.signals.end(gesture, sequence)¶
- Signal Name: - end- Flags: - Parameters: - gesture (Gtk.Gesture) – The object which received the signal
- sequence (Gdk.EventSequenceorNone) – theGdk.EventSequencethat 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- ::checkhandler returned- False), or the number of touch sequences became higher or lower than- Gtk.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 through- Gtk.Gesture.handles_sequence().- New in version 3.14. 
- gesture (
- 
Gtk.Gesture.signals.sequence_state_changed(gesture, sequence, state)¶
- Signal Name: - sequence-state-changed- Flags: - Parameters: - gesture (Gtk.Gesture) – The object which received the signal
- sequence (Gdk.EventSequenceorNone) – theGdk.EventSequencethat was cancelled
- state (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. 
- gesture (
- 
Gtk.Gesture.signals.update(gesture, sequence)¶
- Signal Name: - update- Flags: - Parameters: - gesture (Gtk.Gesture) – The object which received the signal
- sequence (Gdk.EventSequenceorNone) – theGdk.EventSequencethat 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. 
- gesture (
Property Details¶
- 
Gtk.Gesture.props.n_points¶
- Name: - n-points- Type: - int- Default Value: - 1- Flags: - READABLE,- WRITABLE,- CONSTRUCT_ONLY- The number of touch points that trigger recognition on this gesture, - New in version 3.14. 
- 
Gtk.Gesture.props.window¶
- Name: - window- Type: - Gdk.Window- Default Value: - None- Flags: - READABLE,- WRITABLE- If non- - None, the gesture will only listen for events that happen on this- Gdk.Window, or a child of it.- New in version 3.14.