1use gdk_sys;
6use glib::object::IsA;
7#[cfg(any(feature = "v3_20", feature = "dox"))]
8use glib::object::ObjectType as ObjectType_;
9#[cfg(any(feature = "v3_20", feature = "dox"))]
10use glib::signal::connect_raw;
11#[cfg(any(feature = "v3_20", feature = "dox"))]
12use glib::signal::SignalHandlerId;
13use glib::translate::*;
14#[cfg(any(feature = "v3_20", feature = "dox"))]
15use glib_sys;
16#[cfg(any(feature = "v3_20", feature = "dox"))]
17use std::boxed::Box as Box_;
18use std::fmt;
19#[cfg(any(feature = "v3_20", feature = "dox"))]
20use std::mem::transmute;
21#[cfg(any(feature = "v3_20", feature = "dox"))]
22use Cursor;
23#[cfg(any(feature = "v3_20", feature = "dox"))]
24use Device;
25#[cfg(any(feature = "v3_22", feature = "dox"))]
26use DeviceTool;
27#[cfg(any(feature = "v3_20", feature = "dox"))]
28use Display;
29#[cfg(any(feature = "v3_20", feature = "dox"))]
30use Event;
31#[cfg(any(feature = "v3_20", feature = "dox"))]
32use GrabStatus;
33#[cfg(any(feature = "v3_20", feature = "dox"))]
34use SeatCapabilities;
35use Window;
36
37glib_wrapper! {
38 pub struct Seat(Object<gdk_sys::GdkSeat, SeatClass>);
39
40 match fn {
41 get_type => || gdk_sys::gdk_seat_get_type(),
42 }
43}
44
45impl Seat {
46 #[cfg(any(feature = "v3_20", feature = "dox"))]
47 pub fn get_capabilities(&self) -> SeatCapabilities {
48 unsafe { from_glib(gdk_sys::gdk_seat_get_capabilities(self.to_glib_none().0)) }
49 }
50
51 #[cfg(any(feature = "v3_20", feature = "dox"))]
52 pub fn get_display(&self) -> Option<Display> {
53 unsafe { from_glib_none(gdk_sys::gdk_seat_get_display(self.to_glib_none().0)) }
54 }
55
56 #[cfg(any(feature = "v3_20", feature = "dox"))]
57 pub fn get_keyboard(&self) -> Option<Device> {
58 unsafe { from_glib_none(gdk_sys::gdk_seat_get_keyboard(self.to_glib_none().0)) }
59 }
60
61 #[cfg(any(feature = "v3_20", feature = "dox"))]
62 pub fn get_pointer(&self) -> Option<Device> {
63 unsafe { from_glib_none(gdk_sys::gdk_seat_get_pointer(self.to_glib_none().0)) }
64 }
65
66 #[cfg(any(feature = "v3_20", feature = "dox"))]
67 pub fn get_slaves(&self, capabilities: SeatCapabilities) -> Vec<Device> {
68 unsafe {
69 FromGlibPtrContainer::from_glib_container(gdk_sys::gdk_seat_get_slaves(
70 self.to_glib_none().0,
71 capabilities.to_glib(),
72 ))
73 }
74 }
75
76 #[cfg(any(feature = "v3_20", feature = "dox"))]
77 pub fn grab<P: IsA<Window>>(
78 &self,
79 window: &P,
80 capabilities: SeatCapabilities,
81 owner_events: bool,
82 cursor: Option<&Cursor>,
83 event: Option<&Event>,
84 prepare_func: Option<&mut dyn (FnMut(&Seat, &Window))>,
85 ) -> GrabStatus {
86 let prepare_func_data: Option<&mut dyn (FnMut(&Seat, &Window))> = prepare_func;
87 unsafe extern "C" fn prepare_func_func<P: IsA<Window>>(
88 seat: *mut gdk_sys::GdkSeat,
89 window: *mut gdk_sys::GdkWindow,
90 user_data: glib_sys::gpointer,
91 ) {
92 let seat = from_glib_borrow(seat);
93 let window = from_glib_borrow(window);
94 let callback: *mut Option<&mut dyn (FnMut(&Seat, &Window))> =
95 user_data as *const _ as usize as *mut Option<&mut dyn (FnMut(&Seat, &Window))>;
96 if let Some(ref mut callback) = *callback {
97 callback(&seat, &window)
98 } else {
99 panic!("cannot get closure...")
100 };
101 }
102 let prepare_func = if prepare_func_data.is_some() {
103 Some(prepare_func_func::<P> as _)
104 } else {
105 None
106 };
107 let super_callback0: &Option<&mut dyn (FnMut(&Seat, &Window))> = &prepare_func_data;
108 unsafe {
109 from_glib(gdk_sys::gdk_seat_grab(
110 self.to_glib_none().0,
111 window.as_ref().to_glib_none().0,
112 capabilities.to_glib(),
113 owner_events.to_glib(),
114 cursor.to_glib_none().0,
115 event.to_glib_none().0,
116 prepare_func,
117 super_callback0 as *const _ as usize as *mut _,
118 ))
119 }
120 }
121
122 #[cfg(any(feature = "v3_20", feature = "dox"))]
123 pub fn ungrab(&self) {
124 unsafe {
125 gdk_sys::gdk_seat_ungrab(self.to_glib_none().0);
126 }
127 }
128
129 #[cfg(any(feature = "v3_20", feature = "dox"))]
130 pub fn connect_device_added<F: Fn(&Seat, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
131 unsafe extern "C" fn device_added_trampoline<F: Fn(&Seat, &Device) + 'static>(
132 this: *mut gdk_sys::GdkSeat,
133 device: *mut gdk_sys::GdkDevice,
134 f: glib_sys::gpointer,
135 ) {
136 let f: &F = &*(f as *const F);
137 f(&from_glib_borrow(this), &from_glib_borrow(device))
138 }
139 unsafe {
140 let f: Box_<F> = Box_::new(f);
141 connect_raw(
142 self.as_ptr() as *mut _,
143 b"device-added\0".as_ptr() as *const _,
144 Some(transmute(device_added_trampoline::<F> as usize)),
145 Box_::into_raw(f),
146 )
147 }
148 }
149
150 #[cfg(any(feature = "v3_20", feature = "dox"))]
151 pub fn connect_device_removed<F: Fn(&Seat, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
152 unsafe extern "C" fn device_removed_trampoline<F: Fn(&Seat, &Device) + 'static>(
153 this: *mut gdk_sys::GdkSeat,
154 device: *mut gdk_sys::GdkDevice,
155 f: glib_sys::gpointer,
156 ) {
157 let f: &F = &*(f as *const F);
158 f(&from_glib_borrow(this), &from_glib_borrow(device))
159 }
160 unsafe {
161 let f: Box_<F> = Box_::new(f);
162 connect_raw(
163 self.as_ptr() as *mut _,
164 b"device-removed\0".as_ptr() as *const _,
165 Some(transmute(device_removed_trampoline::<F> as usize)),
166 Box_::into_raw(f),
167 )
168 }
169 }
170
171 #[cfg(any(feature = "v3_22", feature = "dox"))]
172 pub fn connect_tool_added<F: Fn(&Seat, &DeviceTool) + 'static>(&self, f: F) -> SignalHandlerId {
173 unsafe extern "C" fn tool_added_trampoline<F: Fn(&Seat, &DeviceTool) + 'static>(
174 this: *mut gdk_sys::GdkSeat,
175 tool: *mut gdk_sys::GdkDeviceTool,
176 f: glib_sys::gpointer,
177 ) {
178 let f: &F = &*(f as *const F);
179 f(&from_glib_borrow(this), &from_glib_borrow(tool))
180 }
181 unsafe {
182 let f: Box_<F> = Box_::new(f);
183 connect_raw(
184 self.as_ptr() as *mut _,
185 b"tool-added\0".as_ptr() as *const _,
186 Some(transmute(tool_added_trampoline::<F> as usize)),
187 Box_::into_raw(f),
188 )
189 }
190 }
191
192 #[cfg(any(feature = "v3_22", feature = "dox"))]
193 pub fn connect_tool_removed<F: Fn(&Seat, &DeviceTool) + 'static>(
194 &self,
195 f: F,
196 ) -> SignalHandlerId {
197 unsafe extern "C" fn tool_removed_trampoline<F: Fn(&Seat, &DeviceTool) + 'static>(
198 this: *mut gdk_sys::GdkSeat,
199 tool: *mut gdk_sys::GdkDeviceTool,
200 f: glib_sys::gpointer,
201 ) {
202 let f: &F = &*(f as *const F);
203 f(&from_glib_borrow(this), &from_glib_borrow(tool))
204 }
205 unsafe {
206 let f: Box_<F> = Box_::new(f);
207 connect_raw(
208 self.as_ptr() as *mut _,
209 b"tool-removed\0".as_ptr() as *const _,
210 Some(transmute(tool_removed_trampoline::<F> as usize)),
211 Box_::into_raw(f),
212 )
213 }
214 }
215}
216
217impl fmt::Display for Seat {
218 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
219 write!(f, "Seat")
220 }
221}