1use crate::{ffi, EventController, Gesture, GestureSingle, PropagationLimit, PropagationPhase};
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 = "GtkGestureStylus")]
16 pub struct GestureStylus(Object<ffi::GtkGestureStylus, ffi::GtkGestureStylusClass>) @extends GestureSingle, Gesture, EventController;
17
18 match fn {
19 type_ => || ffi::gtk_gesture_stylus_get_type(),
20 }
21}
22
23impl GestureStylus {
24 #[doc(alias = "gtk_gesture_stylus_new")]
25 pub fn new() -> GestureStylus {
26 assert_initialized_main_thread!();
27 unsafe { Gesture::from_glib_full(ffi::gtk_gesture_stylus_new()).unsafe_cast() }
28 }
29
30 pub fn builder() -> GestureStylusBuilder {
35 GestureStylusBuilder::new()
36 }
37
38 #[doc(alias = "gtk_gesture_stylus_get_axis")]
39 #[doc(alias = "get_axis")]
40 pub fn axis(&self, axis: gdk::AxisUse) -> Option<f64> {
41 unsafe {
42 let mut value = std::mem::MaybeUninit::uninit();
43 let ret = from_glib(ffi::gtk_gesture_stylus_get_axis(
44 self.to_glib_none().0,
45 axis.into_glib(),
46 value.as_mut_ptr(),
47 ));
48 if ret {
49 Some(value.assume_init())
50 } else {
51 None
52 }
53 }
54 }
55
56 #[doc(alias = "gtk_gesture_stylus_get_backlog")]
57 #[doc(alias = "get_backlog")]
58 pub fn backlog(&self) -> Option<Vec<gdk::TimeCoord>> {
59 unsafe {
60 let mut backlog = std::ptr::null_mut();
61 let mut n_elems = std::mem::MaybeUninit::uninit();
62 let ret = from_glib(ffi::gtk_gesture_stylus_get_backlog(
63 self.to_glib_none().0,
64 &mut backlog,
65 n_elems.as_mut_ptr(),
66 ));
67 if ret {
68 Some(FromGlibContainer::from_glib_full_num(
69 backlog,
70 n_elems.assume_init() as _,
71 ))
72 } else {
73 None
74 }
75 }
76 }
77
78 #[doc(alias = "gtk_gesture_stylus_get_device_tool")]
79 #[doc(alias = "get_device_tool")]
80 pub fn device_tool(&self) -> Option<gdk::DeviceTool> {
81 unsafe {
82 from_glib_none(ffi::gtk_gesture_stylus_get_device_tool(
83 self.to_glib_none().0,
84 ))
85 }
86 }
87
88 #[cfg(feature = "v4_10")]
89 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
90 #[doc(alias = "gtk_gesture_stylus_get_stylus_only")]
91 #[doc(alias = "get_stylus_only")]
92 #[doc(alias = "stylus-only")]
93 pub fn is_stylus_only(&self) -> bool {
94 unsafe {
95 from_glib(ffi::gtk_gesture_stylus_get_stylus_only(
96 self.to_glib_none().0,
97 ))
98 }
99 }
100
101 #[cfg(feature = "v4_10")]
102 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
103 #[doc(alias = "gtk_gesture_stylus_set_stylus_only")]
104 #[doc(alias = "stylus-only")]
105 pub fn set_stylus_only(&self, stylus_only: bool) {
106 unsafe {
107 ffi::gtk_gesture_stylus_set_stylus_only(self.to_glib_none().0, stylus_only.into_glib());
108 }
109 }
110
111 #[doc(alias = "down")]
112 pub fn connect_down<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
113 unsafe extern "C" fn down_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
114 this: *mut ffi::GtkGestureStylus,
115 x: std::ffi::c_double,
116 y: std::ffi::c_double,
117 f: glib::ffi::gpointer,
118 ) {
119 let f: &F = &*(f as *const F);
120 f(&from_glib_borrow(this), x, y)
121 }
122 unsafe {
123 let f: Box_<F> = Box_::new(f);
124 connect_raw(
125 self.as_ptr() as *mut _,
126 c"down".as_ptr() as *const _,
127 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
128 down_trampoline::<F> as *const (),
129 )),
130 Box_::into_raw(f),
131 )
132 }
133 }
134
135 #[doc(alias = "motion")]
136 pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
137 unsafe extern "C" fn motion_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
138 this: *mut ffi::GtkGestureStylus,
139 x: std::ffi::c_double,
140 y: std::ffi::c_double,
141 f: glib::ffi::gpointer,
142 ) {
143 let f: &F = &*(f as *const F);
144 f(&from_glib_borrow(this), x, y)
145 }
146 unsafe {
147 let f: Box_<F> = Box_::new(f);
148 connect_raw(
149 self.as_ptr() as *mut _,
150 c"motion".as_ptr() as *const _,
151 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
152 motion_trampoline::<F> as *const (),
153 )),
154 Box_::into_raw(f),
155 )
156 }
157 }
158
159 #[doc(alias = "proximity")]
160 pub fn connect_proximity<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
161 unsafe extern "C" fn proximity_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
162 this: *mut ffi::GtkGestureStylus,
163 x: std::ffi::c_double,
164 y: std::ffi::c_double,
165 f: glib::ffi::gpointer,
166 ) {
167 let f: &F = &*(f as *const F);
168 f(&from_glib_borrow(this), x, y)
169 }
170 unsafe {
171 let f: Box_<F> = Box_::new(f);
172 connect_raw(
173 self.as_ptr() as *mut _,
174 c"proximity".as_ptr() as *const _,
175 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
176 proximity_trampoline::<F> as *const (),
177 )),
178 Box_::into_raw(f),
179 )
180 }
181 }
182
183 #[doc(alias = "up")]
184 pub fn connect_up<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
185 unsafe extern "C" fn up_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
186 this: *mut ffi::GtkGestureStylus,
187 x: std::ffi::c_double,
188 y: std::ffi::c_double,
189 f: glib::ffi::gpointer,
190 ) {
191 let f: &F = &*(f as *const F);
192 f(&from_glib_borrow(this), x, y)
193 }
194 unsafe {
195 let f: Box_<F> = Box_::new(f);
196 connect_raw(
197 self.as_ptr() as *mut _,
198 c"up".as_ptr() as *const _,
199 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
200 up_trampoline::<F> as *const (),
201 )),
202 Box_::into_raw(f),
203 )
204 }
205 }
206
207 #[cfg(feature = "v4_10")]
208 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
209 #[doc(alias = "stylus-only")]
210 pub fn connect_stylus_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
211 unsafe extern "C" fn notify_stylus_only_trampoline<F: Fn(&GestureStylus) + 'static>(
212 this: *mut ffi::GtkGestureStylus,
213 _param_spec: glib::ffi::gpointer,
214 f: glib::ffi::gpointer,
215 ) {
216 let f: &F = &*(f as *const F);
217 f(&from_glib_borrow(this))
218 }
219 unsafe {
220 let f: Box_<F> = Box_::new(f);
221 connect_raw(
222 self.as_ptr() as *mut _,
223 c"notify::stylus-only".as_ptr() as *const _,
224 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
225 notify_stylus_only_trampoline::<F> as *const (),
226 )),
227 Box_::into_raw(f),
228 )
229 }
230 }
231}
232
233impl Default for GestureStylus {
234 fn default() -> Self {
235 Self::new()
236 }
237}
238
239#[must_use = "The builder must be built to be used"]
244pub struct GestureStylusBuilder {
245 builder: glib::object::ObjectBuilder<'static, GestureStylus>,
246}
247
248impl GestureStylusBuilder {
249 fn new() -> Self {
250 Self {
251 builder: glib::object::Object::builder(),
252 }
253 }
254
255 #[cfg(feature = "v4_10")]
256 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
257 pub fn stylus_only(self, stylus_only: bool) -> Self {
258 Self {
259 builder: self.builder.property("stylus-only", stylus_only),
260 }
261 }
262
263 pub fn button(self, button: u32) -> Self {
264 Self {
265 builder: self.builder.property("button", button),
266 }
267 }
268
269 pub fn exclusive(self, exclusive: bool) -> Self {
270 Self {
271 builder: self.builder.property("exclusive", exclusive),
272 }
273 }
274
275 pub fn touch_only(self, touch_only: bool) -> Self {
276 Self {
277 builder: self.builder.property("touch-only", touch_only),
278 }
279 }
280
281 pub fn n_points(self, n_points: u32) -> Self {
282 Self {
283 builder: self.builder.property("n-points", n_points),
284 }
285 }
286
287 pub fn name(self, name: impl Into<glib::GString>) -> Self {
288 Self {
289 builder: self.builder.property("name", name.into()),
290 }
291 }
292
293 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
294 Self {
295 builder: self
296 .builder
297 .property("propagation-limit", propagation_limit),
298 }
299 }
300
301 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
302 Self {
303 builder: self
304 .builder
305 .property("propagation-phase", propagation_phase),
306 }
307 }
308
309 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
312 pub fn build(self) -> GestureStylus {
313 assert_initialized_main_thread!();
314 self.builder.build()
315 }
316}