1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use crate::EventController;
use crate::Gesture;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib::wrapper! {
    /// [`GestureSingle`][crate::GestureSingle] is a `GtkGestures` subclass optimized for singe-touch
    /// and mouse gestures.
    ///
    /// Under interaction, these gestures stick to the first interacting sequence,
    /// which is accessible through [``GestureSingleExt::current_sequence()``][crate::prelude::`GestureSingleExt::current_sequence()`]
    /// while the gesture is being interacted with.
    ///
    /// By default gestures react to both `GDK_BUTTON_PRIMARY` and touch events.
    /// [``GestureSingleExt::set_touch_only()``][crate::prelude::`GestureSingleExt::set_touch_only()`] can be used to change the
    /// touch behavior. Callers may also specify a different mouse button number
    /// to interact with through [``GestureSingleExt::set_button()``][crate::prelude::`GestureSingleExt::set_button()`], or react
    /// to any mouse button by setting it to 0. While the gesture is active, the
    /// button being currently pressed can be known through
    /// [``GestureSingleExt::current_button()``][crate::prelude::`GestureSingleExt::current_button()`].
    ///
    /// # Implements
    ///
    /// [`GestureSingleExt`][trait@crate::prelude::GestureSingleExt], [`GestureExt`][trait@crate::prelude::GestureExt], [`EventControllerExt`][trait@crate::prelude::EventControllerExt], [`trait@glib::ObjectExt`]
    #[doc(alias = "GtkGestureSingle")]
    pub struct GestureSingle(Object<ffi::GtkGestureSingle, ffi::GtkGestureSingleClass>) @extends Gesture, EventController;

    match fn {
        type_ => || ffi::gtk_gesture_single_get_type(),
    }
}

pub const NONE_GESTURE_SINGLE: Option<&GestureSingle> = None;

/// Trait containing all [`struct@GestureSingle`] methods.
///
/// # Implementors
///
/// [`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]
pub trait GestureSingleExt: 'static {
    /// Returns the button number `self` listens for.
    ///
    /// If this is 0, the gesture reacts to any button press.
    ///
    /// # Returns
    ///
    /// The button number, or 0 for any button
    #[doc(alias = "gtk_gesture_single_get_button")]
    #[doc(alias = "get_button")]
    fn button(&self) -> u32;

    /// Returns the button number currently interacting
    /// with `self`, or 0 if there is none.
    ///
    /// # Returns
    ///
    /// The current button number
    #[doc(alias = "gtk_gesture_single_get_current_button")]
    #[doc(alias = "get_current_button")]
    fn current_button(&self) -> u32;

    /// Returns the event sequence currently interacting with `self`.
    ///
    /// This is only meaningful if [``GestureExt::is_active()``][crate::prelude::`GestureExt::is_active()`]
    /// returns [`true`].
    ///
    /// # Returns
    ///
    /// the current sequence
    #[doc(alias = "gtk_gesture_single_get_current_sequence")]
    #[doc(alias = "get_current_sequence")]
    fn current_sequence(&self) -> Option<gdk::EventSequence>;

    /// Gets whether a gesture is exclusive.
    ///
    /// For more information, see [``set_exclusive()``][`Self::set_exclusive()`].
    ///
    /// # Returns
    ///
    /// Whether the gesture is exclusive
    #[doc(alias = "gtk_gesture_single_get_exclusive")]
    #[doc(alias = "get_exclusive")]
    fn is_exclusive(&self) -> bool;

    /// Returns [`true`] if the gesture is only triggered by touch events.
    ///
    /// # Returns
    ///
    /// [`true`] if the gesture only handles touch events
    #[doc(alias = "gtk_gesture_single_get_touch_only")]
    #[doc(alias = "get_touch_only")]
    fn is_touch_only(&self) -> bool;

    /// Sets the button number `self` listens to.
    ///
    /// If non-0, every button press from a different button
    /// number will be ignored. Touch events implicitly match
    /// with button 1.
    /// ## `button`
    /// button number to listen to, or 0 for any button
    #[doc(alias = "gtk_gesture_single_set_button")]
    fn set_button(&self, button: u32);

    /// Sets whether `self` is exclusive.
    ///
    /// An exclusive gesture will only handle pointer and "pointer emulated"
    /// touch events, so at any given time, there is only one sequence able
    /// to interact with those.
    /// ## `exclusive`
    /// [`true`] to make `self` exclusive
    #[doc(alias = "gtk_gesture_single_set_exclusive")]
    fn set_exclusive(&self, exclusive: bool);

    /// Sets whether to handle only touch events.
    ///
    /// If `touch_only` is [`true`], `self` will only handle events of type
    /// `GDK_TOUCH_BEGIN`, `GDK_TOUCH_UPDATE` or `GDK_TOUCH_END`. If [`false`],
    /// mouse events will be handled too.
    /// ## `touch_only`
    /// whether `self` handles only touch events
    #[doc(alias = "gtk_gesture_single_set_touch_only")]
    fn set_touch_only(&self, touch_only: bool);

    #[doc(alias = "button")]
    fn connect_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "exclusive")]
    fn connect_exclusive_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    #[doc(alias = "touch-only")]
    fn connect_touch_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<GestureSingle>> GestureSingleExt for O {
    fn button(&self) -> u32 {
        unsafe { ffi::gtk_gesture_single_get_button(self.as_ref().to_glib_none().0) }
    }

    fn current_button(&self) -> u32 {
        unsafe { ffi::gtk_gesture_single_get_current_button(self.as_ref().to_glib_none().0) }
    }

    fn current_sequence(&self) -> Option<gdk::EventSequence> {
        unsafe {
            from_glib_full(ffi::gtk_gesture_single_get_current_sequence(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn is_exclusive(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_gesture_single_get_exclusive(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn is_touch_only(&self) -> bool {
        unsafe {
            from_glib(ffi::gtk_gesture_single_get_touch_only(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn set_button(&self, button: u32) {
        unsafe {
            ffi::gtk_gesture_single_set_button(self.as_ref().to_glib_none().0, button);
        }
    }

    fn set_exclusive(&self, exclusive: bool) {
        unsafe {
            ffi::gtk_gesture_single_set_exclusive(
                self.as_ref().to_glib_none().0,
                exclusive.into_glib(),
            );
        }
    }

    fn set_touch_only(&self, touch_only: bool) {
        unsafe {
            ffi::gtk_gesture_single_set_touch_only(
                self.as_ref().to_glib_none().0,
                touch_only.into_glib(),
            );
        }
    }

    fn connect_button_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_button_trampoline<
            P: IsA<GestureSingle>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkGestureSingle,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::button\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_button_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_exclusive_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_exclusive_trampoline<
            P: IsA<GestureSingle>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkGestureSingle,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::exclusive\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_exclusive_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_touch_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_touch_only_trampoline<
            P: IsA<GestureSingle>,
            F: Fn(&P) + 'static,
        >(
            this: *mut ffi::GtkGestureSingle,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(GestureSingle::from_glib_borrow(this).unsafe_cast_ref())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::touch-only\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_touch_only_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for GestureSingle {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("GestureSingle")
    }
}