gdk/auto/seat.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::{Cursor, Device, DeviceTool, Display, Event, GrabStatus, SeatCapabilities, Window};
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 /// The [`Seat`][crate::Seat] object represents a collection of input devices
15 /// that belong to a user.
16 ///
17 /// This is an Abstract Base Class, you cannot instantiate it.
18 ///
19 /// ## Properties
20 ///
21 ///
22 /// #### `display`
23 /// [`Display`][crate::Display] of this seat.
24 ///
25 /// Readable | Writeable | Construct Only
26 ///
27 /// ## Signals
28 ///
29 ///
30 /// #### `device-added`
31 /// The ::device-added signal is emitted when a new input
32 /// device is related to this seat.
33 ///
34 ///
35 ///
36 ///
37 /// #### `device-removed`
38 /// The ::device-removed signal is emitted when an
39 /// input device is removed (e.g. unplugged).
40 ///
41 ///
42 ///
43 ///
44 /// #### `tool-added`
45 /// The ::tool-added signal is emitted whenever a new tool
46 /// is made known to the seat. The tool may later be assigned
47 /// to a device (i.e. on proximity with a tablet). The device
48 /// will emit the [`tool-changed`][struct@crate::Device#tool-changed] signal accordingly.
49 ///
50 /// A same tool may be used by several devices.
51 ///
52 ///
53 ///
54 ///
55 /// #### `tool-removed`
56 /// This signal is emitted whenever a tool is no longer known
57 /// to this `seat`.
58 ///
59 ///
60 ///
61 /// # Implements
62 ///
63 /// [`SeatExt`][trait@crate::prelude::SeatExt]
64 #[doc(alias = "GdkSeat")]
65 pub struct Seat(Object<ffi::GdkSeat>);
66
67 match fn {
68 type_ => || ffi::gdk_seat_get_type(),
69 }
70}
71
72impl Seat {
73 pub const NONE: Option<&'static Seat> = None;
74}
75
76mod sealed {
77 pub trait Sealed {}
78 impl<T: super::IsA<super::Seat>> Sealed for T {}
79}
80
81/// Trait containing all [`struct@Seat`] methods.
82///
83/// # Implementors
84///
85/// [`Seat`][struct@crate::Seat]
86pub trait SeatExt: IsA<Seat> + sealed::Sealed + 'static {
87 /// Returns the capabilities this [`Seat`][crate::Seat] currently has.
88 ///
89 /// # Returns
90 ///
91 /// the seat capabilities
92 #[doc(alias = "gdk_seat_get_capabilities")]
93 #[doc(alias = "get_capabilities")]
94 fn capabilities(&self) -> SeatCapabilities {
95 unsafe {
96 from_glib(ffi::gdk_seat_get_capabilities(
97 self.as_ref().to_glib_none().0,
98 ))
99 }
100 }
101
102 /// Returns the [`Display`][crate::Display] this seat belongs to.
103 ///
104 /// # Returns
105 ///
106 /// a [`Display`][crate::Display]. This object is owned by GTK+
107 /// and must not be freed.
108 #[doc(alias = "gdk_seat_get_display")]
109 #[doc(alias = "get_display")]
110 fn display(&self) -> Option<Display> {
111 unsafe { from_glib_none(ffi::gdk_seat_get_display(self.as_ref().to_glib_none().0)) }
112 }
113
114 /// Returns the master device that routes keyboard events.
115 ///
116 /// # Returns
117 ///
118 /// a master [`Device`][crate::Device] with keyboard
119 /// capabilities. This object is owned by GTK+ and must not be freed.
120 #[doc(alias = "gdk_seat_get_keyboard")]
121 #[doc(alias = "get_keyboard")]
122 fn keyboard(&self) -> Option<Device> {
123 unsafe { from_glib_none(ffi::gdk_seat_get_keyboard(self.as_ref().to_glib_none().0)) }
124 }
125
126 /// Returns the master device that routes pointer events.
127 ///
128 /// # Returns
129 ///
130 /// a master [`Device`][crate::Device] with pointer
131 /// capabilities. This object is owned by GTK+ and must not be freed.
132 #[doc(alias = "gdk_seat_get_pointer")]
133 #[doc(alias = "get_pointer")]
134 fn pointer(&self) -> Option<Device> {
135 unsafe { from_glib_none(ffi::gdk_seat_get_pointer(self.as_ref().to_glib_none().0)) }
136 }
137
138 /// Returns the slave devices that match the given capabilities.
139 /// ## `capabilities`
140 /// capabilities to get devices for
141 ///
142 /// # Returns
143 ///
144 /// A list of `GdkDevices`.
145 /// The list must be freed with `g_list_free()`, the elements are owned
146 /// by GDK and must not be freed.
147 #[doc(alias = "gdk_seat_get_slaves")]
148 #[doc(alias = "get_slaves")]
149 fn slaves(&self, capabilities: SeatCapabilities) -> Vec<Device> {
150 unsafe {
151 FromGlibPtrContainer::from_glib_container(ffi::gdk_seat_get_slaves(
152 self.as_ref().to_glib_none().0,
153 capabilities.into_glib(),
154 ))
155 }
156 }
157
158 /// Grabs the seat so that all events corresponding to the given `capabilities`
159 /// are passed to this application until the seat is ungrabbed with [`ungrab()`][Self::ungrab()],
160 /// or the window becomes hidden. This overrides any previous grab on the
161 /// seat by this client.
162 ///
163 /// As a rule of thumb, if a grab is desired over [`SeatCapabilities::POINTER`][crate::SeatCapabilities::POINTER],
164 /// all other "pointing" capabilities (eg. [`SeatCapabilities::TOUCH`][crate::SeatCapabilities::TOUCH]) should
165 /// be grabbed too, so the user is able to interact with all of those while
166 /// the grab holds, you should thus use [`SeatCapabilities::ALL_POINTING`][crate::SeatCapabilities::ALL_POINTING] most
167 /// commonly.
168 ///
169 /// Grabs are used for operations which need complete control over the
170 /// events corresponding to the given capabilities. For example in GTK+ this
171 /// is used for Drag and Drop operations, popup menus and such.
172 ///
173 /// Note that if the event mask of a [`Window`][crate::Window] has selected both button press
174 /// and button release events, or touch begin and touch end, then a press event
175 /// will cause an automatic grab until the button is released, equivalent to a
176 /// grab on the window with `owner_events` set to [`true`]. This is done because most
177 /// applications expect to receive paired press and release events.
178 ///
179 /// If you set up anything at the time you take the grab that needs to be
180 /// cleaned up when the grab ends, you should handle the [`EventGrabBroken`][crate::EventGrabBroken]
181 /// events that are emitted when the grab ends unvoluntarily.
182 /// ## `window`
183 /// the [`Window`][crate::Window] which will own the grab
184 /// ## `capabilities`
185 /// capabilities that will be grabbed
186 /// ## `owner_events`
187 /// if [`false`] then all device events are reported with respect to
188 /// `window` and are only reported if selected by `event_mask`. If
189 /// [`true`] then pointer events for this application are reported
190 /// as normal, but pointer events outside this application are
191 /// reported with respect to `window` and only if selected by
192 /// `event_mask`. In either mode, unreported events are discarded.
193 /// ## `cursor`
194 /// the cursor to display while the grab is active. If
195 /// this is [`None`] then the normal cursors are used for
196 /// `window` and its descendants, and the cursor for `window` is used
197 /// elsewhere.
198 /// ## `event`
199 /// the event that is triggering the grab, or [`None`] if none
200 /// is available.
201 /// ## `prepare_func`
202 /// function to
203 /// prepare the window to be grabbed, it can be [`None`] if `window` is
204 /// visible before this call.
205 /// ## `prepare_func_data`
206 /// user data to pass to `prepare_func`
207 ///
208 /// # Returns
209 ///
210 /// [`GrabStatus::Success`][crate::GrabStatus::Success] if the grab was successful.
211 #[doc(alias = "gdk_seat_grab")]
212 fn grab(
213 &self,
214 window: &Window,
215 capabilities: SeatCapabilities,
216 owner_events: bool,
217 cursor: Option<&Cursor>,
218 event: Option<&Event>,
219 prepare_func: Option<&mut dyn (FnMut(&Seat, &Window))>,
220 ) -> GrabStatus {
221 let prepare_func_data: Option<&mut dyn (FnMut(&Seat, &Window))> = prepare_func;
222 unsafe extern "C" fn prepare_func_func(
223 seat: *mut ffi::GdkSeat,
224 window: *mut ffi::GdkWindow,
225 user_data: glib::ffi::gpointer,
226 ) {
227 let seat = from_glib_borrow(seat);
228 let window = from_glib_borrow(window);
229 let callback: *mut Option<&mut dyn (FnMut(&Seat, &Window))> =
230 user_data as *const _ as usize as *mut Option<&mut dyn (FnMut(&Seat, &Window))>;
231 if let Some(ref mut callback) = *callback {
232 callback(&seat, &window)
233 } else {
234 panic!("cannot get closure...")
235 }
236 }
237 let prepare_func = if prepare_func_data.is_some() {
238 Some(prepare_func_func as _)
239 } else {
240 None
241 };
242 let super_callback0: &Option<&mut dyn (FnMut(&Seat, &Window))> = &prepare_func_data;
243 unsafe {
244 from_glib(ffi::gdk_seat_grab(
245 self.as_ref().to_glib_none().0,
246 window.to_glib_none().0,
247 capabilities.into_glib(),
248 owner_events.into_glib(),
249 cursor.to_glib_none().0,
250 event.to_glib_none().0,
251 prepare_func,
252 super_callback0 as *const _ as usize as *mut _,
253 ))
254 }
255 }
256
257 /// Releases a grab added through [`grab()`][Self::grab()].
258 #[doc(alias = "gdk_seat_ungrab")]
259 fn ungrab(&self) {
260 unsafe {
261 ffi::gdk_seat_ungrab(self.as_ref().to_glib_none().0);
262 }
263 }
264
265 /// The ::device-added signal is emitted when a new input
266 /// device is related to this seat.
267 /// ## `device`
268 /// the newly added [`Device`][crate::Device].
269 #[doc(alias = "device-added")]
270 fn connect_device_added<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
271 unsafe extern "C" fn device_added_trampoline<P: IsA<Seat>, F: Fn(&P, &Device) + 'static>(
272 this: *mut ffi::GdkSeat,
273 device: *mut ffi::GdkDevice,
274 f: glib::ffi::gpointer,
275 ) {
276 let f: &F = &*(f as *const F);
277 f(
278 Seat::from_glib_borrow(this).unsafe_cast_ref(),
279 &from_glib_borrow(device),
280 )
281 }
282 unsafe {
283 let f: Box_<F> = Box_::new(f);
284 connect_raw(
285 self.as_ptr() as *mut _,
286 b"device-added\0".as_ptr() as *const _,
287 Some(transmute::<_, unsafe extern "C" fn()>(
288 device_added_trampoline::<Self, F> as *const (),
289 )),
290 Box_::into_raw(f),
291 )
292 }
293 }
294
295 /// The ::device-removed signal is emitted when an
296 /// input device is removed (e.g. unplugged).
297 /// ## `device`
298 /// the just removed [`Device`][crate::Device].
299 #[doc(alias = "device-removed")]
300 fn connect_device_removed<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
301 unsafe extern "C" fn device_removed_trampoline<
302 P: IsA<Seat>,
303 F: Fn(&P, &Device) + 'static,
304 >(
305 this: *mut ffi::GdkSeat,
306 device: *mut ffi::GdkDevice,
307 f: glib::ffi::gpointer,
308 ) {
309 let f: &F = &*(f as *const F);
310 f(
311 Seat::from_glib_borrow(this).unsafe_cast_ref(),
312 &from_glib_borrow(device),
313 )
314 }
315 unsafe {
316 let f: Box_<F> = Box_::new(f);
317 connect_raw(
318 self.as_ptr() as *mut _,
319 b"device-removed\0".as_ptr() as *const _,
320 Some(transmute::<_, unsafe extern "C" fn()>(
321 device_removed_trampoline::<Self, F> as *const (),
322 )),
323 Box_::into_raw(f),
324 )
325 }
326 }
327
328 /// The ::tool-added signal is emitted whenever a new tool
329 /// is made known to the seat. The tool may later be assigned
330 /// to a device (i.e. on proximity with a tablet). The device
331 /// will emit the [`tool-changed`][struct@crate::Device#tool-changed] signal accordingly.
332 ///
333 /// A same tool may be used by several devices.
334 /// ## `tool`
335 /// the new [`DeviceTool`][crate::DeviceTool] known to the seat
336 #[doc(alias = "tool-added")]
337 fn connect_tool_added<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> SignalHandlerId {
338 unsafe extern "C" fn tool_added_trampoline<
339 P: IsA<Seat>,
340 F: Fn(&P, &DeviceTool) + 'static,
341 >(
342 this: *mut ffi::GdkSeat,
343 tool: *mut ffi::GdkDeviceTool,
344 f: glib::ffi::gpointer,
345 ) {
346 let f: &F = &*(f as *const F);
347 f(
348 Seat::from_glib_borrow(this).unsafe_cast_ref(),
349 &from_glib_borrow(tool),
350 )
351 }
352 unsafe {
353 let f: Box_<F> = Box_::new(f);
354 connect_raw(
355 self.as_ptr() as *mut _,
356 b"tool-added\0".as_ptr() as *const _,
357 Some(transmute::<_, unsafe extern "C" fn()>(
358 tool_added_trampoline::<Self, F> as *const (),
359 )),
360 Box_::into_raw(f),
361 )
362 }
363 }
364
365 /// This signal is emitted whenever a tool is no longer known
366 /// to this `seat`.
367 /// ## `tool`
368 /// the just removed [`DeviceTool`][crate::DeviceTool]
369 #[doc(alias = "tool-removed")]
370 fn connect_tool_removed<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> SignalHandlerId {
371 unsafe extern "C" fn tool_removed_trampoline<
372 P: IsA<Seat>,
373 F: Fn(&P, &DeviceTool) + 'static,
374 >(
375 this: *mut ffi::GdkSeat,
376 tool: *mut ffi::GdkDeviceTool,
377 f: glib::ffi::gpointer,
378 ) {
379 let f: &F = &*(f as *const F);
380 f(
381 Seat::from_glib_borrow(this).unsafe_cast_ref(),
382 &from_glib_borrow(tool),
383 )
384 }
385 unsafe {
386 let f: Box_<F> = Box_::new(f);
387 connect_raw(
388 self.as_ptr() as *mut _,
389 b"tool-removed\0".as_ptr() as *const _,
390 Some(transmute::<_, unsafe extern "C" fn()>(
391 tool_removed_trampoline::<Self, F> as *const (),
392 )),
393 Box_::into_raw(f),
394 )
395 }
396 }
397}
398
399impl<O: IsA<Seat>> SeatExt for O {}
400
401impl fmt::Display for Seat {
402 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
403 f.write_str("Seat")
404 }
405}