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::{Device, DeviceTool, Display, SeatCapabilities, ffi};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
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 unsafe {
178 let f: &F = &*(f as *const F);
179 f(
180 Seat::from_glib_borrow(this).unsafe_cast_ref(),
181 &from_glib_borrow(device),
182 )
183 }
184 }
185 unsafe {
186 let f: Box_<F> = Box_::new(f);
187 connect_raw(
188 self.as_ptr() as *mut _,
189 c"device-added".as_ptr() as *const _,
190 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
191 device_added_trampoline::<Self, F> as *const (),
192 )),
193 Box_::into_raw(f),
194 )
195 }
196 }
197
198 /// Emitted when an input device is removed (e.g. unplugged).
199 /// ## `device`
200 /// the just removed [`Device`][crate::Device].
201 #[doc(alias = "device-removed")]
202 fn connect_device_removed<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
203 unsafe extern "C" fn device_removed_trampoline<
204 P: IsA<Seat>,
205 F: Fn(&P, &Device) + 'static,
206 >(
207 this: *mut ffi::GdkSeat,
208 device: *mut ffi::GdkDevice,
209 f: glib::ffi::gpointer,
210 ) {
211 unsafe {
212 let f: &F = &*(f as *const F);
213 f(
214 Seat::from_glib_borrow(this).unsafe_cast_ref(),
215 &from_glib_borrow(device),
216 )
217 }
218 }
219 unsafe {
220 let f: Box_<F> = Box_::new(f);
221 connect_raw(
222 self.as_ptr() as *mut _,
223 c"device-removed".as_ptr() as *const _,
224 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
225 device_removed_trampoline::<Self, F> as *const (),
226 )),
227 Box_::into_raw(f),
228 )
229 }
230 }
231
232 /// Emitted whenever a new tool is made known to the seat.
233 ///
234 /// The tool may later be assigned to a device (i.e. on
235 /// proximity with a tablet). The device will emit the
236 /// [`tool-changed`][struct@crate::Device#tool-changed] signal accordingly.
237 ///
238 /// A same tool may be used by several devices.
239 /// ## `tool`
240 /// the new [`DeviceTool`][crate::DeviceTool] known to the seat
241 #[doc(alias = "tool-added")]
242 fn connect_tool_added<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> SignalHandlerId {
243 unsafe extern "C" fn tool_added_trampoline<
244 P: IsA<Seat>,
245 F: Fn(&P, &DeviceTool) + 'static,
246 >(
247 this: *mut ffi::GdkSeat,
248 tool: *mut ffi::GdkDeviceTool,
249 f: glib::ffi::gpointer,
250 ) {
251 unsafe {
252 let f: &F = &*(f as *const F);
253 f(
254 Seat::from_glib_borrow(this).unsafe_cast_ref(),
255 &from_glib_borrow(tool),
256 )
257 }
258 }
259 unsafe {
260 let f: Box_<F> = Box_::new(f);
261 connect_raw(
262 self.as_ptr() as *mut _,
263 c"tool-added".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 unsafe {
286 let f: &F = &*(f as *const F);
287 f(
288 Seat::from_glib_borrow(this).unsafe_cast_ref(),
289 &from_glib_borrow(tool),
290 )
291 }
292 }
293 unsafe {
294 let f: Box_<F> = Box_::new(f);
295 connect_raw(
296 self.as_ptr() as *mut _,
297 c"tool-removed".as_ptr() as *const _,
298 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
299 tool_removed_trampoline::<Self, F> as *const (),
300 )),
301 Box_::into_raw(f),
302 )
303 }
304 }
305}
306
307impl<O: IsA<Seat>> SeatExt for O {}