gdk4/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::{ffi, Device, DeviceTool, Display, SeatCapabilities};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// Represents a collection of input devices 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    ///  Emitted when a new input device is related to this seat.
32    ///
33    ///
34    ///
35    ///
36    /// #### `device-removed`
37    ///  Emitted when an input device is removed (e.g. unplugged).
38    ///
39    ///
40    ///
41    ///
42    /// #### `tool-added`
43    ///  Emitted whenever a new tool is made known to the seat.
44    ///
45    /// The tool may later be assigned to a device (i.e. on
46    /// proximity with a tablet). The device will emit the
47    /// [`tool-changed`][struct@crate::Device#tool-changed] signal accordingly.
48    ///
49    /// A same tool may be used by several devices.
50    ///
51    ///
52    ///
53    ///
54    /// #### `tool-removed`
55    ///  Emitted whenever a tool is no longer known to this @seat.
56    ///
57    ///
58    ///
59    /// # Implements
60    ///
61    /// [`SeatExt`][trait@crate::prelude::SeatExt]
62    #[doc(alias = "GdkSeat")]
63    pub struct Seat(Object<ffi::GdkSeat>);
64
65    match fn {
66        type_ => || ffi::gdk_seat_get_type(),
67    }
68}
69
70impl Seat {
71    pub const NONE: Option<&'static Seat> = None;
72}
73
74/// Trait containing all [`struct@Seat`] methods.
75///
76/// # Implementors
77///
78/// [`Seat`][struct@crate::Seat]
79pub trait SeatExt: IsA<Seat> + 'static {
80    /// Returns the capabilities this [`Seat`][crate::Seat] currently has.
81    ///
82    /// # Returns
83    ///
84    /// the seat capabilities
85    #[doc(alias = "gdk_seat_get_capabilities")]
86    #[doc(alias = "get_capabilities")]
87    fn capabilities(&self) -> SeatCapabilities {
88        unsafe {
89            from_glib(ffi::gdk_seat_get_capabilities(
90                self.as_ref().to_glib_none().0,
91            ))
92        }
93    }
94
95    /// Returns the devices that match the given capabilities.
96    /// ## `capabilities`
97    /// capabilities to get devices for
98    ///
99    /// # Returns
100    ///
101    /// A list
102    ///   of `GdkDevices`. The list must be freed with g_list_free(),
103    ///   the elements are owned by GTK and must not be freed.
104    #[doc(alias = "gdk_seat_get_devices")]
105    #[doc(alias = "get_devices")]
106    fn devices(&self, capabilities: SeatCapabilities) -> Vec<Device> {
107        unsafe {
108            FromGlibPtrContainer::from_glib_container(ffi::gdk_seat_get_devices(
109                self.as_ref().to_glib_none().0,
110                capabilities.into_glib(),
111            ))
112        }
113    }
114
115    /// Returns the [`Display`][crate::Display] this seat belongs to.
116    ///
117    /// # Returns
118    ///
119    /// a [`Display`][crate::Display]. This object
120    ///   is owned by GTK and must not be freed.
121    #[doc(alias = "gdk_seat_get_display")]
122    #[doc(alias = "get_display")]
123    fn display(&self) -> Display {
124        unsafe { from_glib_none(ffi::gdk_seat_get_display(self.as_ref().to_glib_none().0)) }
125    }
126
127    /// Returns the device that routes keyboard events.
128    ///
129    /// # Returns
130    ///
131    /// a [`Device`][crate::Device] with keyboard
132    ///   capabilities. This object is owned by GTK and must not be freed.
133    #[doc(alias = "gdk_seat_get_keyboard")]
134    #[doc(alias = "get_keyboard")]
135    fn keyboard(&self) -> Option<Device> {
136        unsafe { from_glib_none(ffi::gdk_seat_get_keyboard(self.as_ref().to_glib_none().0)) }
137    }
138
139    /// Returns the device that routes pointer events.
140    ///
141    /// # Returns
142    ///
143    /// a [`Device`][crate::Device] with pointer
144    ///   capabilities. This object is owned by GTK and must not be freed.
145    #[doc(alias = "gdk_seat_get_pointer")]
146    #[doc(alias = "get_pointer")]
147    fn pointer(&self) -> Option<Device> {
148        unsafe { from_glib_none(ffi::gdk_seat_get_pointer(self.as_ref().to_glib_none().0)) }
149    }
150
151    /// Returns all `GdkDeviceTools` that are known to the application.
152    ///
153    /// # Returns
154    ///
155    ///
156    ///   A list of tools. Free with g_list_free().
157    #[doc(alias = "gdk_seat_get_tools")]
158    #[doc(alias = "get_tools")]
159    fn tools(&self) -> Vec<DeviceTool> {
160        unsafe {
161            FromGlibPtrContainer::from_glib_container(ffi::gdk_seat_get_tools(
162                self.as_ref().to_glib_none().0,
163            ))
164        }
165    }
166
167    /// Emitted when a new input device is related to this seat.
168    /// ## `device`
169    /// the newly added [`Device`][crate::Device].
170    #[doc(alias = "device-added")]
171    fn connect_device_added<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
172        unsafe extern "C" fn device_added_trampoline<P: IsA<Seat>, F: Fn(&P, &Device) + 'static>(
173            this: *mut ffi::GdkSeat,
174            device: *mut ffi::GdkDevice,
175            f: glib::ffi::gpointer,
176        ) {
177            let f: &F = &*(f as *const F);
178            f(
179                Seat::from_glib_borrow(this).unsafe_cast_ref(),
180                &from_glib_borrow(device),
181            )
182        }
183        unsafe {
184            let f: Box_<F> = Box_::new(f);
185            connect_raw(
186                self.as_ptr() as *mut _,
187                c"device-added".as_ptr() as *const _,
188                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
189                    device_added_trampoline::<Self, F> as *const (),
190                )),
191                Box_::into_raw(f),
192            )
193        }
194    }
195
196    /// Emitted when an input device is removed (e.g. unplugged).
197    /// ## `device`
198    /// the just removed [`Device`][crate::Device].
199    #[doc(alias = "device-removed")]
200    fn connect_device_removed<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
201        unsafe extern "C" fn device_removed_trampoline<
202            P: IsA<Seat>,
203            F: Fn(&P, &Device) + 'static,
204        >(
205            this: *mut ffi::GdkSeat,
206            device: *mut ffi::GdkDevice,
207            f: glib::ffi::gpointer,
208        ) {
209            let f: &F = &*(f as *const F);
210            f(
211                Seat::from_glib_borrow(this).unsafe_cast_ref(),
212                &from_glib_borrow(device),
213            )
214        }
215        unsafe {
216            let f: Box_<F> = Box_::new(f);
217            connect_raw(
218                self.as_ptr() as *mut _,
219                c"device-removed".as_ptr() as *const _,
220                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
221                    device_removed_trampoline::<Self, F> as *const (),
222                )),
223                Box_::into_raw(f),
224            )
225        }
226    }
227
228    /// Emitted whenever a new tool is made known to the seat.
229    ///
230    /// The tool may later be assigned to a device (i.e. on
231    /// proximity with a tablet). The device will emit the
232    /// [`tool-changed`][struct@crate::Device#tool-changed] signal accordingly.
233    ///
234    /// A same tool may be used by several devices.
235    /// ## `tool`
236    /// the new [`DeviceTool`][crate::DeviceTool] known to the seat
237    #[doc(alias = "tool-added")]
238    fn connect_tool_added<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> SignalHandlerId {
239        unsafe extern "C" fn tool_added_trampoline<
240            P: IsA<Seat>,
241            F: Fn(&P, &DeviceTool) + 'static,
242        >(
243            this: *mut ffi::GdkSeat,
244            tool: *mut ffi::GdkDeviceTool,
245            f: glib::ffi::gpointer,
246        ) {
247            let f: &F = &*(f as *const F);
248            f(
249                Seat::from_glib_borrow(this).unsafe_cast_ref(),
250                &from_glib_borrow(tool),
251            )
252        }
253        unsafe {
254            let f: Box_<F> = Box_::new(f);
255            connect_raw(
256                self.as_ptr() as *mut _,
257                c"tool-added".as_ptr() as *const _,
258                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
259                    tool_added_trampoline::<Self, F> as *const (),
260                )),
261                Box_::into_raw(f),
262            )
263        }
264    }
265
266    /// Emitted whenever a tool is no longer known to this @seat.
267    /// ## `tool`
268    /// the just removed [`DeviceTool`][crate::DeviceTool]
269    #[doc(alias = "tool-removed")]
270    fn connect_tool_removed<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> SignalHandlerId {
271        unsafe extern "C" fn tool_removed_trampoline<
272            P: IsA<Seat>,
273            F: Fn(&P, &DeviceTool) + 'static,
274        >(
275            this: *mut ffi::GdkSeat,
276            tool: *mut ffi::GdkDeviceTool,
277            f: glib::ffi::gpointer,
278        ) {
279            let f: &F = &*(f as *const F);
280            f(
281                Seat::from_glib_borrow(this).unsafe_cast_ref(),
282                &from_glib_borrow(tool),
283            )
284        }
285        unsafe {
286            let f: Box_<F> = Box_::new(f);
287            connect_raw(
288                self.as_ptr() as *mut _,
289                c"tool-removed".as_ptr() as *const _,
290                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
291                    tool_removed_trampoline::<Self, F> as *const (),
292                )),
293                Box_::into_raw(f),
294            )
295        }
296    }
297}
298
299impl<O: IsA<Seat>> SeatExt for O {}