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