Skip to main content

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