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