Skip to main content

gdk/auto/
device_manager.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::{Device, Display};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14    /// In addition to a single pointer and keyboard for user interface input,
15    /// GDK contains support for a variety of input devices, including graphics
16    /// tablets, touchscreens and multiple pointers/keyboards interacting
17    /// simultaneously with the user interface. Such input devices often have
18    /// additional features, such as sub-pixel positioning information and
19    /// additional device-dependent information.
20    ///
21    /// In order to query the device hierarchy and be aware of changes in the
22    /// device hierarchy (such as virtual devices being created or removed, or
23    /// physical devices being plugged or unplugged), GDK provides
24    /// [`DeviceManager`][crate::DeviceManager].
25    ///
26    /// By default, and if the platform supports it, GDK is aware of multiple
27    /// keyboard/pointer pairs and multitouch devices. This behavior can be
28    /// changed by calling `gdk_disable_multidevice()` before [`Display::open()`][crate::Display::open()].
29    /// There should rarely be a need to do that though, since GDK defaults
30    /// to a compatibility mode in which it will emit just one enter/leave
31    /// event pair for all devices on a window. To enable per-device
32    /// enter/leave events and other multi-pointer interaction features,
33    /// [`Window::set_support_multidevice()`][crate::Window::set_support_multidevice()] must be called on
34    /// `GdkWindows` (or `gtk_widget_set_support_multidevice()` on widgets).
35    /// window. See the [`Window::set_support_multidevice()`][crate::Window::set_support_multidevice()] documentation
36    /// for more information.
37    ///
38    /// On X11, multi-device support is implemented through XInput 2.
39    /// Unless `gdk_disable_multidevice()` is called, the XInput 2
40    /// [`DeviceManager`][crate::DeviceManager] implementation will be used as the input source.
41    /// Otherwise either the core or XInput 1 implementations will be used.
42    ///
43    /// For simple applications that don’t have any special interest in
44    /// input devices, the so-called “client pointer”
45    /// provides a reasonable approximation to a simple setup with a single
46    /// pointer and keyboard. The device that has been set as the client
47    /// pointer can be accessed via `gdk_device_manager_get_client_pointer()`.
48    ///
49    /// Conceptually, in multidevice mode there are 2 device types. Virtual
50    /// devices (or master devices) are represented by the pointer cursors
51    /// and keyboard foci that are seen on the screen. Physical devices (or
52    /// slave devices) represent the hardware that is controlling the virtual
53    /// devices, and thus have no visible cursor on the screen.
54    ///
55    /// Virtual devices are always paired, so there is a keyboard device for every
56    /// pointer device. Associations between devices may be inspected through
57    /// [`DeviceExt::associated_device()`][crate::prelude::DeviceExt::associated_device()].
58    ///
59    /// There may be several virtual devices, and several physical devices could
60    /// be controlling each of these virtual devices. Physical devices may also
61    /// be “floating”, which means they are not attached to any virtual device.
62    ///
63    /// # Master and slave devices
64    ///
65    ///
66    /// ```text
67    /// carlos@sacarino:~$ xinput list
68    /// ⎡ Virtual core pointer                          id=2    [master pointer  (3)]
69    /// ⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
70    /// ⎜   ↳ Wacom ISDv4 E6 Pen stylus                 id=10   [slave  pointer  (2)]
71    /// ⎜   ↳ Wacom ISDv4 E6 Finger touch               id=11   [slave  pointer  (2)]
72    /// ⎜   ↳ SynPS/2 Synaptics TouchPad                id=13   [slave  pointer  (2)]
73    /// ⎜   ↳ TPPS/2 IBM TrackPoint                     id=14   [slave  pointer  (2)]
74    /// ⎜   ↳ Wacom ISDv4 E6 Pen eraser                 id=16   [slave  pointer  (2)]
75    /// ⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
76    ///     ↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
77    ///     ↳ Power Button                              id=6    [slave  keyboard (3)]
78    ///     ↳ Video Bus                                 id=7    [slave  keyboard (3)]
79    ///     ↳ Sleep Button                              id=8    [slave  keyboard (3)]
80    ///     ↳ Integrated Camera                         id=9    [slave  keyboard (3)]
81    ///     ↳ AT Translated Set 2 keyboard              id=12   [slave  keyboard (3)]
82    ///     ↳ ThinkPad Extra Buttons                    id=15   [slave  keyboard (3)]
83    /// ```
84    ///
85    /// By default, GDK will automatically listen for events coming from all
86    /// master devices, setting the [`Device`][crate::Device] for all events coming from input
87    /// devices. Events containing device information are [`EventType::MotionNotify`][crate::EventType::MotionNotify],
88    /// [`EventType::ButtonPress`][crate::EventType::ButtonPress], [`EventType::_2buttonPress`][crate::EventType::_2buttonPress], [`EventType::_3buttonPress`][crate::EventType::_3buttonPress],
89    /// [`EventType::ButtonRelease`][crate::EventType::ButtonRelease], [`EventType::Scroll`][crate::EventType::Scroll], [`EventType::KeyPress`][crate::EventType::KeyPress], [`EventType::KeyRelease`][crate::EventType::KeyRelease],
90    /// [`EventType::EnterNotify`][crate::EventType::EnterNotify], [`EventType::LeaveNotify`][crate::EventType::LeaveNotify], [`EventType::FocusChange`][crate::EventType::FocusChange],
91    /// [`EventType::ProximityIn`][crate::EventType::ProximityIn], [`EventType::ProximityOut`][crate::EventType::ProximityOut], [`EventType::DragEnter`][crate::EventType::DragEnter], [`EventType::DragLeave`][crate::EventType::DragLeave],
92    /// [`EventType::DragMotion`][crate::EventType::DragMotion], [`EventType::DragStatus`][crate::EventType::DragStatus], [`EventType::DropStart`][crate::EventType::DropStart], [`EventType::DropFinished`][crate::EventType::DropFinished]
93    /// and [`EventType::GrabBroken`][crate::EventType::GrabBroken]. When dealing with an event on a master device,
94    /// it is possible to get the source (slave) device that the event originated
95    /// from via `gdk_event_get_source_device()`.
96    ///
97    /// On a standard session, all physical devices are connected by default to
98    /// the "Virtual Core Pointer/Keyboard" master devices, hence routing all events
99    /// through these. This behavior is only modified by device grabs, where the
100    /// slave device is temporarily detached for as long as the grab is held, and
101    /// more permanently by user modifications to the device hierarchy.
102    ///
103    /// On certain application specific setups, it may make sense
104    /// to detach a physical device from its master pointer, and mapping it to
105    /// an specific window. This can be achieved by the combination of
106    /// `gdk_device_grab()` and [`DeviceExt::set_mode()`][crate::prelude::DeviceExt::set_mode()].
107    ///
108    /// In order to listen for events coming from devices
109    /// other than a virtual device, [`Window::set_device_events()`][crate::Window::set_device_events()] must be
110    /// called. Generally, this function can be used to modify the event mask
111    /// for any given device.
112    ///
113    /// Input devices may also provide additional information besides X/Y.
114    /// For example, graphics tablets may also provide pressure and X/Y tilt
115    /// information. This information is device-dependent, and may be
116    /// queried through `gdk_device_get_axis()`. In multidevice mode, virtual
117    /// devices will change axes in order to always represent the physical
118    /// device that is routing events through it. Whenever the physical device
119    /// changes, the [`n-axes`][struct@crate::Device#n-axes] property will be notified, and
120    /// [`DeviceExt::list_axes()`][crate::prelude::DeviceExt::list_axes()] will return the new device axes.
121    ///
122    /// Devices may also have associated “keys” or
123    /// macro buttons. Such keys can be globally set to map into normal X
124    /// keyboard events. The mapping is set using [`DeviceExt::set_key()`][crate::prelude::DeviceExt::set_key()].
125    ///
126    /// In GTK+ 3.20, a new [`Seat`][crate::Seat] object has been introduced that
127    /// supersedes [`DeviceManager`][crate::DeviceManager] and should be preferred in newly
128    /// written code.
129    ///
130    /// This is an Abstract Base Class, you cannot instantiate it.
131    ///
132    /// ## Properties
133    ///
134    ///
135    /// #### `display`
136    ///  Readable | Writeable | Construct Only
137    ///
138    /// ## Signals
139    ///
140    ///
141    /// #### `device-added`
142    ///  The ::device-added signal is emitted either when a new master
143    /// pointer is created, or when a slave (Hardware) input device
144    /// is plugged in.
145    ///
146    ///
147    ///
148    ///
149    /// #### `device-changed`
150    ///  The ::device-changed signal is emitted whenever a device
151    /// has changed in the hierarchy, either slave devices being
152    /// disconnected from their master device or connected to
153    /// another one, or master devices being added or removed
154    /// a slave device.
155    ///
156    /// If a slave device is detached from all master devices
157    /// ([`DeviceExt::associated_device()`][crate::prelude::DeviceExt::associated_device()] returns [`None`]), its
158    /// [`DeviceType`][crate::DeviceType] will change to [`DeviceType::Floating`][crate::DeviceType::Floating],
159    /// if it's attached, it will change to [`DeviceType::Slave`][crate::DeviceType::Slave].
160    ///
161    ///
162    ///
163    ///
164    /// #### `device-removed`
165    ///  The ::device-removed signal is emitted either when a master
166    /// pointer is removed, or when a slave (Hardware) input device
167    /// is unplugged.
168    ///
169    ///
170    #[doc(alias = "GdkDeviceManager")]
171    pub struct DeviceManager(Object<ffi::GdkDeviceManager>);
172
173    match fn {
174        type_ => || ffi::gdk_device_manager_get_type(),
175    }
176}
177
178impl DeviceManager {
179    /// Gets the [`Display`][crate::Display] associated to `self`.
180    ///
181    /// # Returns
182    ///
183    /// the [`Display`][crate::Display] to which
184    ///  `self` is associated to, or [`None`]. This memory is
185    ///  owned by GDK and must not be freed or unreferenced.
186    #[doc(alias = "gdk_device_manager_get_display")]
187    #[doc(alias = "get_display")]
188    pub fn display(&self) -> Option<Display> {
189        unsafe { from_glib_none(ffi::gdk_device_manager_get_display(self.to_glib_none().0)) }
190    }
191
192    /// The ::device-added signal is emitted either when a new master
193    /// pointer is created, or when a slave (Hardware) input device
194    /// is plugged in.
195    /// ## `device`
196    /// the newly added [`Device`][crate::Device].
197    #[doc(alias = "device-added")]
198    pub fn connect_device_added<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
199        unsafe extern "C" fn device_added_trampoline<F: Fn(&DeviceManager, &Device) + 'static>(
200            this: *mut ffi::GdkDeviceManager,
201            device: *mut ffi::GdkDevice,
202            f: glib::ffi::gpointer,
203        ) {
204            let f: &F = &*(f as *const F);
205            f(&from_glib_borrow(this), &from_glib_borrow(device))
206        }
207        unsafe {
208            let f: Box_<F> = Box_::new(f);
209            connect_raw(
210                self.as_ptr() as *mut _,
211                b"device-added\0".as_ptr() as *const _,
212                Some(transmute::<_, unsafe extern "C" fn()>(
213                    device_added_trampoline::<F> as *const (),
214                )),
215                Box_::into_raw(f),
216            )
217        }
218    }
219
220    /// The ::device-changed signal is emitted whenever a device
221    /// has changed in the hierarchy, either slave devices being
222    /// disconnected from their master device or connected to
223    /// another one, or master devices being added or removed
224    /// a slave device.
225    ///
226    /// If a slave device is detached from all master devices
227    /// ([`DeviceExt::associated_device()`][crate::prelude::DeviceExt::associated_device()] returns [`None`]), its
228    /// [`DeviceType`][crate::DeviceType] will change to [`DeviceType::Floating`][crate::DeviceType::Floating],
229    /// if it's attached, it will change to [`DeviceType::Slave`][crate::DeviceType::Slave].
230    /// ## `device`
231    /// the [`Device`][crate::Device] that changed.
232    #[doc(alias = "device-changed")]
233    pub fn connect_device_changed<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
234        unsafe extern "C" fn device_changed_trampoline<F: Fn(&DeviceManager, &Device) + 'static>(
235            this: *mut ffi::GdkDeviceManager,
236            device: *mut ffi::GdkDevice,
237            f: glib::ffi::gpointer,
238        ) {
239            let f: &F = &*(f as *const F);
240            f(&from_glib_borrow(this), &from_glib_borrow(device))
241        }
242        unsafe {
243            let f: Box_<F> = Box_::new(f);
244            connect_raw(
245                self.as_ptr() as *mut _,
246                b"device-changed\0".as_ptr() as *const _,
247                Some(transmute::<_, unsafe extern "C" fn()>(
248                    device_changed_trampoline::<F> as *const (),
249                )),
250                Box_::into_raw(f),
251            )
252        }
253    }
254
255    /// The ::device-removed signal is emitted either when a master
256    /// pointer is removed, or when a slave (Hardware) input device
257    /// is unplugged.
258    /// ## `device`
259    /// the just removed [`Device`][crate::Device].
260    #[doc(alias = "device-removed")]
261    pub fn connect_device_removed<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
262        unsafe extern "C" fn device_removed_trampoline<F: Fn(&DeviceManager, &Device) + 'static>(
263            this: *mut ffi::GdkDeviceManager,
264            device: *mut ffi::GdkDevice,
265            f: glib::ffi::gpointer,
266        ) {
267            let f: &F = &*(f as *const F);
268            f(&from_glib_borrow(this), &from_glib_borrow(device))
269        }
270        unsafe {
271            let f: Box_<F> = Box_::new(f);
272            connect_raw(
273                self.as_ptr() as *mut _,
274                b"device-removed\0".as_ptr() as *const _,
275                Some(transmute::<_, unsafe extern "C" fn()>(
276                    device_removed_trampoline::<F> as *const (),
277                )),
278                Box_::into_raw(f),
279            )
280        }
281    }
282}
283
284impl fmt::Display for DeviceManager {
285    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
286        f.write_str("DeviceManager")
287    }
288}