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
// 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::Atom;
use crate::AxisFlags;
use crate::AxisUse;
use crate::DeviceManager;
use crate::DeviceTool;
use crate::DeviceType;
use crate::Display;
use crate::InputMode;
use crate::InputSource;
use crate::ModifierType;
use crate::Screen;
use crate::Seat;
use crate::Window;
use glib::object::ObjectType as ObjectType_;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem;
use std::mem::transmute;
use std::ptr;

glib::wrapper! {
    /// The [`Device`][crate::Device] object represents a single input device, such
    /// as a keyboard, a mouse, a touchpad, etc.
    ///
    /// See the [`DeviceManager`][crate::DeviceManager] documentation for more information
    /// about the various kinds of master and slave devices, and their
    /// relationships.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    #[doc(alias = "GdkDevice")]
    pub struct Device(Object<ffi::GdkDevice>);

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

impl Device {
    /// Returns the associated device to `self`, if `self` is of type
    /// [`DeviceType::Master`][crate::DeviceType::Master], it will return the paired pointer or
    /// keyboard.
    ///
    /// If `self` is of type [`DeviceType::Slave`][crate::DeviceType::Slave], it will return
    /// the master device to which `self` is attached to.
    ///
    /// If `self` is of type [`DeviceType::Floating`][crate::DeviceType::Floating], [`None`] will be
    /// returned, as there is no associated device.
    ///
    /// # Returns
    ///
    /// The associated device, or
    ///  [`None`]
    #[doc(alias = "gdk_device_get_associated_device")]
    #[doc(alias = "get_associated_device")]
    #[must_use]
    pub fn associated_device(&self) -> Option<Device> {
        unsafe { from_glib_none(ffi::gdk_device_get_associated_device(self.to_glib_none().0)) }
    }

    /// Returns the axes currently available on the device.
    #[doc(alias = "gdk_device_get_axes")]
    #[doc(alias = "get_axes")]
    pub fn axes(&self) -> AxisFlags {
        unsafe { from_glib(ffi::gdk_device_get_axes(self.to_glib_none().0)) }
    }

    //#[doc(alias = "gdk_device_get_axis")]
    //#[doc(alias = "get_axis")]
    //pub fn axis(&self, axes: &[f64], use_: AxisUse) -> Option<f64> {
    //    unsafe { TODO: call ffi:gdk_device_get_axis() }
    //}

    /// Returns the axis use for `index_`.
    /// ## `index_`
    /// the index of the axis.
    ///
    /// # Returns
    ///
    /// a [`AxisUse`][crate::AxisUse] specifying how the axis is used.
    #[doc(alias = "gdk_device_get_axis_use")]
    #[doc(alias = "get_axis_use")]
    pub fn axis_use(&self, index_: u32) -> AxisUse {
        unsafe { from_glib(ffi::gdk_device_get_axis_use(self.to_glib_none().0, index_)) }
    }

    //#[doc(alias = "gdk_device_get_axis_value")]
    //#[doc(alias = "get_axis_value")]
    //pub fn axis_value(&self, axes: &[f64], axis_label: &Atom) -> Option<f64> {
    //    unsafe { TODO: call ffi:gdk_device_get_axis_value() }
    //}

    /// Returns the device type for `self`.
    ///
    /// # Returns
    ///
    /// the [`DeviceType`][crate::DeviceType] for `self`.
    #[doc(alias = "gdk_device_get_device_type")]
    #[doc(alias = "get_device_type")]
    pub fn device_type(&self) -> DeviceType {
        unsafe { from_glib(ffi::gdk_device_get_device_type(self.to_glib_none().0)) }
    }

    /// Returns the [`Display`][crate::Display] to which `self` pertains.
    ///
    /// # Returns
    ///
    /// a [`Display`][crate::Display]. This memory is owned
    ///  by GTK+, and must not be freed or unreffed.
    #[doc(alias = "gdk_device_get_display")]
    #[doc(alias = "get_display")]
    pub fn display(&self) -> Display {
        unsafe { from_glib_none(ffi::gdk_device_get_display(self.to_glib_none().0)) }
    }

    /// Determines whether the pointer follows device motion.
    /// This is not meaningful for keyboard devices, which don't have a pointer.
    ///
    /// # Returns
    ///
    /// [`true`] if the pointer follows device motion
    #[doc(alias = "gdk_device_get_has_cursor")]
    #[doc(alias = "get_has_cursor")]
    pub fn has_cursor(&self) -> bool {
        unsafe { from_glib(ffi::gdk_device_get_has_cursor(self.to_glib_none().0)) }
    }

    /// If `index_` has a valid keyval, this function will return [`true`]
    /// and fill in `keyval` and `modifiers` with the keyval settings.
    /// ## `index_`
    /// the index of the macro button to get.
    ///
    /// # Returns
    ///
    /// [`true`] if keyval is set for `index`.
    ///
    /// ## `keyval`
    /// return value for the keyval.
    ///
    /// ## `modifiers`
    /// return value for modifiers.
    #[doc(alias = "gdk_device_get_key")]
    #[doc(alias = "get_key")]
    pub fn key(&self, index_: u32) -> Option<(u32, ModifierType)> {
        unsafe {
            let mut keyval = mem::MaybeUninit::uninit();
            let mut modifiers = mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::gdk_device_get_key(
                self.to_glib_none().0,
                index_,
                keyval.as_mut_ptr(),
                modifiers.as_mut_ptr(),
            ));
            if ret {
                Some((keyval.assume_init(), from_glib(modifiers.assume_init())))
            } else {
                None
            }
        }
    }

    /// Gets information about which window the given pointer device is in, based on events
    /// that have been received so far from the display server. If another application
    /// has a pointer grab, or this application has a grab with owner_events = [`false`],
    /// [`None`] may be returned even if the pointer is physically over one of this
    /// application's windows.
    ///
    /// # Returns
    ///
    /// the last window the device
    #[doc(alias = "gdk_device_get_last_event_window")]
    #[doc(alias = "get_last_event_window")]
    pub fn last_event_window(&self) -> Option<Window> {
        unsafe { from_glib_none(ffi::gdk_device_get_last_event_window(self.to_glib_none().0)) }
    }

    /// Determines the mode of the device.
    ///
    /// # Returns
    ///
    /// a [`InputSource`][crate::InputSource]
    #[doc(alias = "gdk_device_get_mode")]
    #[doc(alias = "get_mode")]
    pub fn mode(&self) -> InputMode {
        unsafe { from_glib(ffi::gdk_device_get_mode(self.to_glib_none().0)) }
    }

    /// Returns the number of axes the device currently has.
    ///
    /// # Returns
    ///
    /// the number of axes.
    #[doc(alias = "gdk_device_get_n_axes")]
    #[doc(alias = "get_n_axes")]
    pub fn n_axes(&self) -> i32 {
        unsafe { ffi::gdk_device_get_n_axes(self.to_glib_none().0) }
    }

    /// Returns the number of keys the device currently has.
    ///
    /// # Returns
    ///
    /// the number of keys.
    #[doc(alias = "gdk_device_get_n_keys")]
    #[doc(alias = "get_n_keys")]
    pub fn n_keys(&self) -> i32 {
        unsafe { ffi::gdk_device_get_n_keys(self.to_glib_none().0) }
    }

    /// Determines the name of the device.
    ///
    /// # Returns
    ///
    /// a name
    #[doc(alias = "gdk_device_get_name")]
    #[doc(alias = "get_name")]
    pub fn name(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::gdk_device_get_name(self.to_glib_none().0)) }
    }

    /// Gets the current location of `self`. As a slave device
    /// coordinates are those of its master pointer, This function
    /// may not be called on devices of type [`DeviceType::Slave`][crate::DeviceType::Slave],
    /// unless there is an ongoing grab on them, see `gdk_device_grab()`.
    ///
    /// # Returns
    ///
    ///
    /// ## `screen`
    /// location to store the [`Screen`][crate::Screen]
    ///  the `self` is on, or [`None`].
    ///
    /// ## `x`
    /// location to store root window X coordinate of `self`, or [`None`].
    ///
    /// ## `y`
    /// location to store root window Y coordinate of `self`, or [`None`].
    #[doc(alias = "gdk_device_get_position")]
    #[doc(alias = "get_position")]
    pub fn position(&self) -> (Screen, i32, i32) {
        unsafe {
            let mut screen = ptr::null_mut();
            let mut x = mem::MaybeUninit::uninit();
            let mut y = mem::MaybeUninit::uninit();
            ffi::gdk_device_get_position(
                self.to_glib_none().0,
                &mut screen,
                x.as_mut_ptr(),
                y.as_mut_ptr(),
            );
            (from_glib_none(screen), x.assume_init(), y.assume_init())
        }
    }

    /// Gets the current location of `self` in double precision. As a slave device's
    /// coordinates are those of its master pointer, this function
    /// may not be called on devices of type [`DeviceType::Slave`][crate::DeviceType::Slave],
    /// unless there is an ongoing grab on them. See `gdk_device_grab()`.
    ///
    /// # Returns
    ///
    ///
    /// ## `screen`
    /// location to store the [`Screen`][crate::Screen]
    ///  the `self` is on, or [`None`].
    ///
    /// ## `x`
    /// location to store root window X coordinate of `self`, or [`None`].
    ///
    /// ## `y`
    /// location to store root window Y coordinate of `self`, or [`None`].
    #[doc(alias = "gdk_device_get_position_double")]
    #[doc(alias = "get_position_double")]
    pub fn position_double(&self) -> (Screen, f64, f64) {
        unsafe {
            let mut screen = ptr::null_mut();
            let mut x = mem::MaybeUninit::uninit();
            let mut y = mem::MaybeUninit::uninit();
            ffi::gdk_device_get_position_double(
                self.to_glib_none().0,
                &mut screen,
                x.as_mut_ptr(),
                y.as_mut_ptr(),
            );
            (from_glib_none(screen), x.assume_init(), y.assume_init())
        }
    }

    /// Returns the product ID of this device, or [`None`] if this information couldn't
    /// be obtained. This ID is retrieved from the device, and is thus constant for
    /// it. See [`vendor_id()`][Self::vendor_id()] for more information.
    ///
    /// # Returns
    ///
    /// the product ID, or [`None`]
    #[doc(alias = "gdk_device_get_product_id")]
    #[doc(alias = "get_product_id")]
    pub fn product_id(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::gdk_device_get_product_id(self.to_glib_none().0)) }
    }

    /// Returns the [`Seat`][crate::Seat] the device belongs to.
    ///
    /// # Returns
    ///
    /// A [`Seat`][crate::Seat]. This memory is owned by GTK+ and
    ///  must not be freed.
    #[doc(alias = "gdk_device_get_seat")]
    #[doc(alias = "get_seat")]
    pub fn seat(&self) -> Option<Seat> {
        unsafe { from_glib_none(ffi::gdk_device_get_seat(self.to_glib_none().0)) }
    }

    /// Determines the type of the device.
    ///
    /// # Returns
    ///
    /// a [`InputSource`][crate::InputSource]
    #[doc(alias = "gdk_device_get_source")]
    #[doc(alias = "get_source")]
    pub fn source(&self) -> InputSource {
        unsafe { from_glib(ffi::gdk_device_get_source(self.to_glib_none().0)) }
    }

    //#[doc(alias = "gdk_device_get_state")]
    //#[doc(alias = "get_state")]
    //pub fn state(&self, window: &Window, axes: &[f64]) -> ModifierType {
    //    unsafe { TODO: call ffi:gdk_device_get_state() }
    //}

    /// Returns the vendor ID of this device, or [`None`] if this information couldn't
    /// be obtained. This ID is retrieved from the device, and is thus constant for
    /// it.
    ///
    /// This function, together with [`product_id()`][Self::product_id()], can be used to eg.
    /// compose `GSettings` paths to store settings for this device.
    ///
    ///
    ///
    /// **⚠️ The following code is in C ⚠️**
    ///
    /// ```C
    ///  static GSettings *
    ///  get_device_settings (GdkDevice *device)
    ///  {
    ///    const gchar *vendor, *product;
    ///    GSettings *settings;
    ///    GdkDevice *device;
    ///    gchar *path;
    ///
    ///    vendor = gdk_device_get_vendor_id (device);
    ///    product = gdk_device_get_product_id (device);
    ///
    ///    path = g_strdup_printf ("/org/example/app/devices/%s:%s/", vendor, product);
    ///    settings = g_settings_new_with_path (DEVICE_SCHEMA, path);
    ///    g_free (path);
    ///
    ///    return settings;
    ///  }
    /// ```
    ///
    /// # Returns
    ///
    /// the vendor ID, or [`None`]
    #[doc(alias = "gdk_device_get_vendor_id")]
    #[doc(alias = "get_vendor_id")]
    pub fn vendor_id(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::gdk_device_get_vendor_id(self.to_glib_none().0)) }
    }

    /// Obtains the window underneath `self`, returning the location of the device in `win_x` and `win_y`. Returns
    /// [`None`] if the window tree under `self` is not known to GDK (for example, belongs to another application).
    ///
    /// As a slave device coordinates are those of its master pointer, This
    /// function may not be called on devices of type [`DeviceType::Slave`][crate::DeviceType::Slave],
    /// unless there is an ongoing grab on them, see `gdk_device_grab()`.
    ///
    /// # Returns
    ///
    /// the [`Window`][crate::Window] under the
    /// device position, or [`None`].
    ///
    /// ## `win_x`
    /// return location for the X coordinate of the device location,
    ///  relative to the window origin, or [`None`].
    ///
    /// ## `win_y`
    /// return location for the Y coordinate of the device location,
    ///  relative to the window origin, or [`None`].
    #[doc(alias = "gdk_device_get_window_at_position")]
    #[doc(alias = "get_window_at_position")]
    pub fn window_at_position(&self) -> (Option<Window>, i32, i32) {
        unsafe {
            let mut win_x = mem::MaybeUninit::uninit();
            let mut win_y = mem::MaybeUninit::uninit();
            let ret = from_glib_none(ffi::gdk_device_get_window_at_position(
                self.to_glib_none().0,
                win_x.as_mut_ptr(),
                win_y.as_mut_ptr(),
            ));
            (ret, win_x.assume_init(), win_y.assume_init())
        }
    }

    /// Obtains the window underneath `self`, returning the location of the device in `win_x` and `win_y` in
    /// double precision. Returns [`None`] if the window tree under `self` is not known to GDK (for example,
    /// belongs to another application).
    ///
    /// As a slave device coordinates are those of its master pointer, This
    /// function may not be called on devices of type [`DeviceType::Slave`][crate::DeviceType::Slave],
    /// unless there is an ongoing grab on them, see `gdk_device_grab()`.
    ///
    /// # Returns
    ///
    /// the [`Window`][crate::Window] under the
    ///  device position, or [`None`].
    ///
    /// ## `win_x`
    /// return location for the X coordinate of the device location,
    ///  relative to the window origin, or [`None`].
    ///
    /// ## `win_y`
    /// return location for the Y coordinate of the device location,
    ///  relative to the window origin, or [`None`].
    #[doc(alias = "gdk_device_get_window_at_position_double")]
    #[doc(alias = "get_window_at_position_double")]
    pub fn window_at_position_double(&self) -> (Option<Window>, f64, f64) {
        unsafe {
            let mut win_x = mem::MaybeUninit::uninit();
            let mut win_y = mem::MaybeUninit::uninit();
            let ret = from_glib_none(ffi::gdk_device_get_window_at_position_double(
                self.to_glib_none().0,
                win_x.as_mut_ptr(),
                win_y.as_mut_ptr(),
            ));
            (ret, win_x.assume_init(), win_y.assume_init())
        }
    }

    /// Returns a `GList` of `GdkAtoms`, containing the labels for
    /// the axes that `self` currently has.
    ///
    /// # Returns
    ///
    ///
    ///  A `GList` of `GdkAtoms`, free with `g_list_free()`.
    #[doc(alias = "gdk_device_list_axes")]
    pub fn list_axes(&self) -> Vec<Atom> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gdk_device_list_axes(
                self.to_glib_none().0,
            ))
        }
    }

    /// If the device if of type [`DeviceType::Master`][crate::DeviceType::Master], it will return
    /// the list of slave devices attached to it, otherwise it will return
    /// [`None`]
    ///
    /// # Returns
    ///
    ///
    ///  the list of slave devices, or [`None`]. The list must be
    ///  freed with `g_list_free()`, the contents of the list are
    ///  owned by GTK+ and should not be freed.
    #[doc(alias = "gdk_device_list_slave_devices")]
    pub fn list_slave_devices(&self) -> Vec<Device> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gdk_device_list_slave_devices(
                self.to_glib_none().0,
            ))
        }
    }

    /// Specifies how an axis of a device is used.
    /// ## `index_`
    /// the index of the axis
    /// ## `use_`
    /// specifies how the axis is used
    #[doc(alias = "gdk_device_set_axis_use")]
    pub fn set_axis_use(&self, index_: u32, use_: AxisUse) {
        unsafe {
            ffi::gdk_device_set_axis_use(self.to_glib_none().0, index_, use_.into_glib());
        }
    }

    /// Specifies the X key event to generate when a macro button of a device
    /// is pressed.
    /// ## `index_`
    /// the index of the macro button to set
    /// ## `keyval`
    /// the keyval to generate
    /// ## `modifiers`
    /// the modifiers to set
    #[doc(alias = "gdk_device_set_key")]
    pub fn set_key(&self, index_: u32, keyval: u32, modifiers: ModifierType) {
        unsafe {
            ffi::gdk_device_set_key(self.to_glib_none().0, index_, keyval, modifiers.into_glib());
        }
    }

    /// Sets a the mode of an input device. The mode controls if the
    /// device is active and whether the device’s range is mapped to the
    /// entire screen or to a single window.
    ///
    /// Note: This is only meaningful for floating devices, master devices (and
    /// slaves connected to these) drive the pointer cursor, which is not limited
    /// by the input mode.
    /// ## `mode`
    /// the input mode.
    ///
    /// # Returns
    ///
    /// [`true`] if the mode was successfully changed.
    #[doc(alias = "gdk_device_set_mode")]
    pub fn set_mode(&self, mode: InputMode) -> bool {
        unsafe {
            from_glib(ffi::gdk_device_set_mode(
                self.to_glib_none().0,
                mode.into_glib(),
            ))
        }
    }

    /// Warps `self` in `display` to the point `x`,`y` on
    /// the screen `screen`, unless the device is confined
    /// to a window by a grab, in which case it will be moved
    /// as far as allowed by the grab. Warping the pointer
    /// creates events as if the user had moved the mouse
    /// instantaneously to the destination.
    ///
    /// Note that the pointer should normally be under the
    /// control of the user. This function was added to cover
    /// some rare use cases like keyboard navigation support
    /// for the color picker in the `GtkColorSelectionDialog`.
    /// ## `screen`
    /// the screen to warp `self` to.
    /// ## `x`
    /// the X coordinate of the destination.
    /// ## `y`
    /// the Y coordinate of the destination.
    #[doc(alias = "gdk_device_warp")]
    pub fn warp(&self, screen: &Screen, x: i32, y: i32) {
        unsafe {
            ffi::gdk_device_warp(self.to_glib_none().0, screen.to_glib_none().0, x, y);
        }
    }

    /// The [`DeviceManager`][crate::DeviceManager] the [`Device`][crate::Device] pertains to.
    #[doc(alias = "device-manager")]
    pub fn device_manager(&self) -> Option<DeviceManager> {
        glib::ObjectExt::property(self, "device-manager")
    }

    #[doc(alias = "input-mode")]
    pub fn input_mode(&self) -> InputMode {
        glib::ObjectExt::property(self, "input-mode")
    }

    #[doc(alias = "input-mode")]
    pub fn set_input_mode(&self, input_mode: InputMode) {
        glib::ObjectExt::set_property(self, "input-mode", &input_mode)
    }

    /// Source type for the device.
    #[doc(alias = "input-source")]
    pub fn input_source(&self) -> InputSource {
        glib::ObjectExt::property(self, "input-source")
    }

    /// The maximal number of concurrent touches on a touch device.
    /// Will be 0 if the device is not a touch device or if the number
    /// of touches is unknown.
    #[doc(alias = "num-touches")]
    pub fn num_touches(&self) -> u32 {
        glib::ObjectExt::property(self, "num-touches")
    }

    /// [`Seat`][crate::Seat] of this device.
    pub fn set_seat(&self, seat: Option<&Seat>) {
        glib::ObjectExt::set_property(self, "seat", &seat)
    }

    pub fn tool(&self) -> Option<DeviceTool> {
        glib::ObjectExt::property(self, "tool")
    }

    /// Device role in the device manager.
    #[doc(alias = "type")]
    pub fn type_(&self) -> DeviceType {
        glib::ObjectExt::property(self, "type")
    }

    /// The ::changed signal is emitted either when the [`Device`][crate::Device]
    /// has changed the number of either axes or keys. For example
    /// In X this will normally happen when the slave device routing
    /// events through the master device changes (for example, user
    /// switches from the USB mouse to a tablet), in that case the
    /// master device will change to reflect the new slave device
    /// axes and keys.
    #[doc(alias = "changed")]
    pub fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn changed_trampoline<F: Fn(&Device) + 'static>(
            this: *mut ffi::GdkDevice,
            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"changed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    changed_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// The ::tool-changed signal is emitted on pen/eraser
    /// `GdkDevices` whenever tools enter or leave proximity.
    /// ## `tool`
    /// The new current tool
    #[doc(alias = "tool-changed")]
    pub fn connect_tool_changed<F: Fn(&Self, &DeviceTool) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn tool_changed_trampoline<F: Fn(&Device, &DeviceTool) + 'static>(
            this: *mut ffi::GdkDevice,
            tool: *mut ffi::GdkDeviceTool,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), &from_glib_borrow(tool))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"tool-changed\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    tool_changed_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "associated-device")]
    pub fn connect_associated_device_notify<F: Fn(&Self) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_associated_device_trampoline<F: Fn(&Device) + 'static>(
            this: *mut ffi::GdkDevice,
            _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::associated-device\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_associated_device_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "axes")]
    pub fn connect_axes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_axes_trampoline<F: Fn(&Device) + 'static>(
            this: *mut ffi::GdkDevice,
            _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::axes\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_axes_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "input-mode")]
    pub fn connect_input_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_input_mode_trampoline<F: Fn(&Device) + 'static>(
            this: *mut ffi::GdkDevice,
            _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::input-mode\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_input_mode_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "n-axes")]
    pub fn connect_n_axes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_n_axes_trampoline<F: Fn(&Device) + 'static>(
            this: *mut ffi::GdkDevice,
            _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::n-axes\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_n_axes_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "seat")]
    pub fn connect_seat_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_seat_trampoline<F: Fn(&Device) + 'static>(
            this: *mut ffi::GdkDevice,
            _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::seat\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_seat_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "tool")]
    pub fn connect_tool_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_tool_trampoline<F: Fn(&Device) + 'static>(
            this: *mut ffi::GdkDevice,
            _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::tool\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_tool_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "type")]
    pub fn connect_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_type_trampoline<F: Fn(&Device) + 'static>(
            this: *mut ffi::GdkDevice,
            _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::type\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_type_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

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