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
// 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

use crate::{EventController, Gesture, GestureSingle, PropagationLimit, PropagationPhase};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::{boxed::Box as Box_, fmt, mem, mem::transmute, ptr};

glib::wrapper! {
    /// [`GestureStylus`][crate::GestureStylus] is a [`Gesture`][crate::Gesture] specific to stylus input.
    ///
    /// The provided signals just relay the basic information of the
    /// stylus events.
    ///
    /// ## Properties
    ///
    ///
    /// #### `stylus-only`
    ///  If this gesture should exclusively react to stylus input devices.
    ///
    /// Readable | Writeable | Construct
    /// <details><summary><h4>GestureSingle</h4></summary>
    ///
    ///
    /// #### `button`
    ///  Mouse button number to listen to, or 0 to listen for any button.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `exclusive`
    ///  Whether the gesture is exclusive.
    ///
    /// Exclusive gestures only listen to pointer and pointer emulated events.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `touch-only`
    ///  Whether the gesture handles only touch events.
    ///
    /// Readable | Writeable
    /// </details>
    /// <details><summary><h4>Gesture</h4></summary>
    ///
    ///
    /// #### `n-points`
    ///  The number of touch points that trigger
    /// recognition on this gesture.
    ///
    /// Readable | Writeable | Construct Only
    /// </details>
    /// <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
    ///
    ///
    /// #### `down`
    ///  Emitted when the stylus touches the device.
    ///
    ///
    ///
    ///
    /// #### `motion`
    ///  Emitted when the stylus moves while touching the device.
    ///
    ///
    ///
    ///
    /// #### `proximity`
    ///  Emitted when the stylus is in proximity of the device.
    ///
    ///
    ///
    ///
    /// #### `up`
    ///  Emitted when the stylus no longer touches the device.
    ///
    ///
    /// <details><summary><h4>Gesture</h4></summary>
    ///
    ///
    /// #### `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.
    ///
    ///
    /// </details>
    ///
    /// # Implements
    ///
    /// [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
    #[doc(alias = "GtkGestureStylus")]
    pub struct GestureStylus(Object<ffi::GtkGestureStylus, ffi::GtkGestureStylusClass>) @extends GestureSingle, Gesture, EventController;

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

impl GestureStylus {
    /// Creates a new [`GestureStylus`][crate::GestureStylus].
    ///
    /// # Returns
    ///
    /// a newly created stylus gesture
    #[doc(alias = "gtk_gesture_stylus_new")]
    pub fn new() -> GestureStylus {
        assert_initialized_main_thread!();
        unsafe { Gesture::from_glib_full(ffi::gtk_gesture_stylus_new()).unsafe_cast() }
    }

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`GestureStylus`] objects.
    ///
    /// This method returns an instance of [`GestureStylusBuilder`](crate::builders::GestureStylusBuilder) which can be used to create [`GestureStylus`] objects.
    pub fn builder() -> GestureStylusBuilder {
        GestureStylusBuilder::new()
    }

    /// Returns the current value for the requested @axis.
    ///
    /// This function must be called from the handler of one of the
    /// [`down`][struct@crate::GestureStylus#down], [`motion`][struct@crate::GestureStylus#motion],
    /// [`up`][struct@crate::GestureStylus#up] or [`proximity`][struct@crate::GestureStylus#proximity]
    /// signals.
    /// ## `axis`
    /// requested device axis
    ///
    /// # Returns
    ///
    /// [`true`] if there is a current value for the axis
    ///
    /// ## `value`
    /// return location for the axis value
    #[doc(alias = "gtk_gesture_stylus_get_axis")]
    #[doc(alias = "get_axis")]
    pub fn axis(&self, axis: gdk::AxisUse) -> Option<f64> {
        unsafe {
            let mut value = mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::gtk_gesture_stylus_get_axis(
                self.to_glib_none().0,
                axis.into_glib(),
                value.as_mut_ptr(),
            ));
            if ret {
                Some(value.assume_init())
            } else {
                None
            }
        }
    }

    /// Returns the accumulated backlog of tracking information.
    ///
    /// By default, GTK will limit rate of input events. On stylus input
    /// where accuracy of strokes is paramount, this function returns the
    /// accumulated coordinate/timing state before the emission of the
    /// current [Gtk.GestureStylus::motion] signal.
    ///
    /// This function may only be called within a [`motion`][struct@crate::GestureStylus#motion]
    /// signal handler, the state given in this signal and obtainable through
    /// [`axis()`][Self::axis()] express the latest (most up-to-date)
    /// state in motion history.
    ///
    /// The @backlog is provided in chronological order.
    ///
    /// # Returns
    ///
    /// [`true`] if there is a backlog to unfold in the current state.
    ///
    /// ## `backlog`
    /// coordinates and times for the backlog events
    #[doc(alias = "gtk_gesture_stylus_get_backlog")]
    #[doc(alias = "get_backlog")]
    pub fn backlog(&self) -> Option<Vec<gdk::TimeCoord>> {
        unsafe {
            let mut backlog = ptr::null_mut();
            let mut n_elems = mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::gtk_gesture_stylus_get_backlog(
                self.to_glib_none().0,
                &mut backlog,
                n_elems.as_mut_ptr(),
            ));
            if ret {
                Some(FromGlibContainer::from_glib_full_num(
                    backlog,
                    n_elems.assume_init() as _,
                ))
            } else {
                None
            }
        }
    }

    /// Returns the [`gdk::DeviceTool`][crate::gdk::DeviceTool] currently driving input through this gesture.
    ///
    /// This function must be called from the handler of one of the
    /// [`down`][struct@crate::GestureStylus#down], [`motion`][struct@crate::GestureStylus#motion],
    /// [`up`][struct@crate::GestureStylus#up] or [`proximity`][struct@crate::GestureStylus#proximity]
    /// signals.
    ///
    /// # Returns
    ///
    /// The current stylus tool
    #[doc(alias = "gtk_gesture_stylus_get_device_tool")]
    #[doc(alias = "get_device_tool")]
    pub fn device_tool(&self) -> Option<gdk::DeviceTool> {
        unsafe {
            from_glib_none(ffi::gtk_gesture_stylus_get_device_tool(
                self.to_glib_none().0,
            ))
        }
    }

    /// Checks whether the gesture is for styluses only.
    ///
    /// Stylus-only gestures will signal events exclusively from stylus
    /// input devices.
    ///
    /// # Returns
    ///
    /// [`true`] if the gesture is only for stylus events
    #[cfg(feature = "v4_10")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
    #[doc(alias = "gtk_gesture_stylus_get_stylus_only")]
    #[doc(alias = "get_stylus_only")]
    pub fn is_stylus_only(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_gesture_stylus_get_stylus_only(
                self.to_glib_none().0,
            ))
        }
    }

    /// Sets the state of stylus-only
    ///
    /// If true, the gesture will exclusivly handle events from stylus input deivces,
    /// otherwise it'll handle events from any pointing device.
    /// ## `stylus_only`
    /// whether the gesture is used exclusivly for stylus events
    #[cfg(feature = "v4_10")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
    #[doc(alias = "gtk_gesture_stylus_set_stylus_only")]
    pub fn set_stylus_only(&self, stylus_only: bool) {
        unsafe {
            ffi::gtk_gesture_stylus_set_stylus_only(self.to_glib_none().0, stylus_only.into_glib());
        }
    }

    /// Emitted when the stylus touches the device.
    /// ## `x`
    /// the X coordinate of the stylus event
    /// ## `y`
    /// the Y coordinate of the stylus event
    #[doc(alias = "down")]
    pub fn connect_down<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn down_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
            this: *mut ffi::GtkGestureStylus,
            x: libc::c_double,
            y: libc::c_double,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), x, y)
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"down\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    down_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when the stylus moves while touching the device.
    /// ## `x`
    /// the X coordinate of the stylus event
    /// ## `y`
    /// the Y coordinate of the stylus event
    #[doc(alias = "motion")]
    pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn motion_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
            this: *mut ffi::GtkGestureStylus,
            x: libc::c_double,
            y: libc::c_double,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), x, y)
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"motion\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    motion_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when the stylus is in proximity of the device.
    /// ## `x`
    /// the X coordinate of the stylus event
    /// ## `y`
    /// the Y coordinate of the stylus event
    #[doc(alias = "proximity")]
    pub fn connect_proximity<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn proximity_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
            this: *mut ffi::GtkGestureStylus,
            x: libc::c_double,
            y: libc::c_double,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), x, y)
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"proximity\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    proximity_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when the stylus no longer touches the device.
    /// ## `x`
    /// the X coordinate of the stylus event
    /// ## `y`
    /// the Y coordinate of the stylus event
    #[doc(alias = "up")]
    pub fn connect_up<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn up_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
            this: *mut ffi::GtkGestureStylus,
            x: libc::c_double,
            y: libc::c_double,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), x, y)
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"up\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    up_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[cfg(feature = "v4_10")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
    #[doc(alias = "stylus-only")]
    pub fn connect_stylus_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_stylus_only_trampoline<F: Fn(&GestureStylus) + 'static>(
            this: *mut ffi::GtkGestureStylus,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::stylus-only\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_stylus_only_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl Default for GestureStylus {
    fn default() -> Self {
        Self::new()
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`GestureStylus`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct GestureStylusBuilder {
    builder: glib::object::ObjectBuilder<'static, GestureStylus>,
}

impl GestureStylusBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    /// If this gesture should exclusively react to stylus input devices.
    #[cfg(feature = "v4_10")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
    pub fn stylus_only(self, stylus_only: bool) -> Self {
        Self {
            builder: self.builder.property("stylus-only", stylus_only),
        }
    }

    /// Mouse button number to listen to, or 0 to listen for any button.
    pub fn button(self, button: u32) -> Self {
        Self {
            builder: self.builder.property("button", button),
        }
    }

    /// Whether the gesture is exclusive.
    ///
    /// Exclusive gestures only listen to pointer and pointer emulated events.
    pub fn exclusive(self, exclusive: bool) -> Self {
        Self {
            builder: self.builder.property("exclusive", exclusive),
        }
    }

    /// Whether the gesture handles only touch events.
    pub fn touch_only(self, touch_only: bool) -> Self {
        Self {
            builder: self.builder.property("touch-only", touch_only),
        }
    }

    /// The number of touch points that trigger
    /// recognition on this gesture.
    pub fn n_points(self, n_points: u32) -> Self {
        Self {
            builder: self.builder.property("n-points", n_points),
        }
    }

    /// The name for this controller, typically used for debugging purposes.
    pub fn name(self, name: impl Into<glib::GString>) -> Self {
        Self {
            builder: self.builder.property("name", name.into()),
        }
    }

    /// The limit for which events this controller will handle.
    pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
        Self {
            builder: self
                .builder
                .property("propagation-limit", propagation_limit),
        }
    }

    /// The propagation phase at which this controller will handle events.
    pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
        Self {
            builder: self
                .builder
                .property("propagation-phase", propagation_phase),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`GestureStylus`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> GestureStylus {
        self.builder.build()
    }
}

impl fmt::Display for GestureStylus {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("GestureStylus")
    }
}