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
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
// 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 gdk_sys;
use glib::object::IsA;
use glib::object::ObjectType as ObjectType_;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use glib::GString;
use glib::StaticType;
use glib::Value;
use glib_sys;
use gobject_sys;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem;
use std::mem::transmute;
use std::ptr;
use Atom;
#[cfg(any(feature = "v3_22", feature = "dox"))]
use AxisFlags;
use AxisUse;
use Cursor;
use DeviceManager;
#[cfg(any(feature = "v3_22", feature = "dox"))]
use DeviceTool;
use DeviceType;
use Display;
use EventMask;
use GrabOwnership;
use GrabStatus;
use InputMode;
use InputSource;
use ModifierType;
use Screen;
#[cfg(any(feature = "v3_20", feature = "dox"))]
use Seat;
use Window;

glib_wrapper! {
    /// The `Device` object represents a single input device, such
    /// as a keyboard, a mouse, a touchpad, etc.
    ///
    /// See the `DeviceManager` documentation for more information
    /// about the various kinds of master and slave devices, and their
    /// relationships.
    pub struct Device(Object<gdk_sys::GdkDevice, DeviceClass>);

    match fn {
        get_type => || gdk_sys::gdk_device_get_type(),
    }
}

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

    /// Returns the axes currently available on the device.
    ///
    /// Feature: `v3_22`
    ///
    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn get_axes(&self) -> AxisFlags {
        unsafe { from_glib(gdk_sys::gdk_device_get_axes(self.to_glib_none().0)) }
    }

    //pub fn get_axis(&self, axes: &[f64], use_: AxisUse) -> Option<f64> {
    //    unsafe { TODO: call gdk_sys:gdk_device_get_axis() }
    //}

    /// Returns the axis use for `index_`.
    /// ## `index_`
    /// the index of the axis.
    ///
    /// # Returns
    ///
    /// a `AxisUse` specifying how the axis is used.
    pub fn get_axis_use(&self, index_: u32) -> AxisUse {
        unsafe {
            from_glib(gdk_sys::gdk_device_get_axis_use(
                self.to_glib_none().0,
                index_,
            ))
        }
    }

    //pub fn get_axis_value(&self, axes: &[f64], axis_label: &Atom) -> Option<f64> {
    //    unsafe { TODO: call gdk_sys:gdk_device_get_axis_value() }
    //}

    /// Returns the device type for `self`.
    ///
    /// # Returns
    ///
    /// the `DeviceType` for `self`.
    pub fn get_device_type(&self) -> DeviceType {
        unsafe { from_glib(gdk_sys::gdk_device_get_device_type(self.to_glib_none().0)) }
    }

    /// Returns the `Display` to which `self` pertains.
    ///
    /// # Returns
    ///
    /// a `Display`. This memory is owned
    ///  by GTK+, and must not be freed or unreffed.
    pub fn get_display(&self) -> Display {
        unsafe { from_glib_none(gdk_sys::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
    pub fn get_has_cursor(&self) -> bool {
        unsafe { from_glib(gdk_sys::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.
    /// ## `keyval`
    /// return value for the keyval.
    /// ## `modifiers`
    /// return value for modifiers.
    ///
    /// # Returns
    ///
    /// `true` if keyval is set for `index`.
    pub fn get_key(&self, index_: u32) -> Option<(u32, ModifierType)> {
        unsafe {
            let mut keyval = mem::MaybeUninit::uninit();
            let mut modifiers = mem::MaybeUninit::uninit();
            let ret = from_glib(gdk_sys::gdk_device_get_key(
                self.to_glib_none().0,
                index_,
                keyval.as_mut_ptr(),
                modifiers.as_mut_ptr(),
            ));
            let keyval = keyval.assume_init();
            let modifiers = modifiers.assume_init();
            if ret {
                Some((keyval, from_glib(modifiers)))
            } 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
    pub fn get_last_event_window(&self) -> Option<Window> {
        unsafe {
            from_glib_none(gdk_sys::gdk_device_get_last_event_window(
                self.to_glib_none().0,
            ))
        }
    }

    /// Determines the mode of the device.
    ///
    /// # Returns
    ///
    /// a `InputSource`
    pub fn get_mode(&self) -> InputMode {
        unsafe { from_glib(gdk_sys::gdk_device_get_mode(self.to_glib_none().0)) }
    }

    /// Returns the number of axes the device currently has.
    ///
    /// # Returns
    ///
    /// the number of axes.
    pub fn get_n_axes(&self) -> i32 {
        unsafe { gdk_sys::gdk_device_get_n_axes(self.to_glib_none().0) }
    }

    /// Returns the number of keys the device currently has.
    ///
    /// # Returns
    ///
    /// the number of keys.
    pub fn get_n_keys(&self) -> i32 {
        unsafe { gdk_sys::gdk_device_get_n_keys(self.to_glib_none().0) }
    }

    /// Determines the name of the device.
    ///
    /// # Returns
    ///
    /// a name
    pub fn get_name(&self) -> Option<GString> {
        unsafe { from_glib_none(gdk_sys::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`,
    /// unless there is an ongoing grab on them, see `Device::grab`.
    /// ## `screen`
    /// location to store the `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`.
    pub fn get_position(&self) -> (Screen, i32, i32) {
        unsafe {
            let mut screen = ptr::null_mut();
            let mut x = mem::MaybeUninit::uninit();
            let mut y = mem::MaybeUninit::uninit();
            gdk_sys::gdk_device_get_position(
                self.to_glib_none().0,
                &mut screen,
                x.as_mut_ptr(),
                y.as_mut_ptr(),
            );
            let x = x.assume_init();
            let y = y.assume_init();
            (from_glib_none(screen), x, y)
        }
    }

    /// 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`,
    /// unless there is an ongoing grab on them. See `Device::grab`.
    /// ## `screen`
    /// location to store the `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`.
    pub fn get_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();
            gdk_sys::gdk_device_get_position_double(
                self.to_glib_none().0,
                &mut screen,
                x.as_mut_ptr(),
                y.as_mut_ptr(),
            );
            let x = x.assume_init();
            let y = y.assume_init();
            (from_glib_none(screen), x, y)
        }
    }

    /// 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 `Device::get_vendor_id` for more information.
    ///
    /// Feature: `v3_16`
    ///
    ///
    /// # Returns
    ///
    /// the product ID, or `None`
    #[cfg(any(feature = "v3_16", feature = "dox"))]
    pub fn get_product_id(&self) -> Option<GString> {
        unsafe { from_glib_none(gdk_sys::gdk_device_get_product_id(self.to_glib_none().0)) }
    }

    /// Returns the `Seat` the device belongs to.
    ///
    /// Feature: `v3_20`
    ///
    ///
    /// # Returns
    ///
    /// A `Seat`. This memory is owned by GTK+ and
    ///  must not be freed.
    #[cfg(any(feature = "v3_20", feature = "dox"))]
    pub fn get_seat(&self) -> Option<Seat> {
        unsafe { from_glib_none(gdk_sys::gdk_device_get_seat(self.to_glib_none().0)) }
    }

    /// Determines the type of the device.
    ///
    /// # Returns
    ///
    /// a `InputSource`
    pub fn get_source(&self) -> InputSource {
        unsafe { from_glib(gdk_sys::gdk_device_get_source(self.to_glib_none().0)) }
    }

    //pub fn get_state<P: IsA<Window>>(&self, window: &P, axes: &[f64]) -> ModifierType {
    //    unsafe { TODO: call gdk_sys: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 `Device::get_product_id`, can be used to eg.
    /// compose `gio::Settings` paths to store settings for this device.
    ///
    ///
    /// ```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;
    ///  }
    /// ```
    ///
    /// Feature: `v3_16`
    ///
    ///
    /// # Returns
    ///
    /// the vendor ID, or `None`
    #[cfg(any(feature = "v3_16", feature = "dox"))]
    pub fn get_vendor_id(&self) -> Option<GString> {
        unsafe { from_glib_none(gdk_sys::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`,
    /// unless there is an ongoing grab on them, see `Device::grab`.
    /// ## `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`.
    ///
    /// # Returns
    ///
    /// the `Window` under the
    /// device position, or `None`.
    pub fn get_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(gdk_sys::gdk_device_get_window_at_position(
                self.to_glib_none().0,
                win_x.as_mut_ptr(),
                win_y.as_mut_ptr(),
            ));
            let win_x = win_x.assume_init();
            let win_y = win_y.assume_init();
            (ret, win_x, win_y)
        }
    }

    /// 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`,
    /// unless there is an ongoing grab on them, see `Device::grab`.
    /// ## `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`.
    ///
    /// # Returns
    ///
    /// the `Window` under the
    ///  device position, or `None`.
    pub fn get_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(gdk_sys::gdk_device_get_window_at_position_double(
                self.to_glib_none().0,
                win_x.as_mut_ptr(),
                win_y.as_mut_ptr(),
            ));
            let win_x = win_x.assume_init();
            let win_y = win_y.assume_init();
            (ret, win_x, win_y)
        }
    }

    /// Grabs the device so that all events coming from this device are passed to
    /// this application until the device is ungrabbed with `Device::ungrab`,
    /// or the window becomes unviewable. This overrides any previous grab on the device
    /// by this client.
    ///
    /// Note that `self` and `window` need to be on the same display.
    ///
    /// Device grabs are used for operations which need complete control over the
    /// given device events (either pointer or keyboard). For example in GTK+ this
    /// is used for Drag and Drop operations, popup menus and such.
    ///
    /// Note that if the event mask of an X window has selected both button press
    /// and button release events, then a button press event will cause an automatic
    /// pointer grab until the button is released. X does this automatically since
    /// most applications expect to receive button press and release events in pairs.
    /// It is equivalent to a pointer grab on the window with `owner_events` set to
    /// `true`.
    ///
    /// If you set up anything at the time you take the grab that needs to be
    /// cleaned up when the grab ends, you should handle the `EventGrabBroken`
    /// events that are emitted when the grab ends unvoluntarily.
    ///
    /// # Deprecated since 3.20
    ///
    /// Use `Seat::grab` instead.
    /// ## `window`
    /// the `Window` which will own the grab (the grab window)
    /// ## `grab_ownership`
    /// specifies the grab ownership.
    /// ## `owner_events`
    /// if `false` then all device events are reported with respect to
    ///  `window` and are only reported if selected by `event_mask`. If
    ///  `true` then pointer events for this application are reported
    ///  as normal, but pointer events outside this application are
    ///  reported with respect to `window` and only if selected by
    ///  `event_mask`. In either mode, unreported events are discarded.
    /// ## `event_mask`
    /// specifies the event mask, which is used in accordance with
    ///  `owner_events`.
    /// ## `cursor`
    /// the cursor to display while the grab is active if the device is
    ///  a pointer. If this is `None` then the normal cursors are used for
    ///  `window` and its descendants, and the cursor for `window` is used
    ///  elsewhere.
    /// ## `time_`
    /// the timestamp of the event which led to this pointer grab. This
    ///  usually comes from the ``GdkEvent`` struct, though `GDK_CURRENT_TIME`
    ///  can be used if the time isn’t known.
    ///
    /// # Returns
    ///
    /// `GrabStatus::Success` if the grab was successful.
    #[cfg_attr(feature = "v3_20", deprecated)]
    pub fn grab<P: IsA<Window>>(
        &self,
        window: &P,
        grab_ownership: GrabOwnership,
        owner_events: bool,
        event_mask: EventMask,
        cursor: Option<&Cursor>,
        time_: u32,
    ) -> GrabStatus {
        unsafe {
            from_glib(gdk_sys::gdk_device_grab(
                self.to_glib_none().0,
                window.as_ref().to_glib_none().0,
                grab_ownership.to_glib(),
                owner_events.to_glib(),
                event_mask.to_glib(),
                cursor.to_glib_none().0,
                time_,
            ))
        }
    }

    /// Returns a `glib::List` of ``GdkAtoms``, containing the labels for
    /// the axes that `self` currently has.
    ///
    /// # Returns
    ///
    ///
    ///  A `glib::List` of ``GdkAtoms``, free with `glib::List::free`.
    pub fn list_axes(&self) -> Vec<Atom> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(gdk_sys::gdk_device_list_axes(
                self.to_glib_none().0,
            ))
        }
    }

    /// If the device if of type `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 `glib::List::free`, the contents of the list are
    ///  owned by GTK+ and should not be freed.
    pub fn list_slave_devices(&self) -> Vec<Device> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(gdk_sys::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
    pub fn set_axis_use(&self, index_: u32, use_: AxisUse) {
        unsafe {
            gdk_sys::gdk_device_set_axis_use(self.to_glib_none().0, index_, use_.to_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
    pub fn set_key(&self, index_: u32, keyval: u32, modifiers: ModifierType) {
        unsafe {
            gdk_sys::gdk_device_set_key(self.to_glib_none().0, index_, keyval, modifiers.to_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.
    pub fn set_mode(&self, mode: InputMode) -> bool {
        unsafe {
            from_glib(gdk_sys::gdk_device_set_mode(
                self.to_glib_none().0,
                mode.to_glib(),
            ))
        }
    }

    /// Release any grab on `self`.
    ///
    /// # Deprecated since 3.20
    ///
    /// Use `Seat::ungrab` instead.
    /// ## `time_`
    /// a timestap (e.g. `GDK_CURRENT_TIME`).
    #[cfg_attr(feature = "v3_20", deprecated)]
    pub fn ungrab(&self, time_: u32) {
        unsafe {
            gdk_sys::gdk_device_ungrab(self.to_glib_none().0, time_);
        }
    }

    /// 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.
    pub fn warp(&self, screen: &Screen, x: i32, y: i32) {
        unsafe {
            gdk_sys::gdk_device_warp(self.to_glib_none().0, screen.to_glib_none().0, x, y);
        }
    }

    /// The `DeviceManager` the `Device` pertains to.
    pub fn get_property_device_manager(&self) -> Option<DeviceManager> {
        unsafe {
            let mut value = Value::from_type(<DeviceManager as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.as_ptr() as *mut gobject_sys::GObject,
                b"device-manager\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `device-manager` getter")
        }
    }

    pub fn get_property_input_mode(&self) -> InputMode {
        unsafe {
            let mut value = Value::from_type(<InputMode as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.as_ptr() as *mut gobject_sys::GObject,
                b"input-mode\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `input-mode` getter")
                .unwrap()
        }
    }

    pub fn set_property_input_mode(&self, input_mode: InputMode) {
        unsafe {
            gobject_sys::g_object_set_property(
                self.as_ptr() as *mut gobject_sys::GObject,
                b"input-mode\0".as_ptr() as *const _,
                Value::from(&input_mode).to_glib_none().0,
            );
        }
    }

    /// Source type for the device.
    pub fn get_property_input_source(&self) -> InputSource {
        unsafe {
            let mut value = Value::from_type(<InputSource as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.as_ptr() as *mut gobject_sys::GObject,
                b"input-source\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `input-source` getter")
                .unwrap()
        }
    }

    /// 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.
    ///
    /// Feature: `v3_20`
    ///
    #[cfg(any(feature = "v3_20", feature = "dox"))]
    pub fn get_property_num_touches(&self) -> u32 {
        unsafe {
            let mut value = Value::from_type(<u32 as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.as_ptr() as *mut gobject_sys::GObject,
                b"num-touches\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `num-touches` getter")
                .unwrap()
        }
    }

    /// `Seat` of this device.
    ///
    /// Feature: `v3_20`
    ///
    #[cfg(any(feature = "v3_20", feature = "dox"))]
    pub fn set_property_seat(&self, seat: Option<&Seat>) {
        unsafe {
            gobject_sys::g_object_set_property(
                self.as_ptr() as *mut gobject_sys::GObject,
                b"seat\0".as_ptr() as *const _,
                Value::from(seat).to_glib_none().0,
            );
        }
    }

    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn get_property_tool(&self) -> Option<DeviceTool> {
        unsafe {
            let mut value = Value::from_type(<DeviceTool as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.as_ptr() as *mut gobject_sys::GObject,
                b"tool\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `tool` getter")
        }
    }

    /// Device role in the device manager.
    pub fn get_property_type(&self) -> DeviceType {
        unsafe {
            let mut value = Value::from_type(<DeviceType as StaticType>::static_type());
            gobject_sys::g_object_get_property(
                self.as_ptr() as *mut gobject_sys::GObject,
                b"type\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `type` getter")
                .unwrap()
        }
    }

    /// Determines information about the current keyboard grab.
    /// This is not public API and must not be used by applications.
    ///
    /// # Deprecated since 3.16
    ///
    /// The symbol was never meant to be used outside
    ///  of GTK+
    /// ## `display`
    /// the display for which to get the grab information
    /// ## `device`
    /// device to get the grab information from
    /// ## `grab_window`
    /// location to store current grab window
    /// ## `owner_events`
    /// location to store boolean indicating whether
    ///  the `owner_events` flag to `gdk_keyboard_grab` or
    ///  `gdk_pointer_grab` was `true`.
    ///
    /// # Returns
    ///
    /// `true` if this application currently has the
    ///  keyboard grabbed.
    #[cfg_attr(feature = "v3_16", deprecated)]
    pub fn grab_info_libgtk_only(display: &Display, device: &Device) -> Option<(Window, bool)> {
        skip_assert_initialized!();
        unsafe {
            let mut grab_window = ptr::null_mut();
            let mut owner_events = mem::MaybeUninit::uninit();
            let ret = from_glib(gdk_sys::gdk_device_grab_info_libgtk_only(
                display.to_glib_none().0,
                device.to_glib_none().0,
                &mut grab_window,
                owner_events.as_mut_ptr(),
            ));
            let owner_events = owner_events.assume_init();
            if ret {
                Some((from_glib_none(grab_window), from_glib(owner_events)))
            } else {
                None
            }
        }
    }

    /// The ::changed signal is emitted either when the `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.
    pub fn connect_changed<F: Fn(&Device) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn changed_trampoline<F: Fn(&Device) + 'static>(
            this: *mut gdk_sys::GdkDevice,
            f: glib_sys::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.
    ///
    /// Feature: `v3_22`
    ///
    /// ## `tool`
    /// The new current tool
    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn connect_tool_changed<F: Fn(&Device, &DeviceTool) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn tool_changed_trampoline<F: Fn(&Device, &DeviceTool) + 'static>(
            this: *mut gdk_sys::GdkDevice,
            tool: *mut gdk_sys::GdkDeviceTool,
            f: glib_sys::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),
            )
        }
    }

    pub fn connect_property_associated_device_notify<F: Fn(&Device) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_associated_device_trampoline<F: Fn(&Device) + 'static>(
            this: *mut gdk_sys::GdkDevice,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::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),
            )
        }
    }

    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn connect_property_axes_notify<F: Fn(&Device) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_axes_trampoline<F: Fn(&Device) + 'static>(
            this: *mut gdk_sys::GdkDevice,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::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),
            )
        }
    }

    pub fn connect_property_input_mode_notify<F: Fn(&Device) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_input_mode_trampoline<F: Fn(&Device) + 'static>(
            this: *mut gdk_sys::GdkDevice,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::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),
            )
        }
    }

    pub fn connect_property_n_axes_notify<F: Fn(&Device) + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn notify_n_axes_trampoline<F: Fn(&Device) + 'static>(
            this: *mut gdk_sys::GdkDevice,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::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),
            )
        }
    }

    #[cfg(any(feature = "v3_20", feature = "dox"))]
    pub fn connect_property_seat_notify<F: Fn(&Device) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_seat_trampoline<F: Fn(&Device) + 'static>(
            this: *mut gdk_sys::GdkDevice,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::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),
            )
        }
    }

    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn connect_property_tool_notify<F: Fn(&Device) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_tool_trampoline<F: Fn(&Device) + 'static>(
            this: *mut gdk_sys::GdkDevice,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::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),
            )
        }
    }

    pub fn connect_property_type_notify<F: Fn(&Device) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_type_trampoline<F: Fn(&Device) + 'static>(
            this: *mut gdk_sys::GdkDevice,
            _param_spec: glib_sys::gpointer,
            f: glib_sys::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 {
        write!(f, "Device")
    }
}