gtk4/auto/gesture_stylus.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::{EventController, Gesture, GestureSingle, PropagationLimit, PropagationPhase, 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 /// Recognizes tablet stylus input.
16 ///
17 /// The provided signals just relay the basic information of the
18 /// stylus events.
19 ///
20 /// ## Properties
21 ///
22 ///
23 /// #### `stylus-only`
24 /// If this gesture should exclusively react to stylus input devices.
25 ///
26 /// Readable | Writeable | Construct
27 /// <details><summary><h4>GestureSingle</h4></summary>
28 ///
29 ///
30 /// #### `button`
31 /// Mouse button number to listen to, or 0 to listen for any button.
32 ///
33 /// Readable | Writeable
34 ///
35 ///
36 /// #### `exclusive`
37 /// Whether the gesture is exclusive.
38 ///
39 /// Exclusive gestures only listen to pointer and pointer emulated events.
40 ///
41 /// Readable | Writeable
42 ///
43 ///
44 /// #### `touch-only`
45 /// Whether the gesture handles only touch events.
46 ///
47 /// Readable | Writeable
48 /// </details>
49 /// <details><summary><h4>Gesture</h4></summary>
50 ///
51 ///
52 /// #### `n-points`
53 /// The number of touch points that trigger
54 /// recognition on this gesture.
55 ///
56 /// Readable | Writeable | Construct Only
57 /// </details>
58 /// <details><summary><h4>EventController</h4></summary>
59 ///
60 ///
61 /// #### `name`
62 /// The name for this controller, typically used for debugging purposes.
63 ///
64 /// Readable | Writeable
65 ///
66 ///
67 /// #### `propagation-limit`
68 /// The limit for which events this controller will handle.
69 ///
70 /// Readable | Writeable
71 ///
72 ///
73 /// #### `propagation-phase`
74 /// The propagation phase at which this controller will handle events.
75 ///
76 /// Readable | Writeable
77 ///
78 ///
79 /// #### `widget`
80 /// The widget receiving the `GdkEvents` that the controller will handle.
81 ///
82 /// Readable
83 /// </details>
84 ///
85 /// ## Signals
86 ///
87 ///
88 /// #### `down`
89 /// Emitted when the stylus touches the device.
90 ///
91 ///
92 ///
93 ///
94 /// #### `motion`
95 /// Emitted when the stylus moves while touching the device.
96 ///
97 ///
98 ///
99 ///
100 /// #### `proximity`
101 /// Emitted when the stylus is in proximity of the device.
102 ///
103 ///
104 ///
105 ///
106 /// #### `up`
107 /// Emitted when the stylus no longer touches the device.
108 ///
109 ///
110 /// <details><summary><h4>Gesture</h4></summary>
111 ///
112 ///
113 /// #### `begin`
114 /// Emitted when the gesture is recognized.
115 ///
116 /// This means the number of touch sequences matches
117 /// [`n-points`][struct@crate::Gesture#n-points].
118 ///
119 /// Note: These conditions may also happen when an extra touch
120 /// (eg. a third touch on a 2-touches gesture) is lifted, in that
121 /// situation @sequence won't pertain to the current set of active
122 /// touches, so don't rely on this being true.
123 ///
124 ///
125 ///
126 ///
127 /// #### `cancel`
128 /// Emitted whenever a sequence is cancelled.
129 ///
130 /// This usually happens on active touches when
131 /// [`EventControllerExt::reset()`][crate::prelude::EventControllerExt::reset()] is called on @gesture
132 /// (manually, due to grabs...), or the individual @sequence
133 /// was claimed by parent widgets' controllers (see
134 /// [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()]).
135 ///
136 /// @gesture must forget everything about @sequence as in
137 /// response to this signal.
138 ///
139 ///
140 ///
141 ///
142 /// #### `end`
143 /// Emitted when @gesture either stopped recognizing the event
144 /// sequences as something to be handled, or the number of touch
145 /// sequences became higher or lower than [`n-points`][struct@crate::Gesture#n-points].
146 ///
147 /// Note: @sequence might not pertain to the group of sequences that
148 /// were previously triggering recognition on @gesture (ie. a just
149 /// pressed touch sequence that exceeds [`n-points`][struct@crate::Gesture#n-points]).
150 /// This situation may be detected by checking through
151 /// [`GestureExt::handles_sequence()`][crate::prelude::GestureExt::handles_sequence()].
152 ///
153 ///
154 ///
155 ///
156 /// #### `sequence-state-changed`
157 /// Emitted whenever a sequence state changes.
158 ///
159 /// See [`GestureExt::set_sequence_state()`][crate::prelude::GestureExt::set_sequence_state()] to know
160 /// more about the expectable sequence lifetimes.
161 ///
162 ///
163 ///
164 ///
165 /// #### `update`
166 /// Emitted whenever an event is handled while the gesture is recognized.
167 ///
168 /// @sequence is guaranteed to pertain to the set of active touches.
169 ///
170 ///
171 /// </details>
172 ///
173 /// # Implements
174 ///
175 /// [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`], [`EventControllerExtManual`][trait@crate::prelude::EventControllerExtManual]
176 #[doc(alias = "GtkGestureStylus")]
177 pub struct GestureStylus(Object<ffi::GtkGestureStylus, ffi::GtkGestureStylusClass>) @extends GestureSingle, Gesture, EventController;
178
179 match fn {
180 type_ => || ffi::gtk_gesture_stylus_get_type(),
181 }
182}
183
184impl GestureStylus {
185 /// Creates a new [`GestureStylus`][crate::GestureStylus].
186 ///
187 /// # Returns
188 ///
189 /// a newly created stylus gesture
190 #[doc(alias = "gtk_gesture_stylus_new")]
191 pub fn new() -> GestureStylus {
192 assert_initialized_main_thread!();
193 unsafe { Gesture::from_glib_full(ffi::gtk_gesture_stylus_new()).unsafe_cast() }
194 }
195
196 // rustdoc-stripper-ignore-next
197 /// Creates a new builder-pattern struct instance to construct [`GestureStylus`] objects.
198 ///
199 /// This method returns an instance of [`GestureStylusBuilder`](crate::builders::GestureStylusBuilder) which can be used to create [`GestureStylus`] objects.
200 pub fn builder() -> GestureStylusBuilder {
201 GestureStylusBuilder::new()
202 }
203
204 /// Returns the current value for the requested @axis.
205 ///
206 /// This function must be called from the handler of one of the
207 /// [`down`][struct@crate::GestureStylus#down], [`motion`][struct@crate::GestureStylus#motion],
208 /// [`up`][struct@crate::GestureStylus#up] or [`proximity`][struct@crate::GestureStylus#proximity]
209 /// signals.
210 /// ## `axis`
211 /// requested device axis
212 ///
213 /// # Returns
214 ///
215 /// [`true`] if there is a current value for the axis
216 ///
217 /// ## `value`
218 /// return location for the axis value
219 #[doc(alias = "gtk_gesture_stylus_get_axis")]
220 #[doc(alias = "get_axis")]
221 pub fn axis(&self, axis: gdk::AxisUse) -> Option<f64> {
222 unsafe {
223 let mut value = std::mem::MaybeUninit::uninit();
224 let ret = from_glib(ffi::gtk_gesture_stylus_get_axis(
225 self.to_glib_none().0,
226 axis.into_glib(),
227 value.as_mut_ptr(),
228 ));
229 if ret { Some(value.assume_init()) } else { None }
230 }
231 }
232
233 /// Returns the accumulated backlog of tracking information.
234 ///
235 /// By default, GTK will limit rate of input events. On stylus input
236 /// where accuracy of strokes is paramount, this function returns the
237 /// accumulated coordinate/timing state before the emission of the
238 /// current [Gtk.GestureStylus::motion] signal.
239 ///
240 /// This function may only be called within a [`motion`][struct@crate::GestureStylus#motion]
241 /// signal handler, the state given in this signal and obtainable through
242 /// [`axis()`][Self::axis()] express the latest (most up-to-date)
243 /// state in motion history.
244 ///
245 /// The @backlog is provided in chronological order.
246 ///
247 /// # Returns
248 ///
249 /// [`true`] if there is a backlog to unfold in the current state.
250 ///
251 /// ## `backlog`
252 /// coordinates and times for the backlog events
253 #[doc(alias = "gtk_gesture_stylus_get_backlog")]
254 #[doc(alias = "get_backlog")]
255 pub fn backlog(&self) -> Option<Vec<gdk::TimeCoord>> {
256 unsafe {
257 let mut backlog = std::ptr::null_mut();
258 let mut n_elems = std::mem::MaybeUninit::uninit();
259 let ret = from_glib(ffi::gtk_gesture_stylus_get_backlog(
260 self.to_glib_none().0,
261 &mut backlog,
262 n_elems.as_mut_ptr(),
263 ));
264 if ret {
265 Some(FromGlibContainer::from_glib_full_num(
266 backlog,
267 n_elems.assume_init() as _,
268 ))
269 } else {
270 None
271 }
272 }
273 }
274
275 /// Returns the [`gdk::DeviceTool`][crate::gdk::DeviceTool] currently driving input through this gesture.
276 ///
277 /// This function must be called from the handler of one of the
278 /// [`down`][struct@crate::GestureStylus#down], [`motion`][struct@crate::GestureStylus#motion],
279 /// [`up`][struct@crate::GestureStylus#up] or [`proximity`][struct@crate::GestureStylus#proximity]
280 /// signals.
281 ///
282 /// # Returns
283 ///
284 /// The current stylus tool
285 #[doc(alias = "gtk_gesture_stylus_get_device_tool")]
286 #[doc(alias = "get_device_tool")]
287 pub fn device_tool(&self) -> Option<gdk::DeviceTool> {
288 unsafe {
289 from_glib_none(ffi::gtk_gesture_stylus_get_device_tool(
290 self.to_glib_none().0,
291 ))
292 }
293 }
294
295 /// Checks whether the gesture is for styluses only.
296 ///
297 /// Stylus-only gestures will signal events exclusively from stylus
298 /// input devices.
299 ///
300 /// # Returns
301 ///
302 /// [`true`] if the gesture is only for stylus events
303 #[cfg(feature = "v4_10")]
304 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
305 #[doc(alias = "gtk_gesture_stylus_get_stylus_only")]
306 #[doc(alias = "get_stylus_only")]
307 #[doc(alias = "stylus-only")]
308 pub fn is_stylus_only(&self) -> bool {
309 unsafe {
310 from_glib(ffi::gtk_gesture_stylus_get_stylus_only(
311 self.to_glib_none().0,
312 ))
313 }
314 }
315
316 /// Sets the state of stylus-only
317 ///
318 /// If true, the gesture will exclusively handle events from stylus input devices,
319 /// otherwise it'll handle events from any pointing device.
320 /// ## `stylus_only`
321 /// whether the gesture is used exclusively for stylus events
322 #[cfg(feature = "v4_10")]
323 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
324 #[doc(alias = "gtk_gesture_stylus_set_stylus_only")]
325 #[doc(alias = "stylus-only")]
326 pub fn set_stylus_only(&self, stylus_only: bool) {
327 unsafe {
328 ffi::gtk_gesture_stylus_set_stylus_only(self.to_glib_none().0, stylus_only.into_glib());
329 }
330 }
331
332 /// Emitted when the stylus touches the device.
333 /// ## `x`
334 /// the X coordinate of the stylus event
335 /// ## `y`
336 /// the Y coordinate of the stylus event
337 #[doc(alias = "down")]
338 pub fn connect_down<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
339 unsafe extern "C" fn down_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
340 this: *mut ffi::GtkGestureStylus,
341 x: std::ffi::c_double,
342 y: std::ffi::c_double,
343 f: glib::ffi::gpointer,
344 ) {
345 unsafe {
346 let f: &F = &*(f as *const F);
347 f(&from_glib_borrow(this), x, y)
348 }
349 }
350 unsafe {
351 let f: Box_<F> = Box_::new(f);
352 connect_raw(
353 self.as_ptr() as *mut _,
354 c"down".as_ptr() as *const _,
355 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
356 down_trampoline::<F> as *const (),
357 )),
358 Box_::into_raw(f),
359 )
360 }
361 }
362
363 /// Emitted when the stylus moves while touching the device.
364 /// ## `x`
365 /// the X coordinate of the stylus event
366 /// ## `y`
367 /// the Y coordinate of the stylus event
368 #[doc(alias = "motion")]
369 pub fn connect_motion<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
370 unsafe extern "C" fn motion_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
371 this: *mut ffi::GtkGestureStylus,
372 x: std::ffi::c_double,
373 y: std::ffi::c_double,
374 f: glib::ffi::gpointer,
375 ) {
376 unsafe {
377 let f: &F = &*(f as *const F);
378 f(&from_glib_borrow(this), x, y)
379 }
380 }
381 unsafe {
382 let f: Box_<F> = Box_::new(f);
383 connect_raw(
384 self.as_ptr() as *mut _,
385 c"motion".as_ptr() as *const _,
386 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
387 motion_trampoline::<F> as *const (),
388 )),
389 Box_::into_raw(f),
390 )
391 }
392 }
393
394 /// Emitted when the stylus is in proximity of the device.
395 /// ## `x`
396 /// the X coordinate of the stylus event
397 /// ## `y`
398 /// the Y coordinate of the stylus event
399 #[doc(alias = "proximity")]
400 pub fn connect_proximity<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
401 unsafe extern "C" fn proximity_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
402 this: *mut ffi::GtkGestureStylus,
403 x: std::ffi::c_double,
404 y: std::ffi::c_double,
405 f: glib::ffi::gpointer,
406 ) {
407 unsafe {
408 let f: &F = &*(f as *const F);
409 f(&from_glib_borrow(this), x, y)
410 }
411 }
412 unsafe {
413 let f: Box_<F> = Box_::new(f);
414 connect_raw(
415 self.as_ptr() as *mut _,
416 c"proximity".as_ptr() as *const _,
417 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
418 proximity_trampoline::<F> as *const (),
419 )),
420 Box_::into_raw(f),
421 )
422 }
423 }
424
425 /// Emitted when the stylus no longer touches the device.
426 /// ## `x`
427 /// the X coordinate of the stylus event
428 /// ## `y`
429 /// the Y coordinate of the stylus event
430 #[doc(alias = "up")]
431 pub fn connect_up<F: Fn(&Self, f64, f64) + 'static>(&self, f: F) -> SignalHandlerId {
432 unsafe extern "C" fn up_trampoline<F: Fn(&GestureStylus, f64, f64) + 'static>(
433 this: *mut ffi::GtkGestureStylus,
434 x: std::ffi::c_double,
435 y: std::ffi::c_double,
436 f: glib::ffi::gpointer,
437 ) {
438 unsafe {
439 let f: &F = &*(f as *const F);
440 f(&from_glib_borrow(this), x, y)
441 }
442 }
443 unsafe {
444 let f: Box_<F> = Box_::new(f);
445 connect_raw(
446 self.as_ptr() as *mut _,
447 c"up".as_ptr() as *const _,
448 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
449 up_trampoline::<F> as *const (),
450 )),
451 Box_::into_raw(f),
452 )
453 }
454 }
455
456 #[cfg(feature = "v4_10")]
457 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
458 #[doc(alias = "stylus-only")]
459 pub fn connect_stylus_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
460 unsafe extern "C" fn notify_stylus_only_trampoline<F: Fn(&GestureStylus) + 'static>(
461 this: *mut ffi::GtkGestureStylus,
462 _param_spec: glib::ffi::gpointer,
463 f: glib::ffi::gpointer,
464 ) {
465 unsafe {
466 let f: &F = &*(f as *const F);
467 f(&from_glib_borrow(this))
468 }
469 }
470 unsafe {
471 let f: Box_<F> = Box_::new(f);
472 connect_raw(
473 self.as_ptr() as *mut _,
474 c"notify::stylus-only".as_ptr() as *const _,
475 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
476 notify_stylus_only_trampoline::<F> as *const (),
477 )),
478 Box_::into_raw(f),
479 )
480 }
481 }
482}
483
484impl Default for GestureStylus {
485 fn default() -> Self {
486 Self::new()
487 }
488}
489
490// rustdoc-stripper-ignore-next
491/// A [builder-pattern] type to construct [`GestureStylus`] objects.
492///
493/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
494#[must_use = "The builder must be built to be used"]
495pub struct GestureStylusBuilder {
496 builder: glib::object::ObjectBuilder<'static, GestureStylus>,
497}
498
499impl GestureStylusBuilder {
500 fn new() -> Self {
501 Self {
502 builder: glib::object::Object::builder(),
503 }
504 }
505
506 /// If this gesture should exclusively react to stylus input devices.
507 #[cfg(feature = "v4_10")]
508 #[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
509 pub fn stylus_only(self, stylus_only: bool) -> Self {
510 Self {
511 builder: self.builder.property("stylus-only", stylus_only),
512 }
513 }
514
515 /// Mouse button number to listen to, or 0 to listen for any button.
516 pub fn button(self, button: u32) -> Self {
517 Self {
518 builder: self.builder.property("button", button),
519 }
520 }
521
522 /// Whether the gesture is exclusive.
523 ///
524 /// Exclusive gestures only listen to pointer and pointer emulated events.
525 pub fn exclusive(self, exclusive: bool) -> Self {
526 Self {
527 builder: self.builder.property("exclusive", exclusive),
528 }
529 }
530
531 /// Whether the gesture handles only touch events.
532 pub fn touch_only(self, touch_only: bool) -> Self {
533 Self {
534 builder: self.builder.property("touch-only", touch_only),
535 }
536 }
537
538 /// The number of touch points that trigger
539 /// recognition on this gesture.
540 pub fn n_points(self, n_points: u32) -> Self {
541 Self {
542 builder: self.builder.property("n-points", n_points),
543 }
544 }
545
546 /// The name for this controller, typically used for debugging purposes.
547 pub fn name(self, name: impl Into<glib::GString>) -> Self {
548 Self {
549 builder: self.builder.property("name", name.into()),
550 }
551 }
552
553 /// The limit for which events this controller will handle.
554 pub fn propagation_limit(self, propagation_limit: PropagationLimit) -> Self {
555 Self {
556 builder: self
557 .builder
558 .property("propagation-limit", propagation_limit),
559 }
560 }
561
562 /// The propagation phase at which this controller will handle events.
563 pub fn propagation_phase(self, propagation_phase: PropagationPhase) -> Self {
564 Self {
565 builder: self
566 .builder
567 .property("propagation-phase", propagation_phase),
568 }
569 }
570
571 // rustdoc-stripper-ignore-next
572 /// Build the [`GestureStylus`].
573 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
574 pub fn build(self) -> GestureStylus {
575 assert_initialized_main_thread!();
576 self.builder.build()
577 }
578}