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