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