Skip to main content

gtk/auto/
gesture_single.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, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// [`GestureSingle`][crate::GestureSingle] is a subclass of [`Gesture`][crate::Gesture], optimized (although
15    /// not restricted) for dealing with mouse and single-touch gestures. Under
16    /// interaction, these gestures stick to the first interacting sequence, which
17    /// is accessible through [`GestureSingleExt::current_sequence()`][crate::prelude::GestureSingleExt::current_sequence()] while the
18    /// gesture is being interacted with.
19    ///
20    /// By default gestures react to both `GDK_BUTTON_PRIMARY` and touch
21    /// events, [`GestureSingleExt::set_touch_only()`][crate::prelude::GestureSingleExt::set_touch_only()] can be used to change the
22    /// touch behavior. Callers may also specify a different mouse button number
23    /// to interact with through [`GestureSingleExt::set_button()`][crate::prelude::GestureSingleExt::set_button()], or react to any
24    /// mouse button by setting 0. While the gesture is active, the button being
25    /// currently pressed can be known through [`GestureSingleExt::current_button()`][crate::prelude::GestureSingleExt::current_button()].
26    ///
27    /// ## Properties
28    ///
29    ///
30    /// #### `button`
31    ///  Mouse button number to listen to, or 0 to listen for any button.
32    ///
33    /// Readable | Writable
34    ///
35    ///
36    /// #### `exclusive`
37    ///  Whether the gesture is exclusive. Exclusive gestures only listen to pointer
38    /// and pointer emulated events.
39    ///
40    /// Readable | Writable
41    ///
42    ///
43    /// #### `touch-only`
44    ///  Whether the gesture handles only touch events.
45    ///
46    /// Readable | Writable
47    /// <details><summary><h4>Gesture</h4></summary>
48    ///
49    ///
50    /// #### `n-points`
51    ///  The number of touch points that trigger recognition on this gesture,
52    ///
53    /// Readable | Writable | Construct Only
54    ///
55    ///
56    /// #### `window`
57    ///  If non-[`None`], the gesture will only listen for events that happen on
58    /// this [`gdk::Window`][crate::gdk::Window], or a child of it.
59    ///
60    /// Readable | Writable
61    /// </details>
62    /// <details><summary><h4>EventController</h4></summary>
63    ///
64    ///
65    /// #### `propagation-phase`
66    ///  The propagation phase at which this controller will handle events.
67    ///
68    /// Readable | Writable
69    ///
70    ///
71    /// #### `widget`
72    ///  The widget receiving the `GdkEvents` that the controller will handle.
73    ///
74    /// Readable | Writable | Construct Only
75    /// </details>
76    ///
77    /// # Implements
78    ///
79    /// [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
80    #[doc(alias = "GtkGestureSingle")]
81    pub struct GestureSingle(Object<ffi::GtkGestureSingle, ffi::GtkGestureSingleClass>) @extends Gesture, EventController;
82
83    match fn {
84        type_ => || ffi::gtk_gesture_single_get_type(),
85    }
86}
87
88impl GestureSingle {
89    pub const NONE: Option<&'static GestureSingle> = None;
90}
91
92/// Trait containing all [`struct@GestureSingle`] methods.
93///
94/// # Implementors
95///
96/// [`GestureDrag`][struct@crate::GestureDrag], [`GestureLongPress`][struct@crate::GestureLongPress], [`GestureMultiPress`][struct@crate::GestureMultiPress], [`GestureSingle`][struct@crate::GestureSingle], [`GestureStylus`][struct@crate::GestureStylus], [`GestureSwipe`][struct@crate::GestureSwipe]
97pub trait GestureSingleExt: IsA<GestureSingle> + 'static {
98    /// Returns the button number `self` listens for, or 0 if `self`
99    /// reacts to any button press.
100    ///
101    /// # Returns
102    ///
103    /// The button number, or 0 for any button
104    #[doc(alias = "gtk_gesture_single_get_button")]
105    #[doc(alias = "get_button")]
106    fn button(&self) -> u32 {
107        unsafe { ffi::gtk_gesture_single_get_button(self.as_ref().to_glib_none().0) }
108    }
109
110    /// Returns the button number currently interacting with `self`, or 0 if there
111    /// is none.
112    ///
113    /// # Returns
114    ///
115    /// The current button number
116    #[doc(alias = "gtk_gesture_single_get_current_button")]
117    #[doc(alias = "get_current_button")]
118    fn current_button(&self) -> u32 {
119        unsafe { ffi::gtk_gesture_single_get_current_button(self.as_ref().to_glib_none().0) }
120    }
121
122    /// Returns the event sequence currently interacting with `self`.
123    /// This is only meaningful if [`GestureExt::is_active()`][crate::prelude::GestureExt::is_active()] returns [`true`].
124    ///
125    /// # Returns
126    ///
127    /// the current sequence
128    #[doc(alias = "gtk_gesture_single_get_current_sequence")]
129    #[doc(alias = "get_current_sequence")]
130    fn current_sequence(&self) -> Option<gdk::EventSequence> {
131        unsafe {
132            from_glib_full(ffi::gtk_gesture_single_get_current_sequence(
133                self.as_ref().to_glib_none().0,
134            ))
135        }
136    }
137
138    /// Gets whether a gesture is exclusive. For more information, see
139    /// [`set_exclusive()`][Self::set_exclusive()].
140    ///
141    /// # Returns
142    ///
143    /// Whether the gesture is exclusive
144    #[doc(alias = "gtk_gesture_single_get_exclusive")]
145    #[doc(alias = "get_exclusive")]
146    #[doc(alias = "exclusive")]
147    fn is_exclusive(&self) -> bool {
148        unsafe {
149            from_glib(ffi::gtk_gesture_single_get_exclusive(
150                self.as_ref().to_glib_none().0,
151            ))
152        }
153    }
154
155    /// Returns [`true`] if the gesture is only triggered by touch events.
156    ///
157    /// # Returns
158    ///
159    /// [`true`] if the gesture only handles touch events
160    #[doc(alias = "gtk_gesture_single_get_touch_only")]
161    #[doc(alias = "get_touch_only")]
162    #[doc(alias = "touch-only")]
163    fn is_touch_only(&self) -> bool {
164        unsafe {
165            from_glib(ffi::gtk_gesture_single_get_touch_only(
166                self.as_ref().to_glib_none().0,
167            ))
168        }
169    }
170
171    /// Sets the button number `self` listens to. If non-0, every
172    /// button press from a different button number will be ignored.
173    /// Touch events implicitly match with button 1.
174    /// ## `button`
175    /// button number to listen to, or 0 for any button
176    #[doc(alias = "gtk_gesture_single_set_button")]
177    #[doc(alias = "button")]
178    fn set_button(&self, button: u32) {
179        unsafe {
180            ffi::gtk_gesture_single_set_button(self.as_ref().to_glib_none().0, button);
181        }
182    }
183
184    /// Sets whether `self` is exclusive. An exclusive gesture will
185    /// only handle pointer and "pointer emulated" touch events, so at
186    /// any given time, there is only one sequence able to interact with
187    /// those.
188    /// ## `exclusive`
189    /// [`true`] to make `self` exclusive
190    #[doc(alias = "gtk_gesture_single_set_exclusive")]
191    #[doc(alias = "exclusive")]
192    fn set_exclusive(&self, exclusive: bool) {
193        unsafe {
194            ffi::gtk_gesture_single_set_exclusive(
195                self.as_ref().to_glib_none().0,
196                exclusive.into_glib(),
197            );
198        }
199    }
200
201    /// If `touch_only` is [`true`], `self` will only handle events of type
202    /// `GDK_TOUCH_BEGIN`, `GDK_TOUCH_UPDATE` or `GDK_TOUCH_END`. If [`false`],
203    /// mouse events will be handled too.
204    /// ## `touch_only`
205    /// whether `self` handles only touch events
206    #[doc(alias = "gtk_gesture_single_set_touch_only")]
207    #[doc(alias = "touch-only")]
208    fn set_touch_only(&self, touch_only: bool) {
209        unsafe {
210            ffi::gtk_gesture_single_set_touch_only(
211                self.as_ref().to_glib_none().0,
212                touch_only.into_glib(),
213            );
214        }
215    }
216
217    #[doc(alias = "button")]
218    fn connect_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
219        unsafe extern "C" fn notify_button_trampoline<
220            P: IsA<GestureSingle>,
221            F: Fn(&P) + 'static,
222        >(
223            this: *mut ffi::GtkGestureSingle,
224            _param_spec: glib::ffi::gpointer,
225            f: glib::ffi::gpointer,
226        ) {
227            unsafe {
228                let f: &F = &*(f as *const F);
229                f(GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
230            }
231        }
232        unsafe {
233            let f: Box_<F> = Box_::new(f);
234            connect_raw(
235                self.as_ptr() as *mut _,
236                c"notify::button".as_ptr(),
237                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
238                    notify_button_trampoline::<Self, F> as *const (),
239                )),
240                Box_::into_raw(f),
241            )
242        }
243    }
244
245    #[doc(alias = "exclusive")]
246    fn connect_exclusive_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
247        unsafe extern "C" fn notify_exclusive_trampoline<
248            P: IsA<GestureSingle>,
249            F: Fn(&P) + 'static,
250        >(
251            this: *mut ffi::GtkGestureSingle,
252            _param_spec: glib::ffi::gpointer,
253            f: glib::ffi::gpointer,
254        ) {
255            unsafe {
256                let f: &F = &*(f as *const F);
257                f(GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
258            }
259        }
260        unsafe {
261            let f: Box_<F> = Box_::new(f);
262            connect_raw(
263                self.as_ptr() as *mut _,
264                c"notify::exclusive".as_ptr(),
265                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
266                    notify_exclusive_trampoline::<Self, F> as *const (),
267                )),
268                Box_::into_raw(f),
269            )
270        }
271    }
272
273    #[doc(alias = "touch-only")]
274    fn connect_touch_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
275        unsafe extern "C" fn notify_touch_only_trampoline<
276            P: IsA<GestureSingle>,
277            F: Fn(&P) + 'static,
278        >(
279            this: *mut ffi::GtkGestureSingle,
280            _param_spec: glib::ffi::gpointer,
281            f: glib::ffi::gpointer,
282        ) {
283            unsafe {
284                let f: &F = &*(f as *const F);
285                f(GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
286            }
287        }
288        unsafe {
289            let f: Box_<F> = Box_::new(f);
290            connect_raw(
291                self.as_ptr() as *mut _,
292                c"notify::touch-only".as_ptr(),
293                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
294                    notify_touch_only_trampoline::<Self, F> as *const (),
295                )),
296                Box_::into_raw(f),
297            )
298        }
299    }
300}
301
302impl<O: IsA<GestureSingle>> GestureSingleExt for O {}