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
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::EventType;
use glib::translate::*;
use std::fmt;
use std::mem;

glib::wrapper! {
    /// An event related to a pad-based device.
    #[doc(alias = "GdkPadEvent")]
    pub struct PadEvent(Shared<ffi::GdkPadEvent>);

    match fn {
        ref => |ptr| ffi::gdk_event_ref(ptr as *mut ffi::GdkEvent),
        unref => |ptr| ffi::gdk_event_unref(ptr as *mut ffi::GdkEvent),
    }
}

define_event! {
    PadEvent,
    ffi::GdkPadEvent,
    ffi::gdk_pad_event_get_type,
    &[EventType::PadButtonPress, EventType::PadButtonRelease, EventType::PadRing, EventType::PadStrip, EventType::PadGroupMode]
}

impl PadEvent {
    /// Extracts the information from a pad strip or ring event.
    ///
    /// # Returns
    ///
    ///
    /// ## `index`
    /// Return location for the axis index
    ///
    /// ## `value`
    /// Return location for the axis value
    #[doc(alias = "gdk_pad_event_get_axis_value")]
    #[doc(alias = "get_axis_value")]
    pub fn axis_value(&self) -> (u32, f64) {
        unsafe {
            let mut index = mem::MaybeUninit::uninit();
            let mut value = mem::MaybeUninit::uninit();
            ffi::gdk_pad_event_get_axis_value(
                self.to_glib_none().0,
                index.as_mut_ptr(),
                value.as_mut_ptr(),
            );
            let index = index.assume_init();
            let value = value.assume_init();
            (index, value)
        }
    }

    /// Extracts information about the pressed button from
    /// a pad event.
    ///
    /// # Returns
    ///
    /// the button of `self`
    #[doc(alias = "gdk_pad_event_get_button")]
    #[doc(alias = "get_button")]
    pub fn button(&self) -> u32 {
        unsafe { ffi::gdk_pad_event_get_button(self.to_glib_none().0) }
    }

    /// Extracts group and mode information from a pad event.
    ///
    /// # Returns
    ///
    ///
    /// ## `group`
    /// return location for the group
    ///
    /// ## `mode`
    /// return location for the mode
    #[doc(alias = "gdk_pad_event_get_group_mode")]
    #[doc(alias = "get_group_mode")]
    pub fn group_mode(&self) -> (u32, u32) {
        unsafe {
            let mut group = mem::MaybeUninit::uninit();
            let mut mode = mem::MaybeUninit::uninit();
            ffi::gdk_pad_event_get_group_mode(
                self.to_glib_none().0,
                group.as_mut_ptr(),
                mode.as_mut_ptr(),
            );
            let group = group.assume_init();
            let mode = mode.assume_init();
            (group, mode)
        }
    }
}

impl fmt::Display for PadEvent {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("PadEvent")
            .field("axis_value", &self.axis_value())
            .field("button", &self.button())
            .field("group_mode", &self.group_mode())
            .finish()
    }
}