gdk/auto/
device_manager.rs1use gdk_sys;
6use glib::object::ObjectType as ObjectType_;
7use glib::signal::connect_raw;
8use glib::signal::SignalHandlerId;
9use glib::translate::*;
10use glib_sys;
11use std::boxed::Box as Box_;
12use std::fmt;
13use std::mem::transmute;
14use Device;
15use DeviceType;
16use Display;
17
18glib_wrapper! {
19 pub struct DeviceManager(Object<gdk_sys::GdkDeviceManager, DeviceManagerClass>);
20
21 match fn {
22 get_type => || gdk_sys::gdk_device_manager_get_type(),
23 }
24}
25
26impl DeviceManager {
27 #[cfg_attr(feature = "v3_20", deprecated)]
28 pub fn get_client_pointer(&self) -> Option<Device> {
29 unsafe {
30 from_glib_none(gdk_sys::gdk_device_manager_get_client_pointer(
31 self.to_glib_none().0,
32 ))
33 }
34 }
35
36 pub fn get_display(&self) -> Option<Display> {
37 unsafe {
38 from_glib_none(gdk_sys::gdk_device_manager_get_display(
39 self.to_glib_none().0,
40 ))
41 }
42 }
43
44 #[cfg_attr(feature = "v3_20", deprecated)]
45 pub fn list_devices(&self, type_: DeviceType) -> Vec<Device> {
46 unsafe {
47 FromGlibPtrContainer::from_glib_container(gdk_sys::gdk_device_manager_list_devices(
48 self.to_glib_none().0,
49 type_.to_glib(),
50 ))
51 }
52 }
53
54 pub fn connect_device_added<F: Fn(&DeviceManager, &Device) + 'static>(
55 &self,
56 f: F,
57 ) -> SignalHandlerId {
58 unsafe extern "C" fn device_added_trampoline<F: Fn(&DeviceManager, &Device) + 'static>(
59 this: *mut gdk_sys::GdkDeviceManager,
60 device: *mut gdk_sys::GdkDevice,
61 f: glib_sys::gpointer,
62 ) {
63 let f: &F = &*(f as *const F);
64 f(&from_glib_borrow(this), &from_glib_borrow(device))
65 }
66 unsafe {
67 let f: Box_<F> = Box_::new(f);
68 connect_raw(
69 self.as_ptr() as *mut _,
70 b"device-added\0".as_ptr() as *const _,
71 Some(transmute(device_added_trampoline::<F> as usize)),
72 Box_::into_raw(f),
73 )
74 }
75 }
76
77 pub fn connect_device_changed<F: Fn(&DeviceManager, &Device) + 'static>(
78 &self,
79 f: F,
80 ) -> SignalHandlerId {
81 unsafe extern "C" fn device_changed_trampoline<F: Fn(&DeviceManager, &Device) + 'static>(
82 this: *mut gdk_sys::GdkDeviceManager,
83 device: *mut gdk_sys::GdkDevice,
84 f: glib_sys::gpointer,
85 ) {
86 let f: &F = &*(f as *const F);
87 f(&from_glib_borrow(this), &from_glib_borrow(device))
88 }
89 unsafe {
90 let f: Box_<F> = Box_::new(f);
91 connect_raw(
92 self.as_ptr() as *mut _,
93 b"device-changed\0".as_ptr() as *const _,
94 Some(transmute(device_changed_trampoline::<F> as usize)),
95 Box_::into_raw(f),
96 )
97 }
98 }
99
100 pub fn connect_device_removed<F: Fn(&DeviceManager, &Device) + 'static>(
101 &self,
102 f: F,
103 ) -> SignalHandlerId {
104 unsafe extern "C" fn device_removed_trampoline<F: Fn(&DeviceManager, &Device) + 'static>(
105 this: *mut gdk_sys::GdkDeviceManager,
106 device: *mut gdk_sys::GdkDevice,
107 f: glib_sys::gpointer,
108 ) {
109 let f: &F = &*(f as *const F);
110 f(&from_glib_borrow(this), &from_glib_borrow(device))
111 }
112 unsafe {
113 let f: Box_<F> = Box_::new(f);
114 connect_raw(
115 self.as_ptr() as *mut _,
116 b"device-removed\0".as_ptr() as *const _,
117 Some(transmute(device_removed_trampoline::<F> as usize)),
118 Box_::into_raw(f),
119 )
120 }
121 }
122}
123
124impl fmt::Display for DeviceManager {
125 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
126 write!(f, "DeviceManager")
127 }
128}