1use 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 #[doc(alias = "GdkSeat")]
16 pub struct Seat(Object<ffi::GdkSeat>);
17
18 match fn {
19 type_ => || ffi::gdk_seat_get_type(),
20 }
21}
22
23impl Seat {
24 pub const NONE: Option<&'static Seat> = None;
25}
26
27pub trait SeatExt: IsA<Seat> + 'static {
28 #[doc(alias = "gdk_seat_get_capabilities")]
29 #[doc(alias = "get_capabilities")]
30 fn capabilities(&self) -> SeatCapabilities {
31 unsafe {
32 from_glib(ffi::gdk_seat_get_capabilities(
33 self.as_ref().to_glib_none().0,
34 ))
35 }
36 }
37
38 #[doc(alias = "gdk_seat_get_devices")]
39 #[doc(alias = "get_devices")]
40 fn devices(&self, capabilities: SeatCapabilities) -> Vec<Device> {
41 unsafe {
42 FromGlibPtrContainer::from_glib_container(ffi::gdk_seat_get_devices(
43 self.as_ref().to_glib_none().0,
44 capabilities.into_glib(),
45 ))
46 }
47 }
48
49 #[doc(alias = "gdk_seat_get_display")]
50 #[doc(alias = "get_display")]
51 fn display(&self) -> Display {
52 unsafe { from_glib_none(ffi::gdk_seat_get_display(self.as_ref().to_glib_none().0)) }
53 }
54
55 #[doc(alias = "gdk_seat_get_keyboard")]
56 #[doc(alias = "get_keyboard")]
57 fn keyboard(&self) -> Option<Device> {
58 unsafe { from_glib_none(ffi::gdk_seat_get_keyboard(self.as_ref().to_glib_none().0)) }
59 }
60
61 #[doc(alias = "gdk_seat_get_pointer")]
62 #[doc(alias = "get_pointer")]
63 fn pointer(&self) -> Option<Device> {
64 unsafe { from_glib_none(ffi::gdk_seat_get_pointer(self.as_ref().to_glib_none().0)) }
65 }
66
67 #[doc(alias = "gdk_seat_get_tools")]
68 #[doc(alias = "get_tools")]
69 fn tools(&self) -> Vec<DeviceTool> {
70 unsafe {
71 FromGlibPtrContainer::from_glib_container(ffi::gdk_seat_get_tools(
72 self.as_ref().to_glib_none().0,
73 ))
74 }
75 }
76
77 #[doc(alias = "device-added")]
78 fn connect_device_added<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
79 unsafe extern "C" fn device_added_trampoline<P: IsA<Seat>, F: Fn(&P, &Device) + 'static>(
80 this: *mut ffi::GdkSeat,
81 device: *mut ffi::GdkDevice,
82 f: glib::ffi::gpointer,
83 ) {
84 let f: &F = &*(f as *const F);
85 f(
86 Seat::from_glib_borrow(this).unsafe_cast_ref(),
87 &from_glib_borrow(device),
88 )
89 }
90 unsafe {
91 let f: Box_<F> = Box_::new(f);
92 connect_raw(
93 self.as_ptr() as *mut _,
94 c"device-added".as_ptr() as *const _,
95 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
96 device_added_trampoline::<Self, F> as *const (),
97 )),
98 Box_::into_raw(f),
99 )
100 }
101 }
102
103 #[doc(alias = "device-removed")]
104 fn connect_device_removed<F: Fn(&Self, &Device) + 'static>(&self, f: F) -> SignalHandlerId {
105 unsafe extern "C" fn device_removed_trampoline<
106 P: IsA<Seat>,
107 F: Fn(&P, &Device) + 'static,
108 >(
109 this: *mut ffi::GdkSeat,
110 device: *mut ffi::GdkDevice,
111 f: glib::ffi::gpointer,
112 ) {
113 let f: &F = &*(f as *const F);
114 f(
115 Seat::from_glib_borrow(this).unsafe_cast_ref(),
116 &from_glib_borrow(device),
117 )
118 }
119 unsafe {
120 let f: Box_<F> = Box_::new(f);
121 connect_raw(
122 self.as_ptr() as *mut _,
123 c"device-removed".as_ptr() as *const _,
124 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
125 device_removed_trampoline::<Self, F> as *const (),
126 )),
127 Box_::into_raw(f),
128 )
129 }
130 }
131
132 #[doc(alias = "tool-added")]
133 fn connect_tool_added<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> SignalHandlerId {
134 unsafe extern "C" fn tool_added_trampoline<
135 P: IsA<Seat>,
136 F: Fn(&P, &DeviceTool) + 'static,
137 >(
138 this: *mut ffi::GdkSeat,
139 tool: *mut ffi::GdkDeviceTool,
140 f: glib::ffi::gpointer,
141 ) {
142 let f: &F = &*(f as *const F);
143 f(
144 Seat::from_glib_borrow(this).unsafe_cast_ref(),
145 &from_glib_borrow(tool),
146 )
147 }
148 unsafe {
149 let f: Box_<F> = Box_::new(f);
150 connect_raw(
151 self.as_ptr() as *mut _,
152 c"tool-added".as_ptr() as *const _,
153 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
154 tool_added_trampoline::<Self, F> as *const (),
155 )),
156 Box_::into_raw(f),
157 )
158 }
159 }
160
161 #[doc(alias = "tool-removed")]
162 fn connect_tool_removed<F: Fn(&Self, &DeviceTool) + 'static>(&self, f: F) -> SignalHandlerId {
163 unsafe extern "C" fn tool_removed_trampoline<
164 P: IsA<Seat>,
165 F: Fn(&P, &DeviceTool) + 'static,
166 >(
167 this: *mut ffi::GdkSeat,
168 tool: *mut ffi::GdkDeviceTool,
169 f: glib::ffi::gpointer,
170 ) {
171 let f: &F = &*(f as *const F);
172 f(
173 Seat::from_glib_borrow(this).unsafe_cast_ref(),
174 &from_glib_borrow(tool),
175 )
176 }
177 unsafe {
178 let f: Box_<F> = Box_::new(f);
179 connect_raw(
180 self.as_ptr() as *mut _,
181 c"tool-removed".as_ptr() as *const _,
182 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
183 tool_removed_trampoline::<Self, F> as *const (),
184 )),
185 Box_::into_raw(f),
186 )
187 }
188 }
189}
190
191impl<O: IsA<Seat>> SeatExt for O {}