use libc;
use wlroots_sys::wlr_input_device;
use wayland_sys::server::WAYLAND_SERVER_HANDLE;
use {compositor,
input::touch::{self, Touch},
utils::Handleable};
#[allow(unused_variables)]
pub trait Handler {
fn on_down(&mut self,
compositor_handle: compositor::Handle,
touch_handle: touch::Handle,
event: &touch::event::Down) {}
fn on_up(&mut self,
compositor_handle: compositor::Handle,
touch_handle: touch::Handle,
event: &touch::event::Up) {}
fn on_motion(&mut self,
compositor_handle: compositor::Handle,
touch_handle: touch::Handle,
event: &touch::event::Motion) {}
fn on_cancel(&mut self,
compositor_handle: compositor::Handle,
touch_handle: touch::Handle,
event: &touch::event::Cancel) {}
fn destroyed(&mut self,
compositor_handle: compositor::Handle,
touch_handle: touch::Handle) {}
}
wayland_listener!(pub(crate) TouchWrapper, (Touch, Box<Handler>), [
on_destroy_listener => on_destroy_notify: |this: &mut TouchWrapper, data: *mut libc::c_void,|
unsafe {
let input_device_ptr = data as *mut wlr_input_device;
{
let (ref mut touch, ref mut touch_handler) = this.data;
let compositor = match compositor::handle() {
Some(handle) => handle,
None => return
};
touch_handler.destroyed(compositor, touch.weak_reference());
}
ffi_dispatch!(WAYLAND_SERVER_HANDLE,
wl_list_remove,
&mut (*this.on_destroy_listener()).link as *mut _ as _);
ffi_dispatch!(WAYLAND_SERVER_HANDLE,
wl_list_remove,
&mut (*this.down_listener()).link as *mut _ as _);
ffi_dispatch!(WAYLAND_SERVER_HANDLE,
wl_list_remove,
&mut (*this.up_listener()).link as *mut _ as _);
ffi_dispatch!(WAYLAND_SERVER_HANDLE,
wl_list_remove,
&mut (*this.motion_listener()).link as *mut _ as _);
ffi_dispatch!(WAYLAND_SERVER_HANDLE,
wl_list_remove,
&mut (*this.cancel_listener()).link as *mut _ as _);
Box::from_raw((*input_device_ptr).data as *mut TouchWrapper);
};
down_listener => down_notify: |this: &mut TouchWrapper, data: *mut libc::c_void,| unsafe {
let (ref touch, ref mut handler) = this.data;
let event = touch::event::Down::from_ptr(data as *mut _);
let compositor = match compositor::handle() {
Some(handle) => handle,
None => return
};
handler.on_down(compositor,
touch.weak_reference(),
&event);
};
up_listener => up_notify: |this: &mut TouchWrapper, data: *mut libc::c_void,| unsafe {
let (ref touch, ref mut handler) = this.data;
let event = touch::event::Up::from_ptr(data as *mut _);
let compositor = match compositor::handle() {
Some(handle) => handle,
None => return
};
handler.on_up(compositor,
touch.weak_reference(),
&event);
};
motion_listener => motion_notify: |this: &mut TouchWrapper, data: *mut libc::c_void,| unsafe {
let (ref touch, ref mut handler) = this.data;
let event = touch::event::Motion::from_ptr(data as *mut _);
let compositor = match compositor::handle() {
Some(handle) => handle,
None => return
};
handler.on_motion(compositor,
touch.weak_reference(),
&event);
};
cancel_listener => cancel_notify: |this: &mut TouchWrapper, data: *mut libc::c_void,| unsafe {
let (ref touch, ref mut handler) = this.data;
let event = touch::event::Cancel::from_ptr(data as *mut _);
let compositor = match compositor::handle() {
Some(handle) => handle,
None => return
};
handler.on_cancel(compositor,
touch.weak_reference(),
&event);
};
]);