gtk4/auto/
gesture.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT
#![allow(deprecated)]

use crate::{ffi, EventController, EventSequenceState};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// [`Gesture`][crate::Gesture] is the base class for gesture recognition.
    ///
    /// Although [`Gesture`][crate::Gesture] 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::EventSequence`][crate::gdk::EventSequence]
    /// value for these).
    ///
    /// The number of touches that a [`Gesture`][crate::Gesture] need to be recognized is
    /// controlled by the [`n-points`][struct@crate::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 [`Gesture`][crate::Gesture] subclasses.
    ///
    /// A recognized gesture will then emit the following signals:
    ///
    /// - [`begin`][struct@crate::Gesture#begin] when the gesture is recognized.
    /// - [`update`][struct@crate::Gesture#update], whenever an input event is processed.
    /// - [`end`][struct@crate::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 [`EventControllerExt::set_propagation_phase()`][crate::prelude::EventControllerExt::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 [`Gesture`][crate::Gesture]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
    /// [`gdk::EventSequence`][crate::gdk::EventSequence]s triggering those.
    ///
    /// Within a widget, gestures can be grouped through [`GestureExt::group_with()`][crate::prelude::GestureExt::group_with()].
    /// Grouped gestures synchronize the state of sequences, so calling
    /// [`GestureExt::set_state()`][crate::prelude::GestureExt::set_state()] on one will effectively propagate
    /// the state throughout the group.
    ///
    /// By default, all sequences start out in the [`EventSequenceState::None`][crate::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`][crate::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`][crate::EventSequenceState::Claimed] state, the gesture
    /// group will grab all interaction on the sequence, by:
    ///
    /// - Setting the same sequence to [`EventSequenceState::Denied`][crate::EventSequenceState::Denied] on every other
    ///   gesture group within the widget, and every gesture on parent widgets
    ///   in the propagation chain.
    /// - Emitting [`cancel`][struct@crate::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`][crate::EventSequenceState::Claimed] on
    /// `GDK_TOUCH_BEGIN`/`GDK_BUTTON_PRESS` (so those events are captured before
    /// reaching the event widget, this implies [`PropagationPhase::Capture`][crate::PropagationPhase::Capture]), one similar
    /// event will be emulated if the sequence changes to [`EventSequenceState::Denied`][crate::EventSequenceState::Denied].
    /// This way event coherence is preserved before event propagation is unstopped
    /// again.
    ///
    /// Sequence states can't be changed freely.
    /// See [`GestureExt::set_state()`][crate::prelude::GestureExt::set_state()] to know about the possible
    /// lifetimes of a [`gdk::EventSequence`][crate::gdk::EventSequence].
    ///
    /// ## Touchpad gestures
    ///
    /// On the platforms that support it, [`Gesture`][crate::Gesture] will handle transparently
    /// touchpad gesture events. The only precautions users of [`Gesture`][crate::Gesture] should
    /// do to enable this support are:
    ///
    /// - If the gesture has [`PropagationPhase::None`][crate::PropagationPhase::None], ensuring events of type
    ///   `GDK_TOUCHPAD_SWIPE` and `GDK_TOUCHPAD_PINCH` are handled by the [`Gesture`][crate::Gesture]
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// ## Properties
    ///
    ///
    /// #### `n-points`
    ///  The number of touch points that trigger
    /// recognition on this gesture.
    ///
    /// Readable | Writeable | Construct Only
    /// <details><summary><h4>EventController</h4></summary>
    ///
    ///
    /// #### `name`
    ///  The name for this controller, typically used for debugging purposes.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `propagation-limit`
    ///  The limit for which events this controller will handle.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `propagation-phase`
    ///  The propagation phase at which this controller will handle events.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `widget`
    ///  The widget receiving the `GdkEvents` that the controller will handle.
    ///
    /// Readable
    /// </details>
    ///
    /// ## Signals
    ///
    ///
    /// #### `begin`
    ///  Emitted when the gesture is recognized.
    ///
    /// This means the number of touch sequences matches
    /// [`n-points`][struct@crate::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.
    ///
    ///
    ///
    ///
    /// #### `cancel`
    ///  Emitted whenever a sequence is cancelled.
    ///
    /// This usually happens on active touches when
    /// [`EventControllerExt::reset()`][crate::prelude::EventControllerExt::reset()] is called on @gesture
    /// (manually, due to grabs...), or the individual @sequence
    /// was claimed by parent widgets' controllers (see
    /// [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()]).
    ///
    /// @gesture must forget everything about @sequence as in
    /// response to this signal.
    ///
    ///
    ///
    ///
    /// #### `end`
    ///  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 [`n-points`][struct@crate::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 [`n-points`][struct@crate::Gesture#n-points]).
    /// This situation may be detected by checking through
    /// [`GestureExt::handles_sequence()`][crate::prelude::GestureExt::handles_sequence()].
    ///
    ///
    ///
    ///
    /// #### `sequence-state-changed`
    ///  Emitted whenever a sequence state changes.
    ///
    /// See [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()] to know
    /// more about the expectable sequence lifetimes.
    ///
    ///
    ///
    ///
    /// #### `update`
    ///  Emitted whenever an event is handled while the gesture is recognized.
    ///
    /// @sequence is guaranteed to pertain to the set of active touches.
    ///
    ///
    ///
    /// # Implements
    ///
    /// [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
    #[doc(alias = "GtkGesture")]
    pub struct Gesture(Object<ffi::GtkGesture, ffi::GtkGestureClass>) @extends EventController;

    match fn {
        type_ => || ffi::gtk_gesture_get_type(),
    }
}

