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