use libc::c_double;
use wlroots_sys::{wlr_event_pointer_axis, wlr_event_pointer_button, wlr_event_pointer_motion,
wlr_event_pointer_motion_absolute, wlr_axis_orientation,
wlr_axis_source, wlr_button_state};
use input;
pub const BTN_MOUSE: u32 = 0x110;
pub const BTN_LEFT: u32 = 0x110;
pub const BTN_RIGHT: u32 = 0x111;
pub const BTN_MIDDLE: u32 = 0x112;
pub const BTN_SIDE: u32 = 0x113;
pub const BTN_EXTRA: u32 = 0x114;
pub const BTN_FORWARD: u32 = 0x115;
pub const BTN_BACK: u32 = 0x116;
pub const BTN_TASK: u32 = 0x117;
#[derive(Debug)]
pub struct Axis {
event: *mut wlr_event_pointer_axis,
device: input::Device
}
#[derive(Debug)]
pub struct Button {
event: *mut wlr_event_pointer_button,
device: input::Device
}
#[derive(Debug)]
pub struct Motion {
event: *mut wlr_event_pointer_motion,
device: input::Device
}
#[derive(Debug)]
pub struct AbsoluteMotion {
event: *mut wlr_event_pointer_motion_absolute,
device: input::Device
}
impl Button {
pub(crate) unsafe fn from_ptr(event: *mut wlr_event_pointer_button) -> Self {
Button { device: input::Device::from_ptr((*event).device),
event }
}
pub fn device(&self) -> &input::Device {
&self.device
}
pub fn state(&self) -> wlr_button_state {
unsafe { (*self.event).state }
}
pub fn time_msec(&self) -> u32 {
unsafe { (*self.event).time_msec }
}
pub fn button(&self) -> u32 {
unsafe { (*self.event).button }
}
}
impl Axis {
pub(crate) unsafe fn from_ptr(event: *mut wlr_event_pointer_axis) -> Self {
Axis { device: input::Device::from_ptr((*event).device),
event }
}
pub fn device(&self) -> &input::Device {
&self.device
}
pub fn time_msec(&self) -> u32 {
unsafe { (*self.event).time_msec }
}
pub fn source(&self) -> wlr_axis_source {
unsafe { (*self.event).source }
}
pub fn orientation(&self) -> wlr_axis_orientation {
unsafe { (*self.event).orientation }
}
pub fn delta(&self) -> f64 {
unsafe { (*self.event).delta }
}
}
impl Motion {
pub(crate) unsafe fn from_ptr(event: *mut wlr_event_pointer_motion) -> Self {
Motion { device: input::Device::from_ptr((*event).device),
event }
}
pub fn device(&self) -> &input::Device {
&self.device
}
pub fn time_msec(&self) -> u32 {
unsafe { (*self.event).time_msec }
}
pub fn delta(&self) -> (f64, f64) {
unsafe { ((*self.event).delta_x, (*self.event).delta_y) }
}
}
impl AbsoluteMotion {
pub(crate) unsafe fn from_ptr(event: *mut wlr_event_pointer_motion_absolute) -> Self {
AbsoluteMotion { device: input::Device::from_ptr((*event).device),
event }
}
pub fn time_msec(&self) -> u32 {
unsafe { (*self.event).time_msec }
}
pub fn pos(&self) -> (c_double, c_double) {
unsafe { ((*self.event).x, (*self.event).y) }
}
pub fn device(&self) -> &input::Device {
&self.device
}
}