impl Gesture {
    pub const NONE: Option<&'static Gesture> = None;
}

/// Trait containing all [`struct@Gesture`] methods.
///
/// # Implementors
///
/// [`GestureRotate`][struct@crate::GestureRotate], [`GestureSingle`][struct@crate::GestureSingle], [`GestureZoom`][struct@crate::GestureZoom], [`Gesture`][struct@crate::Gesture]
pub trait GestureExt: IsA<Gesture> + 'static {
    /// If there are touch sequences being currently handled by @self,
    /// 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.
    ///
    /// # Returns
    ///
    /// [`true`] if there are active touches, [`false`] otherwise
    ///
    /// ## `rect`
    /// bounding box containing all active touches.
    #[doc(alias = "gtk_gesture_get_bounding_box")]
    #[doc(alias = "get_bounding_box")]
    fn bounding_box(&self) -> Option<gdk::Rectangle> {
        unsafe {
            let mut rect = gdk::Rectangle::uninitialized();
            let ret = from_glib(ffi::gtk_gesture_get_bounding_box(
                self.as_ref().to_glib_none().0,
                rect.to_glib_none_mut().0,
            ));
            if ret {
                Some(rect)
            } else {
                None
            }
        }
    }

    /// If there are touch sequences being currently handled by @self,
    /// returns [`true`] and fills in @x and @y with the center of the bounding
    /// box containing all active touches.
    ///
    /// Otherwise, [`false`] will be returned.
    ///
    /// # 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
    #[doc(alias = "gtk_gesture_get_bounding_box_center")]
    #[doc(alias = "get_bounding_box_center")]
    fn bounding_box_center(&self) -> Option<(f64, f64)> {
        unsafe {
            let mut x = std::mem::MaybeUninit::uninit();
            let mut y = std::mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::gtk_gesture_get_bounding_box_center(
                self.as_ref().to_glib_none().0,
                x.as_mut_ptr(),
                y.as_mut_ptr(),
            ));
            if ret {
                Some((x.assume_init(), y.assume_init()))
            } else {
                None
            }
        }
    }

    /// Returns the logical [`gdk::Device`][crate::gdk::Device] that is currently operating
    /// on @self.
    ///
    /// This returns [`None`] if the gesture is not being interacted.
    ///
    /// # Returns
    ///
    /// a [`gdk::Device`][crate::gdk::Device]
    #[doc(alias = "gtk_gesture_get_device")]
    #[doc(alias = "get_device")]
    fn device(&self) -> Option<gdk::Device> {
        unsafe { from_glib_none(ffi::gtk_gesture_get_device(self.as_ref().to_glib_none().0)) }
    }

    /// Returns all gestures in the group of @self
    ///
    /// # Returns
    ///
    /// The list
    ///   of [`Gesture`][crate::Gesture]s, free with g_list_free()
    #[doc(alias = "gtk_gesture_get_group")]
    #[doc(alias = "get_group")]
    fn group(&self) -> Vec<Gesture> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gtk_gesture_get_group(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// 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.
    /// ## `sequence`
    /// a [`gdk::EventSequence`][crate::gdk::EventSequence]
    ///
    /// # Returns
    ///
    /// The last event from @sequence
    #[doc(alias = "gtk_gesture_get_last_event")]
    #[doc(alias = "get_last_event")]
    fn last_event(&self, sequence: Option<&gdk::EventSequence>) -> Option<gdk::Event> {
        unsafe {
            from_glib_none(ffi::gtk_gesture_get_last_event(
                self.as_ref().to_glib_none().0,
                mut_override(sequence.to_glib_none().0),
            ))
        }
    }

    /// Returns the [`gdk::EventSequence`][crate::gdk::EventSequence] that was last updated on @self.
    ///
    /// # Returns
    ///
    /// The last updated sequence
    #[doc(alias = "gtk_gesture_get_last_updated_sequence")]
    #[doc(alias = "get_last_updated_sequence")]
    fn last_updated_sequence(&self) -> Option<gdk::EventSequence> {
        unsafe {
            from_glib_none(ffi::gtk_gesture_get_last_updated_sequence(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// If @sequence is currently being interpreted by @self,
    /// 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.
    /// ## `sequence`
    /// a [`gdk::EventSequence`][crate::gdk::EventSequence], or [`None`] 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
    #[doc(alias = "gtk_gesture_get_point")]
    #[doc(alias = "get_point")]
    fn point(&self, sequence: Option<&gdk::EventSequence>) -> Option<(f64, f64)> {
        unsafe {
            let mut x = std::mem::MaybeUninit::uninit();
            let mut y = std::mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::gtk_gesture_get_point(
                self.as_ref().to_glib_none().0,
                mut_override(sequence.to_glib_none().0),
                x.as_mut_ptr(),
                y.as_mut_ptr(),
            ));
            if ret {
                Some((x.assume_init(), y.assume_init()))
            } else {
                None
            }
        }
    }

    /// Returns the @sequence state, as seen by @self.
    /// ## `sequence`
    /// a [`gdk::EventSequence`][crate::gdk::EventSequence]
    ///
    /// # Returns
    ///
    /// The sequence state in @self
    #[doc(alias = "gtk_gesture_get_sequence_state")]
    #[doc(alias = "get_sequence_state")]
    fn sequence_state(&self, sequence: &gdk::EventSequence) -> EventSequenceState {
        unsafe {
            from_glib(ffi::gtk_gesture_get_sequence_state(
                self.as_ref().to_glib_none().0,
                mut_override(sequence.to_glib_none().0),
            ))
        }
    }

    /// Returns the list of `GdkEventSequences` currently being interpreted
    /// by @self.
    ///
    /// # Returns
    ///
    /// A list
    ///   of [`gdk::EventSequence`][crate::gdk::EventSequence], the list elements are owned by GTK and must
    ///   not be freed or modified, the list itself must be deleted
    ///   through g_list_free()
    #[doc(alias = "gtk_gesture_get_sequences")]
    #[doc(alias = "get_sequences")]
    fn sequences(&self) -> Vec<gdk::EventSequence> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gtk_gesture_get_sequences(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Adds @gesture to the same group than @self.
    ///
    /// 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
    /// [`set_sequence_state()`][Self::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`][crate::gdk::EventSequence] state is set to [`EventSequenceState::Claimed`][crate::EventSequenceState::Claimed]
    /// on one group, every other gesture group attached to the same
    /// [`Widget`][crate::Widget] will switch the state for that sequence to
    /// [`EventSequenceState::Denied`][crate::EventSequenceState::Denied].
    /// ## `gesture`
    /// a [`Gesture`][crate::Gesture]
    #[doc(alias = "gtk_gesture_group")]
    #[doc(alias = "group")]
    fn group_with(&self, gesture: &impl IsA<Gesture>) {
        unsafe {
            ffi::gtk_gesture_group(
                self.as_ref().to_glib_none().0,
                gesture.as_ref().to_glib_none().0,
            );
        }
    }

    /// Returns [`true`] if @self is currently handling events
    /// corresponding to @sequence.
    /// ## `sequence`
    /// a [`gdk::EventSequence`][crate::gdk::EventSequence]
    ///
    /// # Returns
    ///
    /// [`true`] if @self is handling @sequence, [`false`] otherwise
    #[doc(alias = "gtk_gesture_handles_sequence")]
    fn handles_sequence(&self, sequence: Option<&gdk::EventSequence>) -> bool {
        unsafe {
            from_glib(ffi::gtk_gesture_handles_sequence(
                self.as_ref().to_glib_none().0,
                mut_override(sequence.to_glib_none().0),
            ))
        }
    }

    /// Returns [`true`] if the gesture is currently active.
    ///
    /// A gesture is active while there are touch sequences
    /// interacting with it.
    ///
    /// # Returns
    ///
    /// [`true`] if gesture is active
    #[doc(alias = "gtk_gesture_is_active")]
    fn is_active(&self) -> bool {
        unsafe { from_glib(ffi::gtk_gesture_is_active(self.as_ref().to_glib_none().0)) }
    }

    /// Returns [`true`] if both gestures pertain to the same group.
    /// ## `other`
    /// another [`Gesture`][crate::Gesture]
    ///
    /// # Returns
    ///
    /// whether the gestures are grouped
    #[doc(alias = "gtk_gesture_is_grouped_with")]
    fn is_grouped_with(&self, other: &impl IsA<Gesture>) -> bool {
        unsafe {
            from_glib(ffi::gtk_gesture_is_grouped_with(
                self.as_ref().to_glib_none().0,
                other.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Returns [`true`] if the gesture is currently recognized.
    ///
    /// A gesture is recognized if there are as many interacting
    /// touch sequences as required by @self.
    ///
    /// # Returns
    ///
    /// [`true`] if gesture is recognized
    #[doc(alias = "gtk_gesture_is_recognized")]
    fn is_recognized(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_gesture_is_recognized(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    /// Sets the state of @sequence in @self.
    ///
    /// Sequences start in state [`EventSequenceState::None`][crate::EventSequenceState::None], and whenever
    /// they change state, they can never go back to that state. Likewise,
    /// sequences in state [`EventSequenceState::Denied`][crate::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 [`begin`][struct@crate::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:
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// 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.
    ///
    /// # Deprecated since 4.10
    ///
    /// Use [`set_state()`][Self::set_state()]
    /// ## `sequence`
    /// a [`gdk::EventSequence`][crate::gdk::EventSequence]
    /// ## `state`
    /// the sequence state
    ///
    /// # Returns
    ///
    /// [`true`] if @sequence is handled by @self,
    ///   and the state is changed successfully
    #[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
    #[allow(deprecated)]
    #[doc(alias = "gtk_gesture_set_sequence_state")]
    fn set_sequence_state(&self, sequence: &gdk::EventSequence, state: EventSequenceState) -> bool {
        unsafe {
            from_glib(ffi::gtk_gesture_set_sequence_state(
                self.as_ref().to_glib_none().0,
                mut_override(sequence.to_glib_none().0),
                state.into_glib(),
            ))
        }
    }

    /// Sets the state of all sequences that @self is currently
    /// interacting with.
    ///
    /// Sequences start in state [`EventSequenceState::None`][crate::EventSequenceState::None], and whenever
    /// they change state, they can never go back to that state. Likewise,
    /// sequences in state [`EventSequenceState::Denied`][crate::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 [`begin`][struct@crate::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:
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// 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.
    /// ## `state`
    /// the sequence state
    ///
    /// # Returns
    ///
    /// [`true`] if the state of at least one sequence
    ///   was changed successfully
    #[doc(alias = "gtk_gesture_set_state")]
    fn set_state(&self, state: EventSequenceState) -> bool {
        unsafe {
            from_glib(ffi::gtk_gesture_set_state(
                self.as_ref().to_glib_none().0,
                state.into_glib(),
            ))
        }
    }

    /// Separates @self into an isolated group.
    #[doc(alias = "gtk_gesture_ungroup")]
    fn ungroup(&self) {
        unsafe {
            ffi::gtk_gesture_ungroup(self.as_ref().to_glib_none().0);
        }
    }

    /// The number of touch points that trigger
    /// recognition on this gesture.
    #[doc(alias = "n-points")]
    fn n_points(&self) -> u32 {
        ObjectExt::property(self.as_ref(), "n-points")
    }

    /// Emitted when the gesture is recognized.
    ///
    /// This means the number of touch sequences matches
    /// [`n-points`][struct@crate::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.
    /// ## `sequence`
    /// the [`gdk::EventSequence`][crate::gdk::EventSequence] that made the gesture
    ///   to be recognized
    #[doc(alias = "begin")]
    fn connect_begin<F: Fn(&Self, Option<&gdk::EventSequence>) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn begin_trampoline<
            P: IsA<Gesture>,
            F: Fn(&P, Option<&gdk::EventSequence>) + 'static,
        >(
            this: *mut ffi::GtkGesture,
            sequence: *mut gdk::ffi::GdkEventSequence,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Gesture::from_glib_borrow(this).unsafe_cast_ref(),
                Option::<gdk::EventSequence>::from_glib_borrow(sequence)
                    .as_ref()
                    .as_ref(),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"begin\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    begin_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted whenever a sequence is cancelled.
    ///
    /// This usually happens on active touches when
    /// [`EventControllerExt::reset()`][crate::prelude::EventControllerExt::reset()] is called on @gesture
    /// (manually, due to grabs...), or the individual @sequence
    /// was claimed by parent widgets' controllers (see
    /// [`set_sequence_state()`][Self::set_sequence_state()]).
    ///
    /// @gesture must forget everything about @sequence as in
    /// response to this signal.
    /// ## `sequence`
    /// the [`gdk::EventSequence`][crate::gdk::EventSequence] that was cancelled
    #[doc(alias = "cancel")]
    fn connect_cancel<F: Fn(&Self, Option<&gdk::EventSequence>) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn cancel_trampoline<
            P: IsA<Gesture>,
            F: Fn(&P, Option<&gdk::EventSequence>) + 'static,
        >(
            this: *mut ffi::GtkGesture,
            sequence: *mut gdk::ffi::GdkEventSequence,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Gesture::from_glib_borrow(this).unsafe_cast_ref(),
                Option::<gdk::EventSequence>::from_glib_borrow(sequence)
                    .as_ref()
                    .as_ref(),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"cancel\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    cancel_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// 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 [`n-points`][struct@crate::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 [`n-points`][struct@crate::Gesture#n-points]).
    /// This situation may be detected by checking through
    /// [`handles_sequence()`][Self::handles_sequence()].
    /// ## `sequence`
    /// the [`gdk::EventSequence`][crate::gdk::EventSequence] that made gesture
    ///   recognition to finish
    #[doc(alias = "end")]
    fn connect_end<F: Fn(&Self, Option<&gdk::EventSequence>) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn end_trampoline<
            P: IsA<Gesture>,
            F: Fn(&P, Option<&gdk::EventSequence>) + 'static,
        >(
            this: *mut ffi::GtkGesture,
            sequence: *mut gdk::ffi::GdkEventSequence,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Gesture::from_glib_borrow(this).unsafe_cast_ref(),
                Option::<gdk::EventSequence>::from_glib_borrow(sequence)
                    .as_ref()
                    .as_ref(),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"end\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    end_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted whenever a sequence state changes.
    ///
    /// See [`set_sequence_state()`][Self::set_sequence_state()] to know
    /// more about the expectable sequence lifetimes.
    /// ## `sequence`
    /// the [`gdk::EventSequence`][crate::gdk::EventSequence] that was cancelled
    /// ## `state`
    /// the new sequence state
    #[doc(alias = "sequence-state-changed")]
    fn connect_sequence_state_changed<
        F: Fn(&Self, Option<&gdk::EventSequence>, EventSequenceState) + 'static,
    >(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn sequence_state_changed_trampoline<
            P: IsA<Gesture>,
            F: Fn(&P, Option<&gdk::EventSequence>, EventSequenceState) + 'static,
        >(
            this: *mut ffi::GtkGesture,
            sequence: *mut gdk::ffi::GdkEventSequence,
            state: ffi::GtkEventSequenceState,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Gesture::from_glib_borrow(this).unsafe_cast_ref(),
                Option::<gdk::EventSequence>::from_glib_borrow(sequence)
                    .as_ref()
                    .as_ref(),
                from_glib(state),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"sequence-state-changed\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    sequence_state_changed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted whenever an event is handled while the gesture is recognized.
    ///
    /// @sequence is guaranteed to pertain to the set of active touches.
    /// ## `sequence`
    /// the [`gdk::EventSequence`][crate::gdk::EventSequence] that was updated
    #[doc(alias = "update")]
    fn connect_update<F: Fn(&Self, Option<&gdk::EventSequence>) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn update_trampoline<
            P: IsA<Gesture>,
            F: Fn(&P, Option<&gdk::EventSequence>) + 'static,
        >(
            this: *mut ffi::GtkGesture,
            sequence: *mut gdk::ffi::GdkEventSequence,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                Gesture::from_glib_borrow(this).unsafe_cast_ref(),
                Option::<gdk::EventSequence>::from_glib_borrow(sequence)
                    .as_ref()
                    .as_ref(),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"update\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    update_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl<O: IsA<Gesture>> GestureExt for O {}