Skip to main content

gdk/auto/
device.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6    Atom, AxisFlags, AxisUse, DeviceManager, DeviceTool, DeviceType, Display, InputMode,
7    InputSource, ModifierType, Screen, Seat, Window,
8};
9use glib::{
10    prelude::*,
11    signal::{connect_raw, SignalHandlerId},
12    translate::*,
13};
14use std::{boxed::Box as Box_, fmt, mem, mem::transmute, ptr};
15
16glib::wrapper! {
17    /// The [`Device`][crate::Device] object represents a single input device, such
18    /// as a keyboard, a mouse, a touchpad, etc.
19    ///
20    /// See the [`DeviceManager`][crate::DeviceManager] documentation for more information
21    /// about the various kinds of master and slave devices, and their
22    /// relationships.
23    ///
24    /// This is an Abstract Base Class, you cannot instantiate it.
25    ///
26    /// ## Properties
27    ///
28    ///
29    /// #### `associated-device`
30    ///  Associated pointer or keyboard with this device, if any. Devices of type [`DeviceType::Master`][crate::DeviceType::Master]
31    /// always come in keyboard/pointer pairs. Other device types will have a [`None`] associated device.
32    ///
33    /// Readable
34    ///
35    ///
36    /// #### `axes`
37    ///  The axes currently available for this device.
38    ///
39    /// Readable
40    ///
41    ///
42    /// #### `device-manager`
43    ///  The [`DeviceManager`][crate::DeviceManager] the [`Device`][crate::Device] pertains to.
44    ///
45    /// Readable | Writeable | Construct Only
46    ///
47    ///
48    /// #### `display`
49    ///  The [`Display`][crate::Display] the [`Device`][crate::Device] pertains to.
50    ///
51    /// Readable | Writeable | Construct Only
52    ///
53    ///
54    /// #### `has-cursor`
55    ///  Whether the device is represented by a cursor on the screen. Devices of type
56    /// [`DeviceType::Master`][crate::DeviceType::Master] will have [`true`] here.
57    ///
58    /// Readable | Writeable | Construct Only
59    ///
60    ///
61    /// #### `input-mode`
62    ///  Readable | Writeable
63    ///
64    ///
65    /// #### `input-source`
66    ///  Source type for the device.
67    ///
68    /// Readable | Writeable | Construct Only
69    ///
70    ///
71    /// #### `n-axes`
72    ///  Number of axes in the device.
73    ///
74    /// Readable
75    ///
76    ///
77    /// #### `name`
78    ///  The device name.
79    ///
80    /// Readable | Writeable | Construct Only
81    ///
82    ///
83    /// #### `num-touches`
84    ///  The maximal number of concurrent touches on a touch device.
85    /// Will be 0 if the device is not a touch device or if the number
86    /// of touches is unknown.
87    ///
88    /// Readable | Writeable | Construct Only
89    ///
90    ///
91    /// #### `product-id`
92    ///  Product ID of this device, see [`DeviceExt::product_id()`][crate::prelude::DeviceExt::product_id()].
93    ///
94    /// Readable | Writeable | Construct Only
95    ///
96    ///
97    /// #### `seat`
98    ///  [`Seat`][crate::Seat] of this device.
99    ///
100    /// Readable | Writeable
101    ///
102    ///
103    /// #### `tool`
104    ///  Readable
105    ///
106    ///
107    /// #### `type`
108    ///  Device role in the device manager.
109    ///
110    /// Readable | Writeable | Construct Only
111    ///
112    ///
113    /// #### `vendor-id`
114    ///  Vendor ID of this device, see [`DeviceExt::vendor_id()`][crate::prelude::DeviceExt::vendor_id()].
115    ///
116    /// Readable | Writeable | Construct Only
117    ///
118    /// ## Signals
119    ///
120    ///
121    /// #### `changed`
122    ///  The ::changed signal is emitted either when the [`Device`][crate::Device]
123    /// has changed the number of either axes or keys. For example
124    /// In X this will normally happen when the slave device routing
125    /// events through the master device changes (for example, user
126    /// switches from the USB mouse to a tablet), in that case the
127    /// master device will change to reflect the new slave device
128    /// axes and keys.
129    ///
130    ///
131    ///
132    ///
133    /// #### `tool-changed`
134    ///  The ::tool-changed signal is emitted on pen/eraser
135    /// `GdkDevices` whenever tools enter or leave proximity.
136    ///
137    ///
138    ///
139    /// # Implements
140    ///
141    /// [`DeviceExt`][trait@crate::prelude::DeviceExt], [`DeviceExtManual`][trait@crate::prelude::DeviceExtManual]
142    #[doc(alias = "GdkDevice")]
143    pub struct Device(Object<ffi::GdkDevice>);
144
145    match fn {
146        type_ => || ffi::gdk_device_get_type(),
147    }
148}
149
150impl Device {
151    pub const NONE: Option<&'static Device> = None;
152}
153
154mod sealed {
155    pub trait Sealed {}
156    impl<T: super::IsA<super::Device>> Sealed for T {}
157}
158
159/// Trait containing all [`struct@Device`] methods.
160///
161/// # Implementors
162///
163/// [`DevicePad`][struct@crate::DevicePad], [`Device`][struct@crate::Device]
164pub trait DeviceExt: IsA<Device> + sealed::Sealed + 'static {
165    /// Returns the associated device to `self`, if `self` is of type
166    /// [`DeviceType::Master`][crate::DeviceType::Master], it will return the paired pointer or
167    /// keyboard.
168    ///
169    /// If `self` is of type [`DeviceType::Slave`][crate::DeviceType::Slave], it will return
170    /// the master device to which `self` is attached to.
171    ///
172    /// If `self` is of type [`DeviceType::Floating`][crate::DeviceType::Floating], [`None`] will be
173    /// returned, as there is no associated device.
174    ///
175    /// # Returns
176    ///
177    /// The associated device, or
178    ///  [`None`]
179    #[doc(alias = "gdk_device_get_associated_device")]
180    #[doc(alias = "get_associated_device")]
181    #[must_use]
182    fn associated_device(&self) -> Option<Device> {
183        unsafe {
184            from_glib_none(ffi::gdk_device_get_associated_device(
185                self.as_ref().to_glib_none().0,
186            ))
187        }
188    }
189
190    /// Returns the axes currently available on the device.
191    #[doc(alias = "gdk_device_get_axes")]
192    #[doc(alias = "get_axes")]
193    fn axes(&self) -> AxisFlags {
194        unsafe { from_glib(ffi::gdk_device_get_axes(self.as_ref().to_glib_none().0)) }
195    }
196
197    //#[doc(alias = "gdk_device_get_axis")]
198    //#[doc(alias = "get_axis")]
199    //fn axis(&self, axes: &[f64], use_: AxisUse) -> Option<f64> {
200    //    unsafe { TODO: call ffi:gdk_device_get_axis() }
201    //}
202
203    /// Returns the axis use for `index_`.
204    /// ## `index_`
205    /// the index of the axis.
206    ///
207    /// # Returns
208    ///
209    /// a [`AxisUse`][crate::AxisUse] specifying how the axis is used.
210    #[doc(alias = "gdk_device_get_axis_use")]
211    #[doc(alias = "get_axis_use")]
212    fn axis_use(&self, index_: u32) -> AxisUse {
213        unsafe {
214            from_glib(ffi::gdk_device_get_axis_use(
215                self.as_ref().to_glib_none().0,
216                index_,
217            ))
218        }
219    }
220
221    //#[doc(alias = "gdk_device_get_axis_value")]
222    //#[doc(alias = "get_axis_value")]
223    //fn axis_value(&self, axes: &[f64], axis_label: &Atom) -> Option<f64> {
224    //    unsafe { TODO: call ffi:gdk_device_get_axis_value() }
225    //}
226
227    /// Returns the device type for `self`.
228    ///
229    /// # Returns
230    ///
231    /// the [`DeviceType`][crate::DeviceType] for `self`.
232    #[doc(alias = "gdk_device_get_device_type")]
233    #[doc(alias = "get_device_type")]
234    fn device_type(&self) -> DeviceType {
235        unsafe {
236            from_glib(ffi::gdk_device_get_device_type(
237                self.as_ref().to_glib_none().0,
238            ))
239        }
240    }
241
242    /// Returns the [`Display`][crate::Display] to which `self` pertains.
243    ///
244    /// # Returns
245    ///
246    /// a [`Display`][crate::Display]. This memory is owned
247    ///  by GTK+, and must not be freed or unreffed.
248    #[doc(alias = "gdk_device_get_display")]
249    #[doc(alias = "get_display")]
250    fn display(&self) -> Display {
251        unsafe { from_glib_none(ffi::gdk_device_get_display(self.as_ref().to_glib_none().0)) }
252    }
253
254    /// Determines whether the pointer follows device motion.
255    /// This is not meaningful for keyboard devices, which don't have a pointer.
256    ///
257    /// # Returns
258    ///
259    /// [`true`] if the pointer follows device motion
260    #[doc(alias = "gdk_device_get_has_cursor")]
261    #[doc(alias = "get_has_cursor")]
262    fn has_cursor(&self) -> bool {
263        unsafe {
264            from_glib(ffi::gdk_device_get_has_cursor(
265                self.as_ref().to_glib_none().0,
266            ))
267        }
268    }
269
270    /// If `index_` has a valid keyval, this function will return [`true`]
271    /// and fill in `keyval` and `modifiers` with the keyval settings.
272    /// ## `index_`
273    /// the index of the macro button to get.
274    ///
275    /// # Returns
276    ///
277    /// [`true`] if keyval is set for `index`.
278    ///
279    /// ## `keyval`
280    /// return value for the keyval.
281    ///
282    /// ## `modifiers`
283    /// return value for modifiers.
284    #[doc(alias = "gdk_device_get_key")]
285    #[doc(alias = "get_key")]
286    fn key(&self, index_: u32) -> Option<(u32, ModifierType)> {
287        unsafe {
288            let mut keyval = mem::MaybeUninit::uninit();
289            let mut modifiers = mem::MaybeUninit::uninit();
290            let ret = from_glib(ffi::gdk_device_get_key(
291                self.as_ref().to_glib_none().0,
292                index_,
293                keyval.as_mut_ptr(),
294                modifiers.as_mut_ptr(),
295            ));
296            if ret {
297                Some((keyval.assume_init(), from_glib(modifiers.assume_init())))
298            } else {
299                None
300            }
301        }
302    }
303
304    /// Gets information about which window the given pointer device is in, based on events
305    /// that have been received so far from the display server. If another application
306    /// has a pointer grab, or this application has a grab with owner_events = [`false`],
307    /// [`None`] may be returned even if the pointer is physically over one of this
308    /// application's windows.
309    ///
310    /// # Returns
311    ///
312    /// the last window the device
313    #[doc(alias = "gdk_device_get_last_event_window")]
314    #[doc(alias = "get_last_event_window")]
315    fn last_event_window(&self) -> Option<Window> {
316        unsafe {
317            from_glib_none(ffi::gdk_device_get_last_event_window(
318                self.as_ref().to_glib_none().0,
319            ))
320        }
321    }
322
323    /// Determines the mode of the device.
324    ///
325    /// # Returns
326    ///
327    /// a [`InputSource`][crate::InputSource]
328    #[doc(alias = "gdk_device_get_mode")]
329    #[doc(alias = "get_mode")]
330    fn mode(&self) -> InputMode {
331        unsafe { from_glib(ffi::gdk_device_get_mode(self.as_ref().to_glib_none().0)) }
332    }
333
334    /// Returns the number of axes the device currently has.
335    ///
336    /// # Returns
337    ///
338    /// the number of axes.
339    #[doc(alias = "gdk_device_get_n_axes")]
340    #[doc(alias = "get_n_axes")]
341    fn n_axes(&self) -> i32 {
342        unsafe { ffi::gdk_device_get_n_axes(self.as_ref().to_glib_none().0) }
343    }
344
345    /// Returns the number of keys the device currently has.
346    ///
347    /// # Returns
348    ///
349    /// the number of keys.
350    #[doc(alias = "gdk_device_get_n_keys")]
351    #[doc(alias = "get_n_keys")]
352    fn n_keys(&self) -> i32 {
353        unsafe { ffi::gdk_device_get_n_keys(self.as_ref().to_glib_none().0) }
354    }
355
356    /// Determines the name of the device.
357    ///
358    /// # Returns
359    ///
360    /// a name
361    #[doc(alias = "gdk_device_get_name")]
362    #[doc(alias = "get_name")]
363    fn name(&self) -> Option<glib::GString> {
364        unsafe { from_glib_none(ffi::gdk_device_get_name(self.as_ref().to_glib_none().0)) }
365    }
366
367    /// Gets the current location of `self`. As a slave device
368    /// coordinates are those of its master pointer, This function
369    /// may not be called on devices of type [`DeviceType::Slave`][crate::DeviceType::Slave],
370    /// unless there is an ongoing grab on them, see `gdk_device_grab()`.
371    ///
372    /// # Returns
373    ///
374    ///
375    /// ## `screen`
376    /// location to store the [`Screen`][crate::Screen]
377    ///  the `self` is on, or [`None`].
378    ///
379    /// ## `x`
380    /// location to store root window X coordinate of `self`, or [`None`].
381    ///
382    /// ## `y`
383    /// location to store root window Y coordinate of `self`, or [`None`].
384    #[doc(alias = "gdk_device_get_position")]
385    #[doc(alias = "get_position")]
386    fn position(&self) -> (Screen, i32, i32) {
387        unsafe {
388            let mut screen = ptr::null_mut();
389            let mut x = mem::MaybeUninit::uninit();
390            let mut y = mem::MaybeUninit::uninit();
391            ffi::gdk_device_get_position(
392                self.as_ref().to_glib_none().0,
393                &mut screen,
394                x.as_mut_ptr(),
395                y.as_mut_ptr(),
396            );
397            (from_glib_none(screen), x.assume_init(), y.assume_init())
398        }
399    }
400
401    /// Gets the current location of `self` in double precision. As a slave device's
402    /// coordinates are those of its master pointer, this function
403    /// may not be called on devices of type [`DeviceType::Slave`][crate::DeviceType::Slave],
404    /// unless there is an ongoing grab on them. See `gdk_device_grab()`.
405    ///
406    /// # Returns
407    ///
408    ///
409    /// ## `screen`
410    /// location to store the [`Screen`][crate::Screen]
411    ///  the `self` is on, or [`None`].
412    ///
413    /// ## `x`
414    /// location to store root window X coordinate of `self`, or [`None`].
415    ///
416    /// ## `y`
417    /// location to store root window Y coordinate of `self`, or [`None`].
418    #[doc(alias = "gdk_device_get_position_double")]
419    #[doc(alias = "get_position_double")]
420    fn position_double(&self) -> (Screen, f64, f64) {
421        unsafe {
422            let mut screen = ptr::null_mut();
423            let mut x = mem::MaybeUninit::uninit();
424            let mut y = mem::MaybeUninit::uninit();
425            ffi::gdk_device_get_position_double(
426                self.as_ref().to_glib_none().0,
427                &mut screen,
428                x.as_mut_ptr(),
429                y.as_mut_ptr(),
430            );
431            (from_glib_none(screen), x.assume_init(), y.assume_init())
432        }
433    }
434
435    /// Returns the product ID of this device, or [`None`] if this information couldn't
436    /// be obtained. This ID is retrieved from the device, and is thus constant for
437    /// it. See [`vendor_id()`][Self::vendor_id()] for more information.
438    ///
439    /// # Returns
440    ///
441    /// the product ID, or [`None`]
442    #[doc(alias = "gdk_device_get_product_id")]
443    #[doc(alias = "get_product_id")]
444    fn product_id(&self) -> Option<glib::GString> {
445        unsafe {
446            from_glib_none(ffi::gdk_device_get_product_id(
447                self.as_ref().to_glib_none().0,
448            ))
449        }
450    }
451
452    /// Returns the [`Seat`][crate::Seat] the device belongs to.
453    ///
454    /// # Returns
455    ///
456    /// A [`Seat`][crate::Seat]. This memory is owned by GTK+ and
457    ///  must not be freed.
458    #[doc(alias = "gdk_device_get_seat")]
459    #[doc(alias = "get_seat")]
460    fn seat(&self) -> Option<Seat> {
461        unsafe { from_glib_none(ffi::gdk_device_get_seat(self.as_ref().to_glib_none().0)) }
462    }
463
464    /// Determines the type of the device.
465    ///
466    /// # Returns
467    ///
468    /// a [`InputSource`][crate::InputSource]
469    #[doc(alias = "gdk_device_get_source")]
470    #[doc(alias = "get_source")]
471    fn source(&self) -> InputSource {
472        unsafe { from_glib(ffi::gdk_device_get_source(self.as_ref().to_glib_none().0)) }
473    }
474
475    //#[doc(alias = "gdk_device_get_state")]
476    //#[doc(alias = "get_state")]
477    //fn state(&self, window: &Window, axes: &[f64]) -> ModifierType {
478    //    unsafe { TODO: call ffi:gdk_device_get_state() }
479    //}
480
481    /// Returns the vendor ID of this device, or [`None`] if this information couldn't
482    /// be obtained. This ID is retrieved from the device, and is thus constant for
483    /// it.
484    ///
485    /// This function, together with [`product_id()`][Self::product_id()], can be used to eg.
486    /// compose `GSettings` paths to store settings for this device.
487    ///
488    ///
489    ///
490    /// **⚠️ The following code is in C ⚠️**
491    ///
492    /// ```C
493    ///  static GSettings *
494    ///  get_device_settings (GdkDevice *device)
495    ///  {
496    ///    const gchar *vendor, *product;
497    ///    GSettings *settings;
498    ///    GdkDevice *device;
499    ///    gchar *path;
500    ///
501    ///    vendor = gdk_device_get_vendor_id (device);
502    ///    product = gdk_device_get_product_id (device);
503    ///
504    ///    path = g_strdup_printf ("/org/example/app/devices/%s:%s/", vendor, product);
505    ///    settings = g_settings_new_with_path (DEVICE_SCHEMA, path);
506    ///    g_free (path);
507    ///
508    ///    return settings;
509    ///  }
510    /// ```
511    ///
512    /// # Returns
513    ///
514    /// the vendor ID, or [`None`]
515    #[doc(alias = "gdk_device_get_vendor_id")]
516    #[doc(alias = "get_vendor_id")]
517    fn vendor_id(&self) -> Option<glib::GString> {
518        unsafe {
519            from_glib_none(ffi::gdk_device_get_vendor_id(
520                self.as_ref().to_glib_none().0,
521            ))
522        }
523    }
524
525    /// Obtains the window underneath `self`, returning the location of the device in `win_x` and `win_y`. Returns
526    /// [`None`] if the window tree under `self` is not known to GDK (for example, belongs to another application).
527    ///
528    /// As a slave device coordinates are those of its master pointer, This
529    /// function may not be called on devices of type [`DeviceType::Slave`][crate::DeviceType::Slave],
530    /// unless there is an ongoing grab on them, see `gdk_device_grab()`.
531    ///
532    /// # Returns
533    ///
534    /// the [`Window`][crate::Window] under the
535    /// device position, or [`None`].
536    ///
537    /// ## `win_x`
538    /// return location for the X coordinate of the device location,
539    ///  relative to the window origin, or [`None`].
540    ///
541    /// ## `win_y`
542    /// return location for the Y coordinate of the device location,
543    ///  relative to the window origin, or [`None`].
544    #[doc(alias = "gdk_device_get_window_at_position")]
545    #[doc(alias = "get_window_at_position")]
546    fn window_at_position(&self) -> (Option<Window>, i32, i32) {
547        unsafe {
548            let mut win_x = mem::MaybeUninit::uninit();
549            let mut win_y = mem::MaybeUninit::uninit();
550            let ret = from_glib_none(ffi::gdk_device_get_window_at_position(
551                self.as_ref().to_glib_none().0,
552                win_x.as_mut_ptr(),
553                win_y.as_mut_ptr(),
554            ));
555            (ret, win_x.assume_init(), win_y.assume_init())
556        }
557    }
558
559    /// Obtains the window underneath `self`, returning the location of the device in `win_x` and `win_y` in
560    /// double precision. Returns [`None`] if the window tree under `self` is not known to GDK (for example,
561    /// belongs to another application).
562    ///
563    /// As a slave device coordinates are those of its master pointer, This
564    /// function may not be called on devices of type [`DeviceType::Slave`][crate::DeviceType::Slave],
565    /// unless there is an ongoing grab on them, see `gdk_device_grab()`.
566    ///
567    /// # Returns
568    ///
569    /// the [`Window`][crate::Window] under the
570    ///  device position, or [`None`].
571    ///
572    /// ## `win_x`
573    /// return location for the X coordinate of the device location,
574    ///  relative to the window origin, or [`None`].
575    ///
576    /// ## `win_y`
577    /// return location for the Y coordinate of the device location,
578    ///  relative to the window origin, or [`None`].
579    #[doc(alias = "gdk_device_get_window_at_position_double")]
580    #[doc(alias = "get_window_at_position_double")]
581    fn window_at_position_double(&self) -> (Option<Window>, f64, f64) {
582        unsafe {
583            let mut win_x = mem::MaybeUninit::uninit();
584            let mut win_y = mem::MaybeUninit::uninit();
585            let ret = from_glib_none(ffi::gdk_device_get_window_at_position_double(
586                self.as_ref().to_glib_none().0,
587                win_x.as_mut_ptr(),
588                win_y.as_mut_ptr(),
589            ));
590            (ret, win_x.assume_init(), win_y.assume_init())
591        }
592    }
593
594    /// Returns a `GList` of `GdkAtoms`, containing the labels for
595    /// the axes that `self` currently has.
596    ///
597    /// # Returns
598    ///
599    ///
600    ///  A `GList` of `GdkAtoms`, free with `g_list_free()`.
601    #[doc(alias = "gdk_device_list_axes")]
602    fn list_axes(&self) -> Vec<Atom> {
603        unsafe {
604            FromGlibPtrContainer::from_glib_container(ffi::gdk_device_list_axes(
605                self.as_ref().to_glib_none().0,
606            ))
607        }
608    }
609
610    /// If the device if of type [`DeviceType::Master`][crate::DeviceType::Master], it will return
611    /// the list of slave devices attached to it, otherwise it will return
612    /// [`None`]
613    ///
614    /// # Returns
615    ///
616    ///
617    ///  the list of slave devices, or [`None`]. The list must be
618    ///  freed with `g_list_free()`, the contents of the list are
619    ///  owned by GTK+ and should not be freed.
620    #[doc(alias = "gdk_device_list_slave_devices")]
621    fn list_slave_devices(&self) -> Vec<Device> {
622        unsafe {
623            FromGlibPtrContainer::from_glib_container(ffi::gdk_device_list_slave_devices(
624                self.as_ref().to_glib_none().0,
625            ))
626        }
627    }
628
629    /// Specifies how an axis of a device is used.
630    /// ## `index_`
631    /// the index of the axis
632    /// ## `use_`
633    /// specifies how the axis is used
634    #[doc(alias = "gdk_device_set_axis_use")]
635    fn set_axis_use(&self, index_: u32, use_: AxisUse) {
636        unsafe {
637            ffi::gdk_device_set_axis_use(self.as_ref().to_glib_none().0, index_, use_.into_glib());
638        }
639    }
640
641    /// Specifies the X key event to generate when a macro button of a device
642    /// is pressed.
643    /// ## `index_`
644    /// the index of the macro button to set
645    /// ## `keyval`
646    /// the keyval to generate
647    /// ## `modifiers`
648    /// the modifiers to set
649    #[doc(alias = "gdk_device_set_key")]
650    fn set_key(&self, index_: u32, keyval: u32, modifiers: ModifierType) {
651        unsafe {
652            ffi::gdk_device_set_key(
653                self.as_ref().to_glib_none().0,
654                index_,
655                keyval,
656                modifiers.into_glib(),
657            );
658        }
659    }
660
661    /// Sets a the mode of an input device. The mode controls if the
662    /// device is active and whether the device’s range is mapped to the
663    /// entire screen or to a single window.
664    ///
665    /// Note: This is only meaningful for floating devices, master devices (and
666    /// slaves connected to these) drive the pointer cursor, which is not limited
667    /// by the input mode.
668    /// ## `mode`
669    /// the input mode.
670    ///
671    /// # Returns
672    ///
673    /// [`true`] if the mode was successfully changed.
674    #[doc(alias = "gdk_device_set_mode")]
675    fn set_mode(&self, mode: InputMode) -> bool {
676        unsafe {
677            from_glib(ffi::gdk_device_set_mode(
678                self.as_ref().to_glib_none().0,
679                mode.into_glib(),
680            ))
681        }
682    }
683
684    /// Warps `self` in `display` to the point `x`,`y` on
685    /// the screen `screen`, unless the device is confined
686    /// to a window by a grab, in which case it will be moved
687    /// as far as allowed by the grab. Warping the pointer
688    /// creates events as if the user had moved the mouse
689    /// instantaneously to the destination.
690    ///
691    /// Note that the pointer should normally be under the
692    /// control of the user. This function was added to cover
693    /// some rare use cases like keyboard navigation support
694    /// for the color picker in the `GtkColorSelectionDialog`.
695    /// ## `screen`
696    /// the screen to warp `self` to.
697    /// ## `x`
698    /// the X coordinate of the destination.
699    /// ## `y`
700    /// the Y coordinate of the destination.
701    #[doc(alias = "gdk_device_warp")]
702    fn warp(&self, screen: &Screen, x: i32, y: i32) {
703        unsafe {
704            ffi::gdk_device_warp(
705                self.as_ref().to_glib_none().0,
706                screen.to_glib_none().0,
707                x,
708                y,
709            );
710        }
711    }
712
713    /// The [`DeviceManager`][crate::DeviceManager] the [`Device`][crate::Device] pertains to.
714    #[doc(alias = "device-manager")]
715    fn device_manager(&self) -> Option<DeviceManager> {
716        ObjectExt::property(self.as_ref(), "device-manager")
717    }
718
719    #[doc(alias = "input-mode")]
720    fn input_mode(&self) -> InputMode {
721        ObjectExt::property(self.as_ref(), "input-mode")
722    }
723
724    #[doc(alias = "input-mode")]
725    fn set_input_mode(&self, input_mode: InputMode) {
726        ObjectExt::set_property(self.as_ref(), "input-mode", input_mode)
727    }
728
729    /// Source type for the device.
730    #[doc(alias = "input-source")]
731    fn input_source(&self) -> InputSource {
732        ObjectExt::property(self.as_ref(), "input-source")
733    }
734
735    /// The maximal number of concurrent touches on a touch device.
736    /// Will be 0 if the device is not a touch device or if the number
737    /// of touches is unknown.
738    #[doc(alias = "num-touches")]
739    fn num_touches(&self) -> u32 {
740        ObjectExt::property(self.as_ref(), "num-touches")
741    }
742
743    /// [`Seat`][crate::Seat] of this device.
744    fn set_seat<P: IsA<Seat>>(&self, seat: Option<&P>) {
745        ObjectExt::set_property(self.as_ref(), "seat", seat)
746    }
747
748    fn tool(&self) -> Option<DeviceTool> {
749        ObjectExt::property(self.as_ref(), "tool")
750    }
751
752    /// Device role in the device manager.
753    #[doc(alias = "type")]
754    fn type_(&self) -> DeviceType {
755        ObjectExt::property(self.as_ref(), "type")
756    }
757
758    /// The ::changed signal is emitted either when the [`Device`][crate::Device]
759    /// has changed the number of either axes or keys. For example
760    /// In X this will normally happen when the slave device routing
761    /// events through the master device changes (for example, user
762    /// switches from the USB mouse to a tablet), in that case the
763    /// master device will change to reflect the new slave device
764    /// axes and keys.
765    #[doc(alias = "changed")]
766    fn connect_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
767        unsafe extern "C" fn changed_trampoline<P: IsA<Device>, F: Fn(&P) + 'static>(
768            this: *mut ffi::GdkDevice,
769            f: glib::ffi::gpointer,
770        ) {
771            let f: &F = &*(f as *const F);
772            f(Device::from_glib_borrow(this).unsafe_cast_ref())
773        }
774        unsafe {
775            let f: Box_<F> = Box_::new(f);
776            connect_raw(
777                self.as_ptr() as *mut _,
778                b"changed\0".as_ptr() as *const _,
779                Some(transmute::<_, unsafe extern "C" fn()>(
780                    changed_trampoline::<Self, F> as *const (),
781                )),
782                Box_::into_raw(f),
783            )
784        }
785    }
786
787    /// The ::tool-changed signal is emitted on pen/eraser
788    /// `GdkDevices` whenever tools enter or leave proximity.
789    /// ## `tool`
790    /// The new current tool
791    #[doc(alias = "tool-changed")]
792    fn connect_tool_changed<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> SignalHandlerId {
793        unsafe extern "C" fn tool_changed_trampoline<
794            P: IsA<Device>,
795            F: Fn(&P, &DeviceTool) + 'static,
796        >(
797            this: *mut ffi::GdkDevice,
798            tool: *mut ffi::GdkDeviceTool,
799            f: glib::ffi::gpointer,
800        ) {
801            let f: &F = &*(f as *const F);
802            f(
803                Device::from_glib_borrow(this).unsafe_cast_ref(),
804                &from_glib_borrow(tool),
805            )
806        }
807        unsafe {
808            let f: Box_<F> = Box_::new(f);
809            connect_raw(
810                self.as_ptr() as *mut _,
811                b"tool-changed\0".as_ptr() as *const _,
812                Some(transmute::<_, unsafe extern "C" fn()>(
813                    tool_changed_trampoline::<Self, F> as *const (),
814                )),
815                Box_::into_raw(f),
816            )
817        }
818    }
819
820    #[doc(alias = "associated-device")]
821    fn connect_associated_device_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
822        unsafe extern "C" fn notify_associated_device_trampoline<
823            P: IsA<Device>,
824            F: Fn(&P) + 'static,
825        >(
826            this: *mut ffi::GdkDevice,
827            _param_spec: glib::ffi::gpointer,
828            f: glib::ffi::gpointer,
829        ) {
830            let f: &F = &*(f as *const F);
831            f(Device::from_glib_borrow(this).unsafe_cast_ref())
832        }
833        unsafe {
834            let f: Box_<F> = Box_::new(f);
835            connect_raw(
836                self.as_ptr() as *mut _,
837                b"notify::associated-device\0".as_ptr() as *const _,
838                Some(transmute::<_, unsafe extern "C" fn()>(
839                    notify_associated_device_trampoline::<Self, F> as *const (),
840                )),
841                Box_::into_raw(f),
842            )
843        }
844    }
845
846    #[doc(alias = "axes")]
847    fn connect_axes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
848        unsafe extern "C" fn notify_axes_trampoline<P: IsA<Device>, F: Fn(&P) + 'static>(
849            this: *mut ffi::GdkDevice,
850            _param_spec: glib::ffi::gpointer,
851            f: glib::ffi::gpointer,
852        ) {
853            let f: &F = &*(f as *const F);
854            f(Device::from_glib_borrow(this).unsafe_cast_ref())
855        }
856        unsafe {
857            let f: Box_<F> = Box_::new(f);
858            connect_raw(
859                self.as_ptr() as *mut _,
860                b"notify::axes\0".as_ptr() as *const _,
861                Some(transmute::<_, unsafe extern "C" fn()>(
862                    notify_axes_trampoline::<Self, F> as *const (),
863                )),
864                Box_::into_raw(f),
865            )
866        }
867    }
868
869    #[doc(alias = "input-mode")]
870    fn connect_input_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
871        unsafe extern "C" fn notify_input_mode_trampoline<P: IsA<Device>, F: Fn(&P) + 'static>(
872            this: *mut ffi::GdkDevice,
873            _param_spec: glib::ffi::gpointer,
874            f: glib::ffi::gpointer,
875        ) {
876            let f: &F = &*(f as *const F);
877            f(Device::from_glib_borrow(this).unsafe_cast_ref())
878        }
879        unsafe {
880            let f: Box_<F> = Box_::new(f);
881            connect_raw(
882                self.as_ptr() as *mut _,
883                b"notify::input-mode\0".as_ptr() as *const _,
884                Some(transmute::<_, unsafe extern "C" fn()>(
885                    notify_input_mode_trampoline::<Self, F> as *const (),
886                )),
887                Box_::into_raw(f),
888            )
889        }
890    }
891
892    #[doc(alias = "n-axes")]
893    fn connect_n_axes_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
894        unsafe extern "C" fn notify_n_axes_trampoline<P: IsA<Device>, F: Fn(&P) + 'static>(
895            this: *mut ffi::GdkDevice,
896            _param_spec: glib::ffi::gpointer,
897            f: glib::ffi::gpointer,
898        ) {
899            let f: &F = &*(f as *const F);
900            f(Device::from_glib_borrow(this).unsafe_cast_ref())
901        }
902        unsafe {
903            let f: Box_<F> = Box_::new(f);
904            connect_raw(
905                self.as_ptr() as *mut _,
906                b"notify::n-axes\0".as_ptr() as *const _,
907                Some(transmute::<_, unsafe extern "C" fn()>(
908                    notify_n_axes_trampoline::<Self, F> as *const (),
909                )),
910                Box_::into_raw(f),
911            )
912        }
913    }
914
915    #[doc(alias = "seat")]
916    fn connect_seat_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
917        unsafe extern "C" fn notify_seat_trampoline<P: IsA<Device>, F: Fn(&P) + 'static>(
918            this: *mut ffi::GdkDevice,
919            _param_spec: glib::ffi::gpointer,
920            f: glib::ffi::gpointer,
921        ) {
922            let f: &F = &*(f as *const F);
923            f(Device::from_glib_borrow(this).unsafe_cast_ref())
924        }
925        unsafe {
926            let f: Box_<F> = Box_::new(f);
927            connect_raw(
928                self.as_ptr() as *mut _,
929                b"notify::seat\0".as_ptr() as *const _,
930                Some(transmute::<_, unsafe extern "C" fn()>(
931                    notify_seat_trampoline::<Self, F> as *const (),
932                )),
933                Box_::into_raw(f),
934            )
935        }
936    }
937
938    #[doc(alias = "tool")]
939    fn connect_tool_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
940        unsafe extern "C" fn notify_tool_trampoline<P: IsA<Device>, F: Fn(&P) + 'static>(
941            this: *mut ffi::GdkDevice,
942            _param_spec: glib::ffi::gpointer,
943            f: glib::ffi::gpointer,
944        ) {
945            let f: &F = &*(f as *const F);
946            f(Device::from_glib_borrow(this).unsafe_cast_ref())
947        }
948        unsafe {
949            let f: Box_<F> = Box_::new(f);
950            connect_raw(
951                self.as_ptr() as *mut _,
952                b"notify::tool\0".as_ptr() as *const _,
953                Some(transmute::<_, unsafe extern "C" fn()>(
954                    notify_tool_trampoline::<Self, F> as *const (),
955                )),
956                Box_::into_raw(f),
957            )
958        }
959    }
960
961    #[doc(alias = "type")]
962    fn connect_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
963        unsafe extern "C" fn notify_type_trampoline<P: IsA<Device>, F: Fn(&P) + 'static>(
964            this: *mut ffi::GdkDevice,
965            _param_spec: glib::ffi::gpointer,
966            f: glib::ffi::gpointer,
967        ) {
968            let f: &F = &*(f as *const F);
969            f(Device::from_glib_borrow(this).unsafe_cast_ref())
970        }
971        unsafe {
972            let f: Box_<F> = Box_::new(f);
973            connect_raw(
974                self.as_ptr() as *mut _,
975                b"notify::type\0".as_ptr() as *const _,
976                Some(transmute::<_, unsafe extern "C" fn()>(
977                    notify_type_trampoline::<Self, F> as *const (),
978                )),
979                Box_::into_raw(f),
980            )
981        }
982    }
983}
984
985impl<O: IsA<Device>> DeviceExt for O {}
986
987impl fmt::Display for Device {
988    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
989        f.write_str("Device")
990    }
991